diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2022-03-06 18:34:33 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-03-07 23:49:32 -0500 |
commit | d0f892fe08a869f5bb924741b828bb7efdfcd801 (patch) | |
tree | 15dbfb6fc5f84edd79c3c9c110f5a62e34ff5a1c /testsuite/tests/generics | |
parent | 6ce6c2504c33eb0faa9c160dc1773735d858504c (diff) | |
download | haskell-d0f892fe08a869f5bb924741b828bb7efdfcd801.tar.gz |
Delete GenericKind_ in favor of GenericKind_DC
When deriving a `Generic1` instance, we need to know what the last type
variable of a data type is. Previously, there were two mechanisms to determine
this information:
* `GenericKind_`, where `Gen1_` stored the last type variable of a data type
constructor (i.e., the `tyConTyVars`).
* `GenericKind_DC`, where `Gen1_DC` stored the last universally quantified
type variable in a data constructor (i.e., the `dataConUnivTyVars`).
These had different use cases, as `GenericKind_` was used for generating
`Rep(1)` instances, while `GenericKind_DC` was used for generating `from(1)`
and `to(1)` implementations. This was already a bit confusing, but things went
from confusing to outright wrong after !6976. This is because after !6976,
the `deriving` machinery stopped using `tyConTyVars` in favor of
`dataConUnivTyVars`. Well, everywhere with the sole exception of
`GenericKind_`, which still continued to use `tyConTyVars`. This lead to
disaster when deriving a `Generic1` instance for a GADT family instance, as
the `tyConTyVars` do not match the `dataConUnivTyVars`. (See #21185.)
The fix is to stop using `GenericKind_` and replace it with `GenericKind_DC`.
For the most part, this proves relatively straightforward. Some highlights:
* The `forgetArgVar` function was deleted entirely, as it no longer proved
necessary after `GenericKind_`'s demise.
* The substitution that maps from the last type variable to `Any` (see
`Note [Generating a correctly typed Rep instance]`) had to be moved from
`tc_mkRepTy` to `tc_mkRepFamInsts`, as `tc_mkRepTy` no longer has access to
the last type variable.
Fixes #21185.
Diffstat (limited to 'testsuite/tests/generics')
-rw-r--r-- | testsuite/tests/generics/T21185.hs | 22 | ||||
-rw-r--r-- | testsuite/tests/generics/all.T | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/testsuite/tests/generics/T21185.hs b/testsuite/tests/generics/T21185.hs new file mode 100644 index 0000000000..1d2d1f30af --- /dev/null +++ b/testsuite/tests/generics/T21185.hs @@ -0,0 +1,22 @@ +{-# LANGUAGE TypeFamilies #-} +module T21185 where + +import Data.Kind (Type) +import GHC.Generics (Generic1(..)) + +type FakeOut x = Int + +data D (b :: Type) where + MkD :: c -> FakeOut c -> D c + deriving Generic1 + +data family DF (a :: Type) +data instance DF (b :: Type) where + MkDF :: c -> FakeOut c -> DF c + deriving Generic1 + +d :: Rep1 D () +d = from1 $ MkD () 42 + +df :: Rep1 DF () +df = from1 $ MkDF () 42 diff --git a/testsuite/tests/generics/all.T b/testsuite/tests/generics/all.T index 1fccfffc16..a43f585020 100644 --- a/testsuite/tests/generics/all.T +++ b/testsuite/tests/generics/all.T @@ -45,3 +45,4 @@ test('T11358', normal, compile_and_run, ['']) test('T12220', normal, compile, ['']) test('T15012', [extra_files(['T15012.hs', 'T15012a.hs'])], makefile_test, []) test('T19819', normal, compile_and_run, ['']) +test('T21185', normal, compile, ['']) |