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_
, whereGen1_
stored the last type variable of a data type constructor (i.e., thetyConTyVars
). -
GenericKind_DC
, whereGen1_DC
stored the last universally quantified type variable in a data constructor (i.e., thedataConUnivTyVars
).
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 (closed). This is because after !6976 (closed),
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 (closed).)
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 afterGenericKind_
's demise. - The substitution that maps from the last type variable to
Any
(seeNote [Generating a correctly typed Rep instance]
) had to be moved fromtc_mkRepTy
totc_mkRepFamInsts
, astc_mkRepTy
no longer has access to the last type variable.
Fixes #21185 (closed).