Note [TYPE and CONSTRAINT] aka Note [Type vs Constraint]
GHC distinguishes Type from Constraint throughout the compiler. See GHC Proposal #518, and tickets #21623 and #11715. All types that classify values have a kind of the form (TYPE rr) or (CONSTRAINT rr) where the `RuntimeRep` parameter, rr, tells us how the value is represented at runtime. TYPE and CONSTRAINT are primitive type constructors. See Note [RuntimeRep polymorphism] about the `rr` parameter. There are a bunch of type synonyms and data types defined in the library ghc-prim:GHC.Types. All of them are also wired in to GHC, in GHC.Builtin.Types type Constraint = CONSTRAINT LiftedRep :: Type type Type = TYPE LiftedRep :: Type type UnliftedType = TYPE UnliftedRep :: Type type LiftedRep = BoxedRep Lifted :: RuntimeRep type UnliftedRep = BoxedRep Unlifted :: RuntimeRep data RuntimeRep -- Defined in ghc-prim:GHC.Types = BoxedRep Levity | IntRep | FloatRep .. etc .. data Levity = Lifted | Unlifted We abbreviate '*' specially (with -XStarIsType), as if we had this: type * = Type So for example: Int :: TYPE (BoxedRep Lifted) Array# Int :: TYPE (BoxedRep Unlifted) Int# :: TYPE IntRep Float# :: TYPE FloatRep Maybe :: TYPE (BoxedRep Lifted) -> TYPE (BoxedRep Lifted) (# , #) :: TYPE r1 -> TYPE r2 -> TYPE (TupleRep [r1, r2]) Eq Int :: CONSTRAINT (BoxedRep Lifted) IP "foo" Int :: CONSTRAINT (BoxedRep Lifted) a ~ b :: CONSTRAINT (BoxedRep Lifted) a ~# b :: CONSTRAINT (TupleRep []) Constraints are mostly lifted, but unlifted ones are useful too. Specifically (a ~# b) :: CONSTRAINT (TupleRep []) Wrinkles (W1) Type and Constraint are considered distinct throughout GHC. But they are not /apart/: see Note [Type and Constraint are not apart] (W2) We need two absent-error Ids, aBSENT_ERROR_ID for types of kind Type, and aBSENT_CONSTRAINT_ERROR_ID for types of kind Constraint. See Note [Type vs Constraint for error ids] in GHC.Core.Make. Ditto noInlineId vs noInlineConstraintId in GHC.Types.Id.Make; see Note [inlineId magic]. (W3) We need a TypeOrConstraint flag in LitRubbish. (W4) In the CPR transformation, we can't unbox constructors with constraint arguments because unboxed tuples (# …, … #) currently only supports fields of type TYPE rr. See (CPR2) in Note [Which types are unboxed?] in GHC.Core.Opt.WorkWrap.Utils.
References 5
- RuntimeRep polymorphism GHC.Builtin.Types.Prim
- Type and Constraint are not apart GHC.Builtin.Types.Prim
- Type vs Constraint for error ids GHC.Core.Make
- inlineId magic GHC.Core.Opt.ConstantFold
- Which types are unboxed? GHC.Core.Opt.WorkWrap.Utils
Referenced by 0
Nothing in the tree points here.