ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Core

Contents

- Main data types
- In/Out type synonyms
  - `Expr` construction
  - Simple `Expr` access functions and predicates
- Unfolding data types
  - Constructing `Unfolding`s
  - Predicates and deconstruction on `Unfolding`
- Annotated expression data types
  - Operations on annotated expressions
  - Operations on annotations
- Orphanhood
- Core rule data types
  - Operations on `CoreRule`s

Description

GHC.Core holds all the main data types for use by for the Glasgow Haskell Compiler midsection

Synopsis

- data Expr b
  - = Var Id
  - | Lit Literal
  - | App (Expr b) (Arg b)
  - | Lam b (Expr b)
  - | Let (Bind b) (Expr b)
  - | Case (Expr b) b Type [Alt b]
  - | Cast (Expr b) CoercionR
  - | Tick CoreTickish (Expr b)
  - | Type Type
  - | Coercion Coercion
- data Alt b = Alt AltCon [b] (Expr b)
- data Bind b
  - = NonRec b (Expr b)
  - | Rec [(b, Expr b)]
- data AltCon
  - = DataAlt DataCon
  - | LitAlt Literal
  - | DEFAULT
- type Arg b = Expr b
- type CoreProgram = [CoreBind]
- type CoreExpr = Expr CoreBndr
- type CoreAlt = Alt CoreBndr
- type CoreBind = Bind CoreBndr
- type CoreArg = Arg CoreBndr
- type CoreBndr = Var
- type TaggedExpr t = Expr (TaggedBndr t)
- type TaggedAlt t = Alt (TaggedBndr t)
- type TaggedBind t = Bind (TaggedBndr t)
- type TaggedArg t = Arg (TaggedBndr t)
- data TaggedBndr t = TB CoreBndr t
- deTagExpr :: TaggedExpr t -> CoreExpr
- type InId = Id
- type InBind = CoreBind
- type InExpr = CoreExpr
- type InAlt = CoreAlt
- type InArg = CoreArg
- type InType = Type
- type InKind = Kind
- type InBndr = CoreBndr
- type InVar = Var
- type InCoercion = Coercion
- type InTyVar = TyVar
- type InCoVar = CoVar
- type InTyCoVar = TyCoVar
- type OutId = Id
- type OutBind = CoreBind
- type OutExpr = CoreExpr
- type OutAlt = CoreAlt
- type OutArg = CoreArg
- type OutType = Type
- type OutKind = Kind
- type OutBndr = CoreBndr
- type OutVar = Var
- type OutCoercion = Coercion
- type OutTyVar = TyVar
- type OutCoVar = CoVar
- type OutTyCoVar = TyCoVar
- type MOutCoercion = MCoercion
- mkLet :: Bind b -> Expr b -> Expr b
- mkLets :: [Bind b] -> Expr b -> Expr b
- mkLetNonRec :: b -> Expr b -> Expr b -> Expr b
- mkLetRec :: [(b, Expr b)] -> Expr b -> Expr b
- mkLams :: [b] -> Expr b -> Expr b
- mkApps :: Expr b -> [Arg b] -> Expr b
- mkTyApps :: Expr b -> [Type] -> Expr b
- mkCoApps :: Expr b -> [Coercion] -> Expr b
- mkVarApps :: Expr b -> [Var] -> Expr b
- mkTyArg :: Type -> Expr b
- mkIntLit :: Platform -> Integer -> Expr b
- mkIntLitWrap :: Platform -> Integer -> Expr b
- mkWordLit :: Platform -> Integer -> Expr b
- mkWordLitWrap :: Platform -> Integer -> Expr b
- mkWord8Lit :: Integer -> Expr b
- mkWord32LitWord32 :: Word32 -> Expr b
- mkWord64LitWord64 :: Word64 -> Expr b
- mkInt64LitInt64 :: Int64 -> Expr b
- mkCharLit :: Char -> Expr b
- mkStringLit :: String -> Expr b
- mkFloatLit :: Rational -> Expr b
- mkFloatLitFloat :: Float -> Expr b
- mkDoubleLit :: Rational -> Expr b
- mkDoubleLitDouble :: Double -> Expr b
- mkConApp :: DataCon -> [Arg b] -> Expr b
- mkConApp2 :: DataCon -> [Type] -> [Var] -> Expr b
- mkTyBind :: TyVar -> Type -> CoreBind
- mkCoBind :: CoVar -> Coercion -> CoreBind
- varToCoreExpr :: CoreBndr -> Expr b
- varsToCoreExprs :: [CoreBndr] -> [Expr b]
- mkBinds :: RecFlag -> [(b, Expr b)] -> [Bind b]
- isId :: Var -> Bool
- cmpAltCon :: AltCon -> AltCon -> Ordering
- cmpAlt :: Alt a -> Alt a -> Ordering
- ltAlt :: Alt a -> Alt a -> Bool
- bindersOf :: Bind b -> [b]
- bindersOfBinds :: [Bind b] -> [b]
- rhssOfBind :: Bind b -> [Expr b]
- rhssOfBinds :: [Bind b] -> [Expr b]
- rhssOfAlts :: [Alt b] -> [Expr b]
- foldBindersOfBindStrict :: (a -> b -> a) -> a -> Bind b -> a
- foldBindersOfBindsStrict :: (a -> b -> a) -> a -> [Bind b] -> a
- collectBinders :: Expr b -> ([b], Expr b)
- collectTyBinders :: CoreExpr -> ([TyVar], CoreExpr)
- collectTyAndValBinders :: CoreExpr -> ([TyVar], [Id], CoreExpr)
- collectNBinders :: JoinArity -> Expr b -> ([b], Expr b)
- collectNValBinders_maybe :: Arity -> CoreExpr -> Maybe ([Var], CoreExpr)
- collectArgs :: Expr b -> (Expr b, [Arg b])
- collectValArgs :: Expr b -> (Expr b, [Arg b])
- stripNArgs :: Word -> Expr a -> Maybe (Expr a)
- collectArgsTicks :: (CoreTickish -> Bool) -> Expr b -> (Expr b, [Arg b], [CoreTickish])
- flattenBinds :: [Bind b] -> [(b, Expr b)]
- collectFunSimple :: Expr b -> Expr b
- exprToType :: CoreExpr -> Type
- wrapLamBody :: (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
- isValArg :: Expr b -> Bool
- isTypeArg :: Expr b -> Bool
- isCoArg :: Expr b -> Bool
- isTyCoArg :: Expr b -> Bool
- valArgCount :: [Arg b] -> Int
- valBndrCount :: [CoreBndr] -> Int
- isRuntimeArg :: CoreExpr -> Bool
- isRuntimeVar :: Var -> Bool
- data Unfolding
  - = NoUnfolding
  - | BootUnfolding
  - | OtherCon [AltCon]
  - | DFunUnfolding {
    - df_bndrs :: [Var]
    - df_con :: DataCon
    - df_args :: [CoreExpr]
    }
  - | CoreUnfolding {
    - uf_tmpl :: CoreExpr
    - uf_src :: UnfoldingSource
    - uf_is_top :: Bool
    - uf_cache :: UnfoldingCache
    - uf_guidance :: UnfoldingGuidance
    }
- data UnfoldingCache = UnfoldingCache {
  - uf_is_value :: !Bool
  - uf_is_conlike :: !Bool
  - uf_is_work_free :: !Bool
  - uf_expandable :: !Bool
  }
- data UnfoldingGuidance
  - = UnfWhen {
    - ug_arity :: Arity
    - ug_unsat_ok :: Bool
    - ug_boring_ok :: Bool
    }
  - | UnfIfGoodArgs {
    - ug_args :: [Int]
    - ug_size :: Int
    - ug_res :: Int
    }
  - | UnfNever
- data UnfoldingSource
  - = VanillaSrc
  - | StableUserSrc
  - | StableSystemSrc
  - | CompulsorySrc
- noUnfolding :: Unfolding
- bootUnfolding :: Unfolding
- evaldUnfolding :: Unfolding
- mkOtherCon :: [AltCon] -> Unfolding
- unSaturatedOk :: Bool
- needSaturated :: Bool
- boringCxtOk :: Bool
- boringCxtNotOk :: Bool
- expandUnfolding_maybe :: Unfolding -> Maybe CoreExpr
- maybeUnfoldingTemplate :: Unfolding -> Maybe CoreExpr
- otherCons :: Unfolding -> [AltCon]
- isValueUnfolding :: Unfolding -> Bool
- isEvaldUnfolding :: Unfolding -> Bool
- isCheapUnfolding :: Unfolding -> Bool
- isExpandableUnfolding :: Unfolding -> Bool
- isConLikeUnfolding :: Unfolding -> Bool
- isCompulsoryUnfolding :: Unfolding -> Bool
- isStableUnfolding :: Unfolding -> Bool
- isStableUserUnfolding :: Unfolding -> Bool
- isStableSystemUnfolding :: Unfolding -> Bool
- isInlineUnfolding :: Unfolding -> Bool
- isBootUnfolding :: Unfolding -> Bool
- isBetterUnfoldingThan :: Unfolding -> Unfolding -> Bool
- hasCoreUnfolding :: Unfolding -> Bool
- hasSomeUnfolding :: Unfolding -> Bool
- canUnfold :: Unfolding -> Bool
- neverUnfoldGuidance :: UnfoldingGuidance -> Bool
- isStableSource :: UnfoldingSource -> Bool
- type AnnExpr bndr annot = (annot, AnnExpr' bndr annot)
- data AnnExpr' bndr annot
  - = AnnVar Id
  - | AnnLit Literal
  - | AnnLam bndr (AnnExpr bndr annot)
  - | AnnApp (AnnExpr bndr annot) (AnnExpr bndr annot)
  - | AnnCase (AnnExpr bndr annot) bndr Type [AnnAlt bndr annot]
  - | AnnLet (AnnBind bndr annot) (AnnExpr bndr annot)
  - | AnnCast (AnnExpr bndr annot) (annot, Coercion)
  - | AnnTick CoreTickish (AnnExpr bndr annot)
  - | AnnType Type
  - | AnnCoercion Coercion
- data AnnBind bndr annot
  - = AnnNonRec bndr (AnnExpr bndr annot)
  - | AnnRec [(bndr, AnnExpr bndr annot)]
- data AnnAlt bndr annot = AnnAlt AltCon [bndr] (AnnExpr bndr annot)
- collectAnnArgs :: AnnExpr b a -> (AnnExpr b a, [AnnExpr b a])
- collectAnnArgsTicks :: (CoreTickish -> Bool) -> AnnExpr b a -> (AnnExpr b a, [AnnExpr b a], [CoreTickish])
- deAnnotate :: AnnExpr bndr annot -> Expr bndr
- deAnnotate' :: AnnExpr' bndr annot -> Expr bndr
- deAnnAlt :: AnnAlt bndr annot -> Alt bndr
- deAnnBind :: AnnBind b annot -> Bind b
- collectAnnBndrs :: AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
- collectNAnnBndrs :: Int -> AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
- data IsOrphan
  - = IsOrphan
  - | NotOrphan !OccName
- isOrphan :: IsOrphan -> Bool
- notOrphan :: IsOrphan -> Bool
- chooseOrphanAnchor :: NameSet -> IsOrphan
- data CoreRule
  - = Rule {
    - ru_name :: RuleName
    - ru_act :: Activation
    - ru_fn :: !Name
    - ru_rough :: [Maybe Name]
    - ru_bndrs :: [CoreBndr]
    - ru_args :: [CoreExpr]
    - ru_rhs :: CoreExpr
    - ru_auto :: Bool
    - ru_origin :: !Module
    - ru_orphan :: !IsOrphan
    - ru_local :: Bool
    }
  - | BuiltinRule {
    - ru_name :: RuleName
    - ru_fn :: Name
    - ru_nargs :: Int
    - ru_try :: RuleFun
    }
- type RuleName = FastString
- type RuleFun = RuleOpts -> InScopeEnv -> Id -> [CoreExpr] -> Maybe CoreExpr
- type IdUnfoldingFun = Id -> Unfolding
- data InScopeEnv = ISE InScopeSet IdUnfoldingFun
- data RuleOpts
- ruleArity :: CoreRule -> FullArgCount
- ruleName :: CoreRule -> RuleName
- ruleIdName :: CoreRule -> Name
- ruleActivation :: CoreRule -> Activation
- setRuleIdName :: Name -> CoreRule -> CoreRule
- ruleModule :: CoreRule -> Maybe Module
- isBuiltinRule :: CoreRule -> Bool
- isLocalRule :: CoreRule -> Bool
- isAutoRule :: CoreRule -> Bool

# Main data types

data Expr b #

This is the data type that represents GHCs core intermediate language. Currently GHC uses System FC https://www.microsoft.com/en-us/research/publication/system-f-with-type-equality-coercions/ for this purpose, which is closely related to the simpler and better known System F http://en.wikipedia.org/wiki/System_F.

We get from Haskell source to this Core language in a number of stages:

1. The source code is parsed into an abstract syntax tree, which is represented by the data type `HsExpr` with the names being `RdrNames`
2. This syntax tree is renamed, which attaches a `Unique` to every `RdrName` (yielding a `Name`) to disambiguate identifiers which are lexically identical. For example, this program:

         f x = let f x = x + 1
               in f (x - 2)

Would be renamed by having `Unique`s attached so it looked something like this:

         f_1 x_2 = let f_3 x_4 = x_4 + 1
                   in f_3 (x_2 - 2)

But see Note [Shadowing in Core] below.

1. The resulting syntax tree undergoes type checking (which also deals with instantiating type class arguments) to yield a `HsExpr` type that has `Id` as it's names.
2. Finally the syntax tree is desugared from the expressive `HsExpr` type into this `Expr` type, which has far fewer constructors and hence is easier to perform optimization, analysis and code generation on.

The type parameter `b` is for the type of binders in the expression tree.

The language consists of the following elements:

- Variables See Note [Variable occurrences in Core]
- Primitive literals
- Applications: note that the argument may be a `Type`. See Note [Representation polymorphism invariants]
- Lambda abstraction See Note [Representation polymorphism invariants]
- Recursive and non recursive `let`s. Operationally this corresponds to allocating a thunk for the things bound and then executing the sub-expression.

See Note [Core letrec invariant] See Note [Core let-can-float invariant] See Note [Representation polymorphism invariants] See Note [Core type and coercion invariant]

- Case expression. Operationally this corresponds to evaluating the scrutinee (expression examined) to weak head normal form and then examining at most one level of resulting constructor (i.e. you cannot do nested pattern matching directly with this).

The binder gets bound to the value of the scrutinee, and the `Type` must be that of all the case alternatives

IMPORTANT: see Note [Case expression invariants]

- Cast an expression to a particular type. This is used to implement `newtype`s (a `newtype` constructor or destructor just becomes a `Cast` in Core) and GADTs.
- Ticks. These are used to represent all the source annotation we support: profiling SCCs, HPC ticks, and GHCi breakpoints.
- A type: this should only show up at the top level of an Arg
- A coercion

Constructors

Var Id |
Lit Literal |
App (Expr b) (Arg b) infixl 4 |
Lam b (Expr b) |
Let (Bind b) (Expr b) |
Case (Expr b) b Type [Alt b] |
Cast (Expr b) CoercionR |
Tick CoreTickish (Expr b) |
Type Type |
Coercion Coercion |

#### Instances

Instances details

Data b => Data (Expr b) # |
Instance details Defined in GHC.Core Methods gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Expr b -> c (Expr b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Expr b) # toConstr :: Expr b -> Constr # dataTypeOf :: Expr b -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Expr b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> Expr b -> Expr b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r # gmapQ :: (forall d. Data d => d -> u) -> Expr b -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Expr b -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Expr b -> m (Expr b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Expr b -> m (Expr b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Expr b -> m (Expr b) #
OutputableBndr b => Outputable (Expr b) # |
Instance details Defined in GHC.Core.Ppr Methods ppr :: Expr b -> SDoc #
Eq (DeBruijn CoreExpr) # |
Instance details Defined in GHC.Core.Map.Expr Methods (==) :: DeBruijn CoreExpr -> DeBruijn CoreExpr -> Bool # (/=) :: DeBruijn CoreExpr -> DeBruijn CoreExpr -> Bool #

data Alt b #

A case split alternative. Consists of the constructor leading to the alternative, the variables bound from the constructor, and the expression to be executed given that binding. The default alternative is `(DEFAULT, [], rhs)`

Constructors

Alt AltCon [b] (Expr b) |

#### Instances

Instances details

Data b => Data (Alt b) # |
Instance details Defined in GHC.Core Methods gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Alt b -> c (Alt b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Alt b) # toConstr :: Alt b -> Constr # dataTypeOf :: Alt b -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Alt b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Alt b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> Alt b -> Alt b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r # gmapQ :: (forall d. Data d => d -> u) -> Alt b -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Alt b -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Alt b -> m (Alt b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Alt b -> m (Alt b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Alt b -> m (Alt b) #
OutputableBndr b => Outputable (Alt b) # |
Instance details Defined in GHC.Core.Ppr Methods ppr :: Alt b -> SDoc #
Eq (DeBruijn CoreAlt) # |
Instance details Defined in GHC.Core.Map.Expr Methods (==) :: DeBruijn CoreAlt -> DeBruijn CoreAlt -> Bool # (/=) :: DeBruijn CoreAlt -> DeBruijn CoreAlt -> Bool #

data Bind b #

Binding, used for top level bindings in a module and local bindings in a `let`.

Constructors

NonRec b (Expr b) |
Rec [(b, Expr b)] |

#### Instances

Instances details

Data b => Data (Bind b) # |
Instance details Defined in GHC.Core Methods gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Bind b -> c (Bind b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Bind b) # toConstr :: Bind b -> Constr # dataTypeOf :: Bind b -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Bind b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Bind b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> Bind b -> Bind b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r # gmapQ :: (forall d. Data d => d -> u) -> Bind b -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Bind b -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Bind b -> m (Bind b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Bind b -> m (Bind b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Bind b -> m (Bind b) #
OutputableBndr b => Outputable (Bind b) # |
Instance details Defined in GHC.Core.Ppr Methods ppr :: Bind b -> SDoc #

data AltCon #

A case alternative constructor (i.e. pattern match)

Constructors

DataAlt DataCon |
LitAlt Literal | A literal: `case e of { 1 -> ... }` Invariant: always an *unlifted* literal See Note [Literal alternatives]
DEFAULT | Trivial alternative: `case e of { _ -> ... }`

#### Instances

Instances details

Data AltCon # |
Instance details Defined in GHC.Core Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> AltCon -> c AltCon # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c AltCon # toConstr :: AltCon -> Constr # dataTypeOf :: AltCon -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c AltCon) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AltCon) # gmapT :: (forall b. Data b => b -> b) -> AltCon -> AltCon # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AltCon -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AltCon -> r # gmapQ :: (forall d. Data d => d -> u) -> AltCon -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> AltCon -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> AltCon -> m AltCon # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> AltCon -> m AltCon # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> AltCon -> m AltCon #
Outputable AltCon # |
Instance details Defined in GHC.Core Methods ppr :: AltCon -> SDoc #
Eq AltCon # |
Instance details Defined in GHC.Core Methods (==) :: AltCon -> AltCon -> Bool # (/=) :: AltCon -> AltCon -> Bool #
Ord AltCon # |
Instance details Defined in GHC.Core Methods compare :: AltCon -> AltCon -> Ordering # (<) :: AltCon -> AltCon -> Bool # (<=) :: AltCon -> AltCon -> Bool # (>) :: AltCon -> AltCon -> Bool # (>=) :: AltCon -> AltCon -> Bool # max :: AltCon -> AltCon -> AltCon # min :: AltCon -> AltCon -> AltCon #

type Arg b = Expr b #

Type synonym for expressions that occur in function argument positions. Only `Arg` should contain a `Type` at top level, general `Expr` should not

type CoreProgram = [CoreBind] #

type CoreExpr = Expr CoreBndr #

Expressions where binders are `CoreBndr`s

type CoreAlt = Alt CoreBndr #

Case alternatives where binders are `CoreBndr`s

type CoreBind = Bind CoreBndr #

Binding groups where binders are `CoreBndr`s

type CoreArg = Arg CoreBndr #

Argument expressions where binders are `CoreBndr`s

type CoreBndr = Var #

The common case for the type of binders and variables when we are manipulating the Core language within GHC

type TaggedExpr t = Expr (TaggedBndr t) #

type TaggedAlt t = Alt (TaggedBndr t) #

type TaggedBind t = Bind (TaggedBndr t) #

type TaggedArg t = Arg (TaggedBndr t) #

data TaggedBndr t #

Binders are tagged with a t

Constructors

TB CoreBndr t |

#### Instances

Instances details

Outputable b => Outputable (TaggedBndr b) # |
Instance details Defined in GHC.Core Methods ppr :: TaggedBndr b -> SDoc #
Outputable b => OutputableBndr (TaggedBndr b) # |
Instance details Defined in GHC.Core.Ppr Methods pprBndr :: BindingSite -> TaggedBndr b -> SDoc # pprPrefixOcc :: TaggedBndr b -> SDoc # pprInfixOcc :: TaggedBndr b -> SDoc # bndrIsJoin_maybe :: TaggedBndr b -> JoinPointHood #

deTagExpr :: TaggedExpr t -> CoreExpr #

# In/Out type synonyms

type InId = Id #

type InBind = CoreBind #

type InExpr = CoreExpr #

type InAlt = CoreAlt #

type InArg = CoreArg #

type InType = Type #

type InKind = Kind #

type InBndr = CoreBndr #

type InVar = Var #

type InCoercion = Coercion #

type InTyVar = TyVar #

type InCoVar = CoVar #

type InTyCoVar = TyCoVar #

type OutId = Id #

type OutBind = CoreBind #

type OutExpr = CoreExpr #

type OutAlt = CoreAlt #

type OutArg = CoreArg #

type OutType = Type #

type OutKind = Kind #

type OutBndr = CoreBndr #

type OutVar = Var #

type OutCoercion = Coercion #

type OutTyVar = TyVar #

type OutCoVar = CoVar #

type OutTyCoVar = TyCoVar #

type MOutCoercion = MCoercion #

## `Expr` construction

mkLet :: Bind b -> Expr b -> Expr b #

mkLets :: [Bind b] -> Expr b -> Expr b #

Bind all supplied binding groups over an expression in a nested let expression. Assumes that the rhs satisfies the let-can-float invariant. Prefer to use `mkCoreLets` if possible, which does guarantee the invariant

mkLetNonRec :: b -> Expr b -> Expr b -> Expr b #

`mkLetNonRec bndr rhs body` wraps `body` in a `let` binding `bndr`.

mkLetRec :: [(b, Expr b)] -> Expr b -> Expr b #

`mkLetRec binds body` wraps `body` in a `let rec` with the given set of `binds` if binds is non-empty.

mkLams :: [b] -> Expr b -> Expr b #

Bind all supplied binders over an expression in a nested lambda expression. Prefer to use `mkCoreLams` if possible

mkApps :: Expr b -> [Arg b] -> Expr b infixl 4 #

Apply a list of argument expressions to a function expression in a nested fashion. Prefer to use `mkCoreApps` if possible

mkTyApps :: Expr b -> [Type] -> Expr b infixl 4 #

Apply a list of type argument expressions to a function expression in a nested fashion

mkCoApps :: Expr b -> [Coercion] -> Expr b infixl 4 #

Apply a list of coercion argument expressions to a function expression in a nested fashion

mkVarApps :: Expr b -> [Var] -> Expr b infixl 4 #

Apply a list of type or value variables to a function expression in a nested fashion

mkTyArg :: Type -> Expr b #

mkIntLit :: Platform -> Integer -> Expr b #

Create a machine integer literal expression of type `Int#` from an `Integer`. If you want an expression of type `Int` use `mkIntExpr`

mkIntLitWrap :: Platform -> Integer -> Expr b #

Create a machine integer literal expression of type `Int#` from an `Integer`, wrapping if necessary. If you want an expression of type `Int` use `mkIntExpr`

mkWordLit :: Platform -> Integer -> Expr b #

Create a machine word literal expression of type `Word#` from an `Integer`. If you want an expression of type `Word` use `mkWordExpr`

mkWordLitWrap :: Platform -> Integer -> Expr b #

Create a machine word literal expression of type `Word#` from an `Integer`, wrapping if necessary. If you want an expression of type `Word` use `mkWordExpr`

mkWord8Lit :: Integer -> Expr b #

mkWord32LitWord32 :: Word32 -> Expr b #

mkWord64LitWord64 :: Word64 -> Expr b #

mkInt64LitInt64 :: Int64 -> Expr b #

mkCharLit :: Char -> Expr b #

Create a machine character literal expression of type `Char#`. If you want an expression of type `Char` use `mkCharExpr`

mkStringLit :: String -> Expr b #

Create a machine string literal expression of type `Addr#`. If you want an expression of type `String` use `mkStringExpr`

mkFloatLit :: Rational -> Expr b #

Create a machine single precision literal expression of type `Float#` from a `Rational`. If you want an expression of type `Float` use `mkFloatExpr`

mkFloatLitFloat :: Float -> Expr b #

Create a machine single precision literal expression of type `Float#` from a `Float`. If you want an expression of type `Float` use `mkFloatExpr`

mkDoubleLit :: Rational -> Expr b #

Create a machine double precision literal expression of type `Double#` from a `Rational`. If you want an expression of type `Double` use `mkDoubleExpr`

mkDoubleLitDouble :: Double -> Expr b #

Create a machine double precision literal expression of type `Double#` from a `Double`. If you want an expression of type `Double` use `mkDoubleExpr`

mkConApp :: DataCon -> [Arg b] -> Expr b #

Apply a list of argument expressions to a data constructor in a nested fashion. Prefer to use `mkCoreConApps` if possible

mkConApp2 :: DataCon -> [Type] -> [Var] -> Expr b #

mkTyBind :: TyVar -> Type -> CoreBind #

Create a binding group where a type variable is bound to a type. Per Note [Core type and coercion invariant], this can only be used to bind something in a non-recursive `let` expression

mkCoBind :: CoVar -> Coercion -> CoreBind #

Create a binding group where a type variable is bound to a type. Per Note [Core type and coercion invariant], this can only be used to bind something in a non-recursive `let` expression

varToCoreExpr :: CoreBndr -> Expr b #

Convert a binder into either a `Var` or `Type` `Expr` appropriately

varsToCoreExprs :: [CoreBndr] -> [Expr b] #

mkBinds :: RecFlag -> [(b, Expr b)] -> [Bind b] #

Helper function. You can use the result of `mkBinds` with `mkLets` for instance.

- ``mkBinds` `Recursive` binds` makes a single mutually-recursive bindings with all the rhs/lhs pairs in `binds`
- ``mkBinds` `NonRecursive` binds` makes one non-recursive binding for each rhs/lhs pairs in `binds`

isId :: Var -> Bool #

Is this a value-level (i.e., computationally relevant) `Id`entifier? Satisfies `isId = not . isTyVar`.

cmpAltCon :: AltCon -> AltCon -> Ordering #

Compares `AltCon`s within a single list of alternatives DEFAULT comes out smallest, so that sorting by AltCon puts alternatives in the order required: see Note [Case expression invariants]

cmpAlt :: Alt a -> Alt a -> Ordering #

ltAlt :: Alt a -> Alt a -> Bool #

## Simple `Expr` access functions and predicates

bindersOf :: Bind b -> [b] #

Extract every variable by this group

bindersOfBinds :: [Bind b] -> [b] #

`bindersOf` applied to a list of binding groups

rhssOfBind :: Bind b -> [Expr b] #

rhssOfBinds :: [Bind b] -> [Expr b] #

rhssOfAlts :: [Alt b] -> [Expr b] #

foldBindersOfBindStrict :: (a -> b -> a) -> a -> Bind b -> a #

foldBindersOfBindsStrict :: (a -> b -> a) -> a -> [Bind b] -> a #

collectBinders :: Expr b -> ([b], Expr b) #

We often want to strip off leading lambdas before getting down to business. Variants are `collectTyBinders`, `collectValBinders`, and `collectTyAndValBinders`

collectTyBinders :: CoreExpr -> ([TyVar], CoreExpr) #

collectTyAndValBinders :: CoreExpr -> ([TyVar], [Id], CoreExpr) #

collectNBinders :: JoinArity -> Expr b -> ([b], Expr b) #

Strip off exactly N leading lambdas (type or value). Good for use with join points. Panic if there aren't enough

collectNValBinders_maybe :: Arity -> CoreExpr -> Maybe ([Var], CoreExpr) #

Strip off exactly N leading value lambdas returning all the binders found up to that point Return Nothing if there aren't enough

collectArgs :: Expr b -> (Expr b, [Arg b]) #

Takes a nested application expression and returns the function being applied and the arguments to which it is applied

collectValArgs :: Expr b -> (Expr b, [Arg b]) #

Takes a nested application expression and returns the function being applied and the arguments to which it is applied

stripNArgs :: Word -> Expr a -> Maybe (Expr a) #

Attempt to remove the last N arguments of a function call. Strip off any ticks or coercions encountered along the way and any at the end.

collectArgsTicks :: (CoreTickish -> Bool) -> Expr b -> (Expr b, [Arg b], [CoreTickish]) #

Like `collectArgs`, but also looks through floatable ticks if it means that we can find more arguments.

flattenBinds :: [Bind b] -> [(b, Expr b)] #

Collapse all the bindings in the supplied groups into a single list of lhs/rhs pairs suitable for binding in a `Rec` binding group

collectFunSimple :: Expr b -> Expr b #

Takes a nested application expression and returns the function being applied. Looking through casts and ticks to find it.

exprToType :: CoreExpr -> Type #

If the expression is a `Type`, converts. Otherwise, panics. NB: This does not convert `Coercion` to `CoercionTy`.

wrapLamBody :: (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr #

fmap on the body of a lambda. wrapLamBody f (x -> body) == (x -> f body)

isValArg :: Expr b -> Bool #

Returns `True` for value arguments, false for type args NB: coercions are value arguments (zero width, to be sure, like State#, but still value args).

isTypeArg :: Expr b -> Bool #

Returns `True` iff the expression is a `Type` expression at its top level. Note this does NOT include `Coercion`s.

isCoArg :: Expr b -> Bool #

Returns `True` iff the expression is a `Coercion` expression at its top level

isTyCoArg :: Expr b -> Bool #

Returns `True` iff the expression is a `Type` or `Coercion` expression at its top level

valArgCount :: [Arg b] -> Int #

The number of argument expressions that are values rather than types at their top level

valBndrCount :: [CoreBndr] -> Int #

The number of binders that bind values rather than types

isRuntimeArg :: CoreExpr -> Bool #

Will this argument expression exist at runtime?

isRuntimeVar :: Var -> Bool #

Will this variable exist at runtime?

# Unfolding data types

data Unfolding #

Records the unfolding of an identifier, which is approximately the form the identifier would have if we substituted its definition in for the identifier. This type should be treated as abstract everywhere except in GHC.Core.Unfold

Constructors

NoUnfolding | We have no information about the unfolding.
BootUnfolding | We have no information about the unfolding, because this `Id` came from an `hi-boot` file. See Note [Inlining and hs-boot files] in GHC.CoreToIface for what this is used for.
OtherCon [AltCon] | It ain't one of these constructors. `OtherCon xs` also indicates that something has been evaluated and hence there's no point in re-evaluating it. `OtherCon []` is used even for non-data-type values to indicated evaluated-ness. Notably:
    data C = C !(Int -> Int)
    case x of { C f -> ... }
Here, `f` gets an `OtherCon []` unfolding.
DFunUnfolding |
Fields df_bndrs :: [Var] df_con :: DataCon df_args :: [CoreExpr]
CoreUnfolding | An unfolding with redundant cached information. Parameters: uf_tmpl: Template used to perform unfolding; NB: Occurrence info is guaranteed correct: see Note [OccInfo in unfoldings and rules] uf_is_top: Is this a top level binding? uf_is_value: `exprIsHNF` template (cached); it is ok to discard a `seq` on this variable uf_is_work_free: Does this waste only a little work if we expand it inside an inlining? Basically this is a cached version of `exprIsWorkFree` uf_guidance: Tells us about the size of the unfolding template
Fields uf_tmpl :: CoreExpr uf_src :: UnfoldingSource uf_is_top :: Bool uf_cache :: UnfoldingCache uf_guidance :: UnfoldingGuidance

#### Instances

Instances details

Outputable Unfolding # |
Instance details Defined in GHC.Core.Ppr Methods ppr :: Unfolding -> SDoc #

data UnfoldingCache #

Properties of a `CoreUnfolding` that could be computed on-demand from its template. See Note [UnfoldingCache]

Constructors

UnfoldingCache |
Fields uf_is_value :: !Bool uf_is_conlike :: !Bool uf_is_work_free :: !Bool uf_expandable :: !Bool

#### Instances

Instances details

Outputable UnfoldingCache # |
Instance details Defined in GHC.Core.Ppr Methods ppr :: UnfoldingCache -> SDoc #
Eq UnfoldingCache # |
Instance details Defined in GHC.Core Methods (==) :: UnfoldingCache -> UnfoldingCache -> Bool # (/=) :: UnfoldingCache -> UnfoldingCache -> Bool #

data UnfoldingGuidance #

`UnfoldingGuidance` says when unfolding should take place

Constructors

UnfWhen |
Fields ug_arity :: Arity ug_unsat_ok :: Bool ug_boring_ok :: Bool
UnfIfGoodArgs |
Fields ug_args :: [Int] ug_size :: Int ug_res :: Int
UnfNever |

#### Instances

Instances details

Outputable UnfoldingGuidance # |
Instance details Defined in GHC.Core.Ppr Methods ppr :: UnfoldingGuidance -> SDoc #
Eq UnfoldingGuidance # |
Instance details Defined in GHC.Core Methods (==) :: UnfoldingGuidance -> UnfoldingGuidance -> Bool # (/=) :: UnfoldingGuidance -> UnfoldingGuidance -> Bool #

data UnfoldingSource #

Constructors

VanillaSrc |
StableUserSrc |
StableSystemSrc |
CompulsorySrc |

#### Instances

Instances details

NFData UnfoldingSource # |
Instance details Defined in GHC.Types.Basic Methods rnf :: UnfoldingSource -> () #
Binary UnfoldingSource # |
Instance details Defined in GHC.Types.Basic Methods put_ :: WriteBinHandle -> UnfoldingSource -> IO () # put :: WriteBinHandle -> UnfoldingSource -> IO (Bin UnfoldingSource) # get :: ReadBinHandle -> IO UnfoldingSource #
Outputable UnfoldingSource # |
Instance details Defined in GHC.Types.Basic Methods ppr :: UnfoldingSource -> SDoc #

## Constructing `Unfolding`s

noUnfolding :: Unfolding #

There is no known `Unfolding`

bootUnfolding :: Unfolding #

There is no known `Unfolding`, because this came from an hi-boot file.

evaldUnfolding :: Unfolding #

This unfolding marks the associated thing as being evaluated

mkOtherCon :: [AltCon] -> Unfolding #

unSaturatedOk :: Bool #

needSaturated :: Bool #

boringCxtOk :: Bool #

boringCxtNotOk :: Bool #

## Predicates and deconstruction on `Unfolding`

expandUnfolding_maybe :: Unfolding -> Maybe CoreExpr #

maybeUnfoldingTemplate :: Unfolding -> Maybe CoreExpr #

Retrieves the template of an unfolding if possible maybeUnfoldingTemplate is used mainly when specialising, and we do want to specialise DFuns, so it's important to return a template for DFunUnfoldings

otherCons :: Unfolding -> [AltCon] #

The constructors that the unfolding could never be: returns `[]` if no information is available

isValueUnfolding :: Unfolding -> Bool #

Determines if it is certainly the case that the unfolding will yield a value (something in HNF): returns `False` if unsure

isEvaldUnfolding :: Unfolding -> Bool #

Determines if it possibly the case that the unfolding will yield a value. Unlike `isValueUnfolding` it returns `True` for `OtherCon`

isCheapUnfolding :: Unfolding -> Bool #

Is the thing we will unfold into certainly cheap?

isExpandableUnfolding :: Unfolding -> Bool #

isConLikeUnfolding :: Unfolding -> Bool #

`True` if the unfolding is a constructor application, the application of a CONLIKE function or `OtherCon`

isCompulsoryUnfolding :: Unfolding -> Bool #

isStableUnfolding :: Unfolding -> Bool #

isStableUserUnfolding :: Unfolding -> Bool #

isStableSystemUnfolding :: Unfolding -> Bool #

isInlineUnfolding :: Unfolding -> Bool #

True of a stable unfolding that is (a) always inlined; that is, with an `UnfWhen` guidance, or (b) a DFunUnfolding which never needs to be inlined

isBootUnfolding :: Unfolding -> Bool #

isBetterUnfoldingThan :: Unfolding -> Unfolding -> Bool #

hasCoreUnfolding :: Unfolding -> Bool #

hasSomeUnfolding :: Unfolding -> Bool #

Only returns False if there is no unfolding information available at all

canUnfold :: Unfolding -> Bool #

neverUnfoldGuidance :: UnfoldingGuidance -> Bool #

isStableSource :: UnfoldingSource -> Bool #

# Annotated expression data types

type AnnExpr bndr annot = (annot, AnnExpr' bndr annot) #

Annotated core: allows annotation at every node in the tree

data AnnExpr' bndr annot #

A clone of the `Expr` type but allowing annotation at every tree node

Constructors

AnnVar Id |
AnnLit Literal |
AnnLam bndr (AnnExpr bndr annot) |
AnnApp (AnnExpr bndr annot) (AnnExpr bndr annot) |
AnnCase (AnnExpr bndr annot) bndr Type [AnnAlt bndr annot] |
AnnLet (AnnBind bndr annot) (AnnExpr bndr annot) |
AnnCast (AnnExpr bndr annot) (annot, Coercion) |
AnnTick CoreTickish (AnnExpr bndr annot) |
AnnType Type |
AnnCoercion Coercion |

data AnnBind bndr annot #

A clone of the `Bind` type but allowing annotation at every tree node

Constructors

AnnNonRec bndr (AnnExpr bndr annot) |
AnnRec [(bndr, AnnExpr bndr annot)] |

data AnnAlt bndr annot #

A clone of the `Alt` type but allowing annotation at every tree node

Constructors

AnnAlt AltCon [bndr] (AnnExpr bndr annot) |

## Operations on annotated expressions

collectAnnArgs :: AnnExpr b a -> (AnnExpr b a, [AnnExpr b a]) #

Takes a nested application expression and returns the function being applied and the arguments to which it is applied

collectAnnArgsTicks :: (CoreTickish -> Bool) -> AnnExpr b a -> (AnnExpr b a, [AnnExpr b a], [CoreTickish]) #

## Operations on annotations

deAnnotate :: AnnExpr bndr annot -> Expr bndr #

deAnnotate' :: AnnExpr' bndr annot -> Expr bndr #

deAnnAlt :: AnnAlt bndr annot -> Alt bndr #

deAnnBind :: AnnBind b annot -> Bind b #

collectAnnBndrs :: AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot) #

As `collectBinders` but for `AnnExpr` rather than `Expr`

collectNAnnBndrs :: Int -> AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot) #

As `collectNBinders` but for `AnnExpr` rather than `Expr`

# Orphanhood

data IsOrphan #

Is this instance an orphan? If it is not an orphan, contains an `OccName` witnessing the instance's non-orphanhood. See Note [Orphans]

Constructors

IsOrphan |
NotOrphan !OccName |

#### Instances

Instances details

NFData IsOrphan # |
Instance details Defined in GHC.Core Methods rnf :: IsOrphan -> () #
Data IsOrphan # |
Instance details Defined in GHC.Core Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IsOrphan -> c IsOrphan # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IsOrphan # toConstr :: IsOrphan -> Constr # dataTypeOf :: IsOrphan -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c IsOrphan) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IsOrphan) # gmapT :: (forall b. Data b => b -> b) -> IsOrphan -> IsOrphan # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IsOrphan -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IsOrphan -> r # gmapQ :: (forall d. Data d => d -> u) -> IsOrphan -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> IsOrphan -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan #
Binary IsOrphan # |
Instance details Defined in GHC.Core Methods put_ :: WriteBinHandle -> IsOrphan -> IO () # put :: WriteBinHandle -> IsOrphan -> IO (Bin IsOrphan) # get :: ReadBinHandle -> IO IsOrphan #

isOrphan :: IsOrphan -> Bool #

Returns true if `IsOrphan` is orphan.

notOrphan :: IsOrphan -> Bool #

Returns true if `IsOrphan` is not an orphan.

chooseOrphanAnchor :: NameSet -> IsOrphan #

# Core rule data types

data CoreRule #

A `CoreRule` is:

- "Local" if the function it is a rule for is defined in the same module as the rule itself.
- "Orphan" if nothing on the LHS is defined in the same module as the rule itself

Constructors

Rule |
Fields ru_name :: RuleName Name of the rule, for communication with the user ru_act :: Activation When the rule is active ru_fn :: !Name Name of the `Id` at the head of this rule ru_rough :: [Maybe Name] Name at the head of each argument to the left hand side ru_bndrs :: [CoreBndr] Variables quantified over ru_args :: [CoreExpr] Left hand side arguments ru_rhs :: CoreExpr Right hand side of the rule Occurrence info is guaranteed correct See Note [OccInfo in unfoldings and rules] ru_auto :: Bool `True` = this rule is auto-generated (notably by Specialise or SpecConstr) `False` = generated at the user's behest See Note [Trimming auto-rules] in GHC.Iface.Tidy for the sole purpose of this field. ru_origin :: !Module `Module` the rule was defined in, used to test if we should see an orphan rule. ru_orphan :: !IsOrphan Whether or not the rule is an orphan. ru_local :: Bool `True` iff the fn at the head of the rule is defined in the same module as the rule and is not an implicit `Id` (like a record selector, class operation, or data constructor). This is different from `ru_orphan`, where a rule can avoid being an orphan if *any* Name in LHS of the rule was defined in the same module as the rule.
BuiltinRule | Built-in rules are used for constant folding and suchlike. They have no free variables. A built-in rule is always visible (there is no such thing as an orphan built-in rule.)
Fields ru_name :: RuleName Name of the rule, for communication with the user ru_fn :: Name Name of the `Id` at the head of this rule ru_nargs :: Int Number of arguments that `ru_try` consumes, if it fires, including type arguments ru_try :: RuleFun This function does the rewrite. It given too many arguments, it simply discards them; the returned `CoreExpr` is just the rewrite of `ru_fn` applied to the first `ru_nargs` args

#### Instances

Instances details

Outputable CoreRule # |
Instance details Defined in GHC.Core.Ppr Methods ppr :: CoreRule -> SDoc #

type RuleName = FastString #

type RuleFun = RuleOpts -> InScopeEnv -> Id -> [CoreExpr] -> Maybe CoreExpr #

type IdUnfoldingFun = Id -> Unfolding #

data InScopeEnv #

The `InScopeSet` in the `InScopeEnv` is a superset of variables that are currently in scope. See Note [The InScopeSet invariant].

Constructors

ISE InScopeSet IdUnfoldingFun |

data RuleOpts #

Rule options

## Operations on `CoreRule`s

ruleArity :: CoreRule -> FullArgCount #

The number of arguments the `ru_fn` must be applied to before the rule can match on it

ruleName :: CoreRule -> RuleName #

ruleIdName :: CoreRule -> Name #

The `Name` of the `Id` at the head of the rule left hand side

ruleActivation :: CoreRule -> Activation #

setRuleIdName :: Name -> CoreRule -> CoreRule #

Set the `Name` of the `Id` at the head of the rule left hand side

ruleModule :: CoreRule -> Maybe Module #

isBuiltinRule :: CoreRule -> Bool #

isLocalRule :: CoreRule -> Bool #

isAutoRule :: CoreRule -> Bool #