HORIZON HASKELLDocslts/ghc-10.0.x04404a62026-10-19Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 04404a6 · 2026-10-19

Moduleghc-10.0.0.20260917GHC2024

GHC.Core.Make

Handy functions for creating much Core syntax

Contents
  1. Constructing normal syntax
  2. Constructing boxed literals
  3. Floats
  4. Constructing small tuples
  5. Constructing big tuples
  6. Deconstructing big tuples
  7. Constructing list expressions
  8. Constructing Maybe expressions
  9. Error Ids
Synopsis

Constructing normal syntax

valuemkCoreApp
  1. :: CoreExpr

    function

  2. -> CoreExpr

    argument

  3. -> CoreExpr

Construct an expression which represents the application of one expression to the other See Note [Assertion checking in mkCoreApp]

valuemkCoreApps
  1. :: CoreExpr

    function

  2. -> [CoreExpr]

    arguments

  3. -> CoreExpr

Construct an expression which represents the application of a number of expressions to another. The leftmost expression in the list is applied first See Note [Assertion checking in mkCoreApp]

Construct an expression which represents the application of a number of expressions to that of a data constructor expression. The leftmost expression in the list is applied first

A variant of mkCoreConApps constructs an expression which represents the application of a number of expressions to that of a data constructor expression using the wrapper, not the worker, of the data constructor. The leftmost expression in the list is applied first

Create a lambda where the given expression has a number of variables bound over it. The leftmost binder is that bound by the outermost lambda in the result

valuemkWildValBinder :: Mult -> Type -> Id

Make a wildcard binder. This is typically used when you need a binder that you expect to use only at a *binding* site. Do not use it at occurrence sites because it has a single, fixed unique, and it's very easy to get into difficulties with shadowing. That's why it is used so little.

See Note [WildCard binders] in GHC.Core.Opt.Simplify.Env

valuesortQuantVars :: [Var] -> [Var]

Sort the variables, putting type and covars first, in scoped order, and then other Ids

It is a deterministic sort, meaning it doesn't look at the values of Uniques. For explanation why it's important See Note [Unique Determinism] in GHC.Types.Unique.

Constructing boxed literals

Floats

Constructing small tuples

valuemkCoreVarTupTy :: [Id] -> Type

Build the type of a small tuple that holds the specified variables One-tuples are flattened; see Note [Flattening one-tuples]

Build a small tuple holding the specified expressions One-tuples are flattened; see Note [Flattening one-tuples]

Build a small unboxed tuple holding the specified expressions. Do not include the RuntimeRep specifiers; this function calculates them for you. Does not flatten one-tuples; see Note [Flattening one-tuples]

Constructing big tuples

valuemkChunkified
  1. :: ([a] -> a)

    "Small" constructor function, of maximum input arity mAX_TUPLE_SIZE

  2. -> [a]

    Possible "big" list of things to construct from

  3. -> a

    Constructed thing made possible by recursive decomposition

Lifts a "small" constructor into a "big" constructor by recursive decomposition

valuechunkify :: [a] -> [[a]]

Split a list into lists that are small enough to have a corresponding tuple arity. The sub-lists of the result all have length <= mAX_TUPLE_SIZE But there may be more than mAX_TUPLE_SIZE sub-lists

Build a big tuple holding the specified variables One-tuples are flattened; see Note [Flattening one-tuples] Arguments don't have to have kind Type

Build a "big" tuple holding the specified expressions One-tuples are flattened; see Note [Flattening one-tuples] Arguments don't have to have kind Type; ones that do not are boxed This function crashes (in wrapBox) if given a non-Type argument that it doesn't know how to box.

Deconstructing big tuples

valuemkBigTupleSelector
  1. :: [Id]

    The Ids to pattern match the tuple against

  2. -> Id

    The Id to select

  3. -> Id

    A variable of the same type as the scrutinee

  4. -> CoreExpr

    Scrutinee

  5. -> CoreExpr

    Selector expression

Builds a selector which scrutinises the given expression and extracts the one name from the list given. If you want the no-shadowing rule to apply, the caller is responsible for making sure that none of these names are in scope.

If there is just one Id in the tuple, then the selector is just the identity.

If necessary, we pattern match on a "big" tuple.

A tuple selector is not linear in its argument. Consequently, the case expression built by mkBigTupleSelector must consume its scrutinee Many times. And all the argument variables must have multiplicity Many.

mkBigTupleSelectorSolo is like mkBigTupleSelector but one-tuples are NOT flattened (see Note [Flattening one-tuples])

valuemkBigTupleSelectorSolo
  1. :: [Id]

    The Ids to pattern match the tuple against

  2. -> Id

    The Id to select

  3. -> Id

    A variable of the same type as the scrutinee

  4. -> CoreExpr

    Scrutinee

  5. -> CoreExpr

    Selector expression

Builds a selector which scrutinises the given expression and extracts the one name from the list given. If you want the no-shadowing rule to apply, the caller is responsible for making sure that none of these names are in scope.

If there is just one Id in the tuple, then the selector is just the identity.

If necessary, we pattern match on a "big" tuple.

A tuple selector is not linear in its argument. Consequently, the case expression built by mkBigTupleSelector must consume its scrutinee Many times. And all the argument variables must have multiplicity Many.

valuemkBigTupleCase
  1. :: MonadUnique m
  2. => [Id]

    The tuple identifiers to pattern match on; Bring these into scope in the body

  3. -> CoreExpr

    Body of the case

  4. -> CoreExpr

    Scrutinee

  5. -> m CoreExpr

A generalization of mkBigTupleSelector, allowing the body of the case to be an arbitrary expression.

To avoid shadowing, we use uniques to invent new variables.

If necessary we pattern match on a "big" tuple.

Constructing list expressions

Constructing Maybe expressions

Error Ids