HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

  • Packageghc-9.10.3
  • Exports159
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceTyCon.hs

Main TyCon data types

10 declarations
datadata TyCon
#

TyCons represent type constructors. Type constructors are introduced by things such as:

1) Data declarations: data Foo = ... creates the Foo type constructor of kind Type

2) Type synonyms: type Foo = ... creates the Foo type constructor

3) Newtypes: newtype Foo a = MkFoo ... creates the Foo type constructor of kind Type -> Type

4) Class declarations: class Foo where creates the Foo type constructor of kind Constraint

This data type also encodes a number of primitive, built in type constructors such as those for function and tuple types.

If you edit this type, you may need to update the GHC formalism See Note [GHC Formalism] in GHC.Core.Lint

Instances5Eq, Data, NamedThing, Outputable, Uniquable
datadata AlgTyConRhs
#

Represents right-hand-sides of TyCons for algebraic types

Constructors

  • AbstractTyCon

    Says that we know nothing about this data type, except that it's represented by a pointer. Used when we export a data type abstractly into an .hi file.

  • DataTyCon

    Information about those TyCons derived from a data declaration. This includes data types with no constructors at all.

    • data_cons :: [DataCon]

      The data type constructors; can be empty if the user declares the type to have no constructors

      INVARIANT: Kept in order of increasing DataCon tag (see the tag assignment in mkTyConTagMap)

    • data_cons_size :: Int

      Cached value: length data_cons

    • is_enum :: Bool

      Cached value: is this an enumeration type? See Note [Enumeration types]

    • is_type_data :: Bool
    • data_fixed_lev :: Bool

      True if the data type constructor has a known, fixed levity when fully applied to its arguments, False otherwise.

      This can only be False with UnliftedDatatypes, e.g.

      data A :: TYPE (BoxedRep l) where { MkA :: Int -> A }

      This boolean is cached to make it cheaper to check for levity and representation-polymorphism in tcHasFixedRuntimeRep.

  • TupleTyCon
  • SumTyCon

    An unboxed sum type.

    • data_cons :: [DataCon]

      The data type constructors; can be empty if the user declares the type to have no constructors

      INVARIANT: Kept in order of increasing DataCon tag (see the tag assignment in mkTyConTagMap)

    • data_cons_size :: Int

      Cached value: length data_cons

  • NewTyCon

    Information about those TyCons derived from a newtype declaration

    • data_con :: DataCon

      The unique constructor for the newtype. It has no existentials

    • nt_rhs :: Type

      Cached value: the argument type of the constructor, which is just the representation type of the TyCon (remember that newtypes do not exist at runtime so need a different representation type).

      The free TyVars of this type are the tyConTyVars from the corresponding TyCon

    • nt_etad_rhs :: ([TyVar], Type)

      Same as the nt_rhs, but this time eta-reduced. Hence the list of TyVars in this field may be shorter than the declared arity of the TyCon.

    • nt_co :: CoAxiom Unbranched
    • nt_fixed_rep :: Bool

      True if the newtype has a known, fixed representation when fully applied to its arguments, False otherwise. This can only ever be False with UnliftedNewtypes.

      Example:

      newtype N (a :: TYPE r) = MkN a

      Invariant: nt_fixed_rep nt = tcHasFixedRuntimeRep (nt_rhs nt)

      This boolean is cached to make it cheaper to check if a variable binding is representation-polymorphic in tcHasFixedRuntimeRep.

Extract those DataCons that we are able to learn about. Note that visibility in this sense does not correspond to visibility in the context of any particular user program!

datadata AlgTyConFlav
#

Describes the flavour of an algebraic type constructor. For classes and data families, this flavour includes a reference to the parent TyCon.

Constructors

  • VanillaAlgTyCon TyConRepName

    An ordinary algebraic type constructor. This includes unlifted and representation-polymorphic datatypes and newtypes and unboxed tuples, but NOT unboxed sums; see UnboxedSumTyCon.

  • UnboxedSumTyCon

    An unboxed sum type constructor. This is distinct from VanillaAlgTyCon because we currently don't allow unboxed sums to be Typeable since there are too many of them. See #13276.

  • ClassTyCon Class TyConRepName

    Type constructors representing a class dictionary. See Note [ATyCon for classes] in GHC.Core.TyCo.Rep

  • DataFamInstTyCon (CoAxiom Unbranched) TyCon [Type]

    Type constructors representing an *instance* of a *data* family. Parameters:

    1) The type family in question

    2) Instance types; free variables are the tyConTyVars of the current TyCon (not the family one). INVARIANT: the number of types matches the arity of the family TyCon

    3) A CoTyCon identifying the representation type with the type instance family

Instances1Outputable
datadata FamTyConFlav
#

Information pertaining to the expansion of a type synonym (type)

Constructors

Instances1Outputable
datadata Role
#

See Note [Roles] in GHC.Core.Coercion

Order of constructors matters: the Ord instance coincides with the *super*typing relation on roles.

Instances7Eq, Data, Ord, Outputable, Binary, Anno, …
  • Eq RoleDefined in ghc-9.10.3 · Language.Haskell.Syntax.Basic
  • Data RoleDefined in ghc-9.10.3 · Language.Haskell.Syntax.Basic
  • Ord RoleDefined in ghc-9.10.3 · Language.Haskell.Syntax.Basic
  • Outputable RoleDefined in ghc-9.10.3 · GHC.Core.Coercion.Axiom · orphan
  • Binary RoleDefined in ghc-9.10.3 · GHC.Core.Coercion.Axiom · orphan
  • type Anno (Maybe Role) = EpAnnCODefined in ghc-9.10.3 · GHC.Hs.Decls · orphan
  • type Anno (Maybe Role) = EpAnnCODefined in ghc-9.10.3 · GHC.Hs.Decls · orphan
datadata PromDataConInfo
#

Some promoted datacons signify extra info relevant to GHC. For example, the IntRep constructor of RuntimeRep corresponds to the IntRep constructor of PrimRep. This data structure allows us to store this information right in the TyCon. The other approach would be to look up things like RuntimeRep's PrimRep by known-key every time. See also Note [Getting from RuntimeRep to PrimRep] in GHC.Types.RepType

Constructors

datadata TyConFlavour tc
#

Paints a picture of what a TyCon represents, in broad strokes. This is used towards more informative error messages.

Instances5Functor, Eq, Data, NFData, Outputable

TyConBinder

14 declarations

Field labels

Constructing TyCons

valuemkPrimTyCon
  1. :: Name
  2. -> [TyConBinder]
  3. -> Kind

    result kind Must answer True to isFixedRuntimeRepKind (i.e., no representation polymorphism). (If you need a representation-polymorphic PrimTyCon, change tcHasFixedRuntimeRep, marshalablePrimTyCon, reifyTyCon for PrimTyCons.)

  4. -> [Role]
  5. -> TyCon
#

Create an primitive TyCon, such as Int#, Type or RealWorld Primitive TyCons are marshalable iff not lifted. If you'd like to change this, modify marshalablePrimTyCon.

valuemkTcTyCon
  1. :: Name
  2. -> [TyConBinder]
  3. -> Kind

    result kind only

  4. -> [(Name, TcTyVar)]

    Scoped type variables;

  5. -> Bool

    Is this TcTyCon generalised already?

  6. -> TyConFlavour TyCon

    What sort of TyCon this represents

  7. -> TyCon
#

Makes a tycon suitable for use during type-checking. It stores a variety of details about the definition of the TyCon, but no right-hand side. It lives only during the type-checking of a mutually-recursive group of tycons; it is then zonked to a proper TyCon in zonkTcTyCon. See Note [TcTyCon, MonoTcTyCon, and PolyTcTyCon] in GHC.Tc.TyCl

Predicates on TyCons

valueisVanillaAlgTyCon :: TyCon -> Bool
#

Returns True for vanilla AlgTyCons -- that is, those created with a data or newtype declaration.

valueisTupleTyCon :: TyCon -> Bool
#

Does this TyCon represent a tuple?

NB: when compiling Data.Tuple, the tycons won't reply True to isTupleTyCon, because they are built as AlgTyCons. However they get spat into the interface file as tuple tycons, so I don't think it matters.

True iff we can decompose (T a b c) into ((T a b) c) I.e. is it injective and generative w.r.t nominal equality? That is, if (T a b) ~N d e f, is it always the case that (T ~N d), (a ~N e) and (b ~N f)? Specifically NOT true of synonyms (open and otherwise)

It'd be unusual to call tyConMustBeSaturated on a regular H98 type synonym, because you should probably have expanded it first But regardless, it's not decomposable

This function identifies PromotedDataCon's from data constructors in `data T = K1 | K2`, promoted by -XDataKinds. These type constructors are printed with a tick mark 'K1 and 'K2, and similarly have a tick mark added to their OccName's.

In contrast, constructors in `type data T = K1 | K2` are printed and represented with their original undecorated names. See Note [Type data declarations] in GHC.Rename.Module

valueisKindTyCon :: TyCon -> Bool
#

Is this TyCon really meant for use at the kind level? That is, should it be permitted without DataKinds?

valueisKindName :: Name -> Bool
#

This is Name really meant for use at the kind level? That is, should it be permitted wihout DataKinds?

valueisFamFreeTyCon :: TyCon -> Bool
#

Is this tycon neither a type family nor a synonym that expands to a type family?

Is this a forgetful type synonym? If this is a type synonym whose RHS does not mention one (or more) of its bound variables, returns True. Thus, False means that all bound variables appear on the RHS; True may not mean anything, as the test to set this flag is conservative.

valueisDataTyCon :: TyCon -> Bool
#

Returns True for data types that are definitely represented by heap-allocated constructors. These are scrutinised by Core-level case expressions, and they get info tables allocated for them.

Generally, the function will be true for all data types and false for newtypes, unboxed tuples, unboxed sums and type family TyCons. But it is not guaranteed to return True in all cases that it could.

NB: for a data type family, only the instance TyCons get an info table. The family declaration TyCon does not

valueisInjectiveTyCon :: TyCon -> Role -> Bool
#

isInjectiveTyCon is true of TyCons for which this property holds (where r is the role passed in): If (T a1 b1 c1) ~r (T a2 b2 c2), then (a1 ~r1 a2), (b1 ~r2 b2), and (c1 ~r3 c2) (where r1, r2, and r3, are the roles given by tyConRolesX tc r) See also Note [Decomposing TyConApp equalities] in GHC.Tc.Solver.Equality

valueisGenerativeTyCon :: TyCon -> Role -> Bool
#

isGenerativeTyCon is true of TyCons for which this property holds (where r is the role passed in): If (T tys ~r t), then (t's head ~r T). See also Note [Decomposing TyConApp equalities] in GHC.Tc.Solver.Equality

NB: at Nominal role, isGenerativeTyCon is simple: isGenerativeTyCon tc Nominal = not (isTypeFamilyTyCon tc || isSynonymTyCon tc)

valueisImplicitTyCon :: TyCon -> Bool
#

Identifies implicit tycons that, in particular, do not go into interface files (because they are implicitly reconstructed when the interface is read).

Note that:

  • Associated families are implicit, as they are re-constructed from the class declaration in which they reside, and

  • Family instances are not implicit as they represent the instance body (similar to a dfun does that for a class instance).

  • Tuples are implicit iff they have a wired-in name (namely: boxed and unboxed tuples are wired-in and implicit, but constraint tuples are not)

Check if the tycon actually refers to a proper data or newtype with user defined constructors rather than one from a class or other construction.

valueisTcTyCon :: TyCon -> Bool
#

Is this a TcTyCon? (That is, one only used during type-checking?)

Does this TyCon have a syntactically fixed RuntimeRep when fully applied, as per Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete?

False is safe. True means we're sure. Does only a quick check, based on the TyCon's category.

See Note [Representation-polymorphic TyCons]

valueisConcreteTyCon :: TyCon -> Bool
#

Is this TyCon concrete? More specifically, if tys are all concrete, is (T tys) concrete? (for synonyms this requires us to look at the RHS) Used for representation polymorphism checks. See Note [Concrete types] in GHC.Tc.Utils.Concrete

valueisValidDTT2TyCon :: TyCon -> Bool
#

Returns True if a boxed type headed by the given TyCon satisfies condition DTT2 of Note [DataToTag overview] in GHC.Tc.Instance.Class

Extracting information out of TyCons

valuetyConSkolem :: TyCon -> Bool
#

Returns whether or not this TyCon is definite, or a hole that may be filled in at some later point. See Note [Skolem abstract data]

valuetyConUnique :: TyCon -> Unique
#

A Unique of this TyCon. Invariant: identical to Unique of Name stored in tyConName field.

If the given TyCon has a single data constructor, i.e. it is a data type with one alternative, a tuple type or a newtype then that constructor is returned. If the TyCon has more than one constructor, or represents a primitive or function type constructor then Nothing is returned.

valuetyConStupidTheta :: TyCon -> [PredType]
#

Find the "stupid theta" of the TyCon. A "stupid theta" is the context to the left of an algebraic type declaration, e.g. Eq a in the declaration data Eq a => T a .... See Note [The stupid context] in GHC.Core.DataCon.

valuemkTyConTy :: TyCon -> Type
#

(mkTyConTy tc) returns (TyConApp tc []) but arranges to share that TyConApp among all calls See Note [Sharing nullary TyConApps] So it's just an alias for tyConNullaryTy!

valuetyConRoles :: TyCon -> [Role]
#

The role for each type variable This list has length = tyConArity See also Note [TyCon Role signatures]

valuenewTyConEtadArity :: TyCon -> Int
#

The number of type parameters that need to be passed to a newtype to resolve it. May be less than in the definition if it can be eta-contracted.

Manipulating TyCons

valueexpandSynTyCon_maybe
  1. :: TyCon
  2. -> [tyco]

    Arguments to TyCon

  3. -> ExpandSynResult tyco

    Returns a TyVar substitution, the body type of the synonym (not yet substituted) and any arguments remaining from the application ^ Expand a type synonym application Return Nothing if the TyCon is not a synonym, or if not enough arguments are supplied

#

Extracts the newtype coercion from such a TyCon, which can be used to construct something with the newtypes type from its representation type (right hand side). If the supplied TyCon is not a newtype, returns Nothing

Predicated on TyConFlavours

Runtime type representation

4 declarations

Primitive representations of Types

15 declarations
datadata PrimRep
#

A PrimRep is an abstraction of a non-void type. (Use PrimRepOrVoidRep if you want void types too.) It contains information that the code generator needs in order to pass arguments, return results, and store values of this type. See also Note [RuntimeRep and PrimRep] in GHC.Types.RepType and Note [VoidRep] in GHC.Types.RepType.

Constructors

Instances6Eq, Data, Ord, Show, Outputable, Binary
datadata PrimElemRep
#
Instances7Enum, Eq, Data, Ord, Show, Outputable, …
valueprimRepSizeB :: Platform -> PrimRep -> Int
#

The size of a PrimRep in bytes.

This applies also when used in a constructor, where we allow packing the fields. For instance, in data Foo = Foo Float# Float# the two fields will take only 8 bytes, which for 64-bit arch will be equal to 1 word. See also mkVirtHeapOffsetsWithPadding for details of how data fields are laid out.

valueprimRepSizeW64_B :: PrimRep -> Int
#

Like primRepSizeB but assumes pointers/words are 8 words wide.

This can be useful to compute the size of a rep as if we were compiling for a 64bit platform.

Like primElemRepSizeB but assumes pointers/words are 8 words wide.

This can be useful to compute the size of a rep as if we were compiling for a 64bit platform.