Note [Flag cast in data con wrappers]
Consider the data declaration
data G a where
MkG :: forall a -> a -> G a
The user-facing type of MkG has a 'Required' forall. Workers, on the other hand,
always use 'Specified' foralls (coreTyLamForAllTyFlag). So we need a wrapper:
wrapper type: forall a -> a -> G a
worker type: forall a. a -> G a
Concretely, it looks like this:
$WMkG = /\a. \(x:a). MkG a x |> co
where 'co' is a coercion constructed by GHC.Core.Coercion.mkForAllVisCos.
The cast is added by the call to mkCoreTyLams in GHC.Types.Id.Make.mkDataConRep.
In general, wrappers may use 'Inferred', 'Specified', or 'Required' foralls.
However, we do /not/ need a cast to convert 'Inferred' to 'Specified' because they are
'eqType'-equal. Only a 'Required' forall necessitates a cast in the wrapper.
See Note [ForAllTy and type equality], Note [Comparing visibility],
and Note [Required foralls in Core]. References 3
- Comparing visibility GHC.Core.TyCo.Compare
- ForAllTy and type equality GHC.Core.TyCo.Compare
- Required foralls in Core GHC.Core.TyCo.Rep
Referenced by 2
- GHC.Core.DataCon call site
- DataCon user type variable binders GHC.Core.DataCon