Note [Flag cast in data con wrappers]

GHC/Core/DataCon.hs:1941 compiler

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

Referenced by 2