HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.Core.DataCon

  • 12 types
  • 73 values
  • Packageghc-9.10.3
  • Exports85
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceDataCon.hs

Main data types

9 declarations
datadata SrcUnpackedness
#

Source Unpackedness

What unpackedness the user requested

Constructors

Instances4Eq, Data, Outputable, Binary
datadata HsSrcBang
#

Haskell Source Bang

Bangs on data constructor arguments as the user wrote them in the source code.

(HsSrcBang _ SrcUnpack SrcLazy) and (HsSrcBang _ SrcUnpack NoSrcStrict) (without StrictData) makes no sense, we emit a warning (in checkValidDataCon) and treat it like (HsSrcBang _ NoSrcUnpack SrcLazy)

Instances2Data, Outputable
datadata HsImplBang
#

Haskell Implementation Bang

Bangs of data constructor arguments as generated by the compiler after consulting HsSrcBang, flags, etc.

Constructors

  • HsLazy

    Lazy field, or one with an unlifted type

  • HsStrict Bool

    Strict but not unpacked field True = we could have unpacked, but opted not to because of -O0. See Note [Detecting useless UNPACK pragmas]

  • HsUnpack (Maybe Coercion)

    Strict and unpacked field co :: arg-ty ~ product-ty HsBang

Instances2Data, Outputable
typetype ConTag = Int
#

A *one-index* constructor tag

Type of the tags associated with each constructor possibility or superclass selector

Equality specs

datadata EqSpec
#

An EqSpec is a tyvar/type pair representing an equality made in rejigging a GADT constructor

Instances1Outputable

Field labels

datadata FieldLabel
#

Fields in an algebraic record type; see Note [FieldLabel].

Constructors

Instances6Eq, Data, NFData, Outputable, Binary, HasOccName
newtypenewtype FieldLabelString
#

Field labels are just represented as strings; they are not necessarily unique (even within a module)

Instances6Eq, Data, NFData, Outputable, Uniquable, Anno

Type construction

valuemkDataCon
  1. :: Name
  2. -> Bool

    Is the constructor declared infix?

  3. -> TyConRepName

    TyConRepName for the promoted TyCon

  4. -> [HsSrcBang]

    Strictness/unpack annotations, from user

  5. -> [FieldLabel]

    Field labels for the constructor, if it is a record, otherwise empty

  6. -> [TyVar]

    Universals.

  7. -> [TyCoVar]

    Existentials.

  8. -> ConcreteTyVars

    TyVars which must be instantiated with concrete types

  9. -> [InvisTVBinder]

    User-written TyVarBinders. These must be Inferred/Specified. See Note [TyVarBinders in DataCons]

  10. -> [EqSpec]

    GADT equalities

  11. -> KnotTied ThetaType

    Theta-type occurring before the arguments proper

  12. -> [KnotTied (Scaled Type)]

    Original argument types

  13. -> KnotTied Type

    Original result type

  14. -> PromDataConInfo

    See comments on PromDataConInfo

  15. -> KnotTied TyCon

    Representation type constructor

  16. -> ConTag

    Constructor tag

  17. -> ThetaType

    The "stupid theta", context of the data declaration e.g. data Eq a => T a ...

  18. -> Id

    Worker Id

  19. -> DataConRep

    Representation

  20. -> DataCon
#

Build a new data constructor

valuefIRST_TAG :: ConTag
#

Tags are allocated from here for real constructors or for superclass selectors

Type deconstruction

valuedataConRepType :: DataCon -> Type
#

The representation type of the data constructor, i.e. the sort type that will represent values of this type at runtime

valuedataConInstSig :: DataCon -> [Type] -> ([TyCoVar], ThetaType, [Type])
#

Instantiate the universal tyvars of a data con, returning ( instantiated existentials , instantiated constraints including dependent GADT equalities which are *also* listed in the instantiated existentials , instantiated args)

The "full signature" of the DataCon returns, in order:

1) The result of dataConUnivTyVars

2) The result of dataConExTyCoVars

3) The non-dependent GADT equalities. Dependent GADT equalities are implied by coercion variables in return value (2).

4) The other constraints of the data constructor type, excluding GADT equalities

5) The original argument types to the DataCon (i.e. before any change of the representation of the type) with linearity annotations

6) The original result type of the DataCon

The string package:module.name identifying a constructor, which is attached to its info table and used by the GHCi debugger and the heap profiler

The original type constructor used in the definition of this data constructor. In case of a data family instance, that will be the family type constructor.

The user-declared type of the data constructor in the nice-to-read form:

T :: forall a b. a -> b -> T [a]

rather than:

T :: forall a c. forall b. (c~[a]) => a -> b -> T c

The type variables are quantified in the order that the user wrote them. See Note [DataCon user type variable binders].

NB: If the constructor is part of a data instance, the result type mentions the family tycon, not the internal one.

The existentially-quantified type/coercion variables of the constructor including dependent (kind-) GADT equalities

Which type variables of this data constructor that must be instantiated to concrete types? For example: the RuntimeRep variables of unboxed tuples and unboxed sums.

See Note [Representation-polymorphism checking built-ins] in GHC.Tc.Gen.Head.

valuedataConInstArgTys
  1. :: DataCon

    A datacon with no existentials or equality constraints However, it can have a dcTheta (notably it can be a class dictionary, with superclasses)

  2. -> [Type]

    Instantiated at these types

  3. -> [Scaled Type]
#

Finds the instantiated types of the arguments required to construct a DataCon representation NB: these INCLUDE any dictionary args but EXCLUDE the data-declaration context, which is discarded It's all post-flattening etc; this is a representation type

Returns the argument types of the wrapper, excluding all dictionary arguments and without substituting for any type variables

Returns the arg types of the worker, including *all* non-dependent evidence, after any flattening has been done and without substituting for any type variables

Were the type variables of the data con written in a different order than the regular order (universal tyvars followed by existential tyvars)?

This is not a cheap test, so we minimize its use in GHC as much as possible. Currently, its only call site in the GHC codebase is in mkDataConRep in MkId, and so dataConUserTyVarsNeedWrapper is only called at most once during a data constructor's lifetime.

valuedataConInstUnivs :: DataCon -> [Type] -> [Type]
#

Given a data constructor dc with n universally quantified type variables a_{1}, a_{2}, ..., a_{n}, and given a list of argument types dc_args of length m where m <= n, then:

dataConInstUnivs dc dc_args

Will return:

[dc_arg_{1}, dc_arg_{2}, ..., dc_arg_{m}, a_{m+1}, ..., a_{n}]

That is, return the list of universal type variables with a_{1}, a_{2}, ..., a_{m} instantiated with dc_arg_{1}, dc_arg_{2}, ..., dc_arg_{m}. It is possible for m to be less than n, in which case the remaining n - m elements will simply be universal type variables (with their kinds possibly instantiated).

Examples:

  • Given the data constructor D :: forall a b. Foo a b and dc_args [Int, Bool], then dataConInstUnivs D dc_args will return [Int, Bool].

  • Given the data constructor D :: forall a b. Foo a b and dc_args [Int], then @dataConInstUnivs D dc_args will return [Int, b].

  • Given the data constructor E :: forall k (a :: k). Bar k a and dc_args [Type], then @dataConInstUnivs D dc_args will return [Type, (a :: Type)].

This is primarily used in GHC.Tc.Deriv.* in service of instantiating data constructors' field types. See Note [Instantiating field types in stock deriving] for a notable example of this.

Strictness/unpack annotations, from user; or, for imported DataCons, from the interface file The list is in one-to-one correspondence with the arity of the DataCon

Gives the number of value arguments (including zero-width coercions) stored by the given DataCon's worker in its Core representation. This may differ from the number of arguments that appear in the source code; see also Note [DataCon arities]

valuedataConWorkId :: DataCon -> Id
#

Get the Id of the DataCon worker: a function that is the "actual" constructor and has no top level binding in the program. The type may be different from the obvious one written in the source program. Panics if there is no such Id for this DataCon

Get the Id of the DataCon wrapper: a function that wraps the "actual" constructor so it has the type visible in the source program: c.f. dataConWorkId. Returns Nothing if there is no wrapper, which occurs for an algebraic data constructor and also for a newtype (whose constructor is inlined compulsorily)

valuesplitDataProductType_maybe
  1. :: Type

    A product type, perhaps

  2. -> Maybe (TyCon, [Type], DataCon, [Scaled Type])
#

Extract the type constructor, type argument, data constructor and it's representation argument types from a type if it is a product type.

Precisely, we return Just for any data type that is all of:

  • Concrete (i.e. constructors visible)

  • Single-constructor

  • ... which has no existentials

Whether the type is a data type or a newtype.

Predicates on DataCons

Return whether this DataCon's worker, in its Core representation, takes any value arguments.

In particular, remember that we include coercion arguments in the arity of the Core representation of the DataCon -- both lifted and unlifted coercions, despite the latter having zero-width runtime representation.

See also Note [DataCon arities].

valueisTypeDataCon :: DataCon -> Bool
#

Is this data constructor in a "type data" declaration? See Note [Type data declarations] in GHC.Rename.Module.

Should this DataCon be allowed in a type even without -XDataKinds? Currently, only Lifted & Unlifted

Promotion related functions

Orphan instances

4 instances