HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Code generator views onto Types

valueunwrapType :: Type -> Type

Gets rid of the stuff that prevents us from understanding the runtime representation of a type. Including: 1. Casts 2. Newtypes 3. Foralls 4. Synonyms But not type/data families, because we don't have the envs to hand.

Predicates on types

Type representation for the code generator

Discovers the primitive representation of a Type. Returns a list of PrimRep: it's a list because of the possibility of no runtime representation (void) or multiple (unboxed tuple/sum) See also Note [Getting from RuntimeRep to PrimRep]

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
  • Eq PrimRepDefined in ghc-10.0.0.20260917 · GHC.Core.TyCon
  • Data PrimRepDefined in ghc-10.0.0.20260917 · GHC.Core.TyCon
  • Ord PrimRepDefined in ghc-10.0.0.20260917 · GHC.Core.TyCon
  • Show PrimRepDefined in ghc-10.0.0.20260917 · GHC.Core.TyCon
  • Outputable PrimRepDefined in ghc-10.0.0.20260917 · GHC.Core.TyCon
  • Binary PrimRepDefined in ghc-10.0.0.20260917 · GHC.Core.TyCon

Convert a PrimRep back to a Type. Used only in the unariser to give types to fresh Ids. Really, only the type's representation matters. See also Note [RuntimeRep and PrimRep]

Count the arity of a function post-unarisation, including zero-width arguments.

The post-unarisation arity may be larger than the arity of the original function type. See Note [Unarisation].

Take a type of kind RuntimeRep and extract the list of PrimRep that it encodes. See also Note [Getting from RuntimeRep to PrimRep]. The [PrimRep] is the final runtime representation after unarisation.

Returns Nothing if rep can't be determined. Eg. levity polymorphic types.

Discovers the primitive representation of a Type. Returns a list of PrimRep: it's a list because of the possibility of no runtime representation (void) or multiple (unboxed tuple/sum) See also Note [Getting from RuntimeRep to PrimRep] Returns Nothing if rep can't be determined. Eg. levity polymorphic types.

Unboxed sum representation type

Given the arguments of a sum type constructor application, return the unboxed sum rep type.

E.g.

(# Int# | Maybe Int | (# Int#, Float# #) #)

We call `ubxSumRepType [ [IntRep], [LiftedRep], [IntRep, FloatRep] ]`, which returns [WordSlot, PtrSlot, WordSlot, FloatSlot]

INVARIANT: Result slots are sorted (via Ord SlotTy), except that at the head of the list we have the slot for the tag.

Is this type known to be data?

valuemightBeFunTy :: Type -> Bool

Might this type be a function type, including after looking through newtypes and reducing type family applications?

In particular, returns True for IO a: after unwrapping the newtype, we get State# RealWorld -> (# State# RealWorld, a #), which is indeed a function type.

This function is conservative: it returns False only if the type is **definitely not** a function type. It returns True when it's not sure, e.g. for a type family application.

This function is generally used when we can perform certain optimisations when we are sure a type is not a function type (i.e. operationally does not take a value argument at runtime).

This is different from isFunTy, which only returns True when the type is a function arrow on-the-nose (without looking through newtypes). In particular, isFunTy returns False for IO () as well as for all type family applications.