CoreSyn

ghc-7.8.3: The GHC API

Safe Haskell | None
Language | Haskell98

CoreSyn

Contents

- Main data types
  - `Expr` construction
  - Simple `Expr` access functions and predicates
- Unfolding data types
  - Constructing `Unfolding`s
  - Predicates and deconstruction on `Unfolding`
- Strictness
- Annotated expression data types
  - Operations on annotated expressions
  - Operations on annotations
- Core rule data types
  - Operations on `CoreRule`s
- Core vectorisation declarations data type

Description

CoreSyn 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) Coercion
  - | Tick (Tickish Id) (Expr b)
  - | Type Type
  - | Coercion Coercion
- type Alt b = (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
- data Tickish id
  - = ProfNote {
    - profNoteCC :: CostCentre
    - profNoteCount :: !Bool
    - profNoteScope :: !Bool
    }
  - | HpcTick {
    - tickModule :: Module
    - tickId :: !Int
    }
  - | Breakpoint {
    - breakpointId :: !Int
    - breakpointFVs :: [id]
    }
- 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
- mkLets :: [Bind 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
- mkIntLit :: DynFlags -> Integer -> Expr b
- mkIntLitInt :: DynFlags -> Int -> Expr b
- mkWordLit :: DynFlags -> Integer -> Expr b
- mkWordLitWord :: DynFlags -> Word -> 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]
- isId :: Var -> Bool
- cmpAltCon :: AltCon -> AltCon -> Ordering
- cmpAlt :: (AltCon, a, b) -> (AltCon, a, b) -> Ordering
- ltAlt :: (AltCon, a, b) -> (AltCon, a, b) -> Bool
- bindersOf :: Bind b -> [b]
- bindersOfBinds :: [Bind b] -> [b]
- rhssOfBind :: Bind b -> [Expr b]
- rhssOfAlts :: [Alt b] -> [Expr b]
- collectBinders :: Expr b -> ([b], Expr b)
- collectTyBinders :: CoreExpr -> ([TyVar], CoreExpr)
- collectValBinders :: CoreExpr -> ([Id], CoreExpr)
- collectTyAndValBinders :: CoreExpr -> ([TyVar], [Id], CoreExpr)
- collectArgs :: Expr b -> (Expr b, [Arg b])
- flattenBinds :: [Bind b] -> [(b, Expr b)]
- isValArg :: Expr b -> Bool
- isTypeArg :: Expr b -> Bool
- isTyCoArg :: Expr b -> Bool
- valArgCount :: [Arg b] -> Int
- valBndrCount :: [CoreBndr] -> Int
- isRuntimeArg :: CoreExpr -> Bool
- isRuntimeVar :: Var -> Bool
- tickishCounts :: Tickish id -> Bool
- tickishScoped :: Tickish id -> Bool
- tickishIsCode :: Tickish id -> Bool
- mkNoCount :: Tickish id -> Tickish id
- mkNoScope :: Tickish id -> Tickish id
- tickishCanSplit :: Tickish Id -> Bool
- data Unfolding
  - = NoUnfolding
  - | OtherCon [AltCon]
  - | DFunUnfolding {
    - df_bndrs :: [Var]
    - df_con :: DataCon
    - df_args :: [CoreExpr]
    }
  - | CoreUnfolding {
    - uf_tmpl :: CoreExpr
    - uf_src :: UnfoldingSource
    - uf_is_top :: Bool
    - uf_arity :: Arity
    - uf_is_value :: Bool
    - uf_is_conlike :: Bool
    - uf_is_work_free :: Bool
    - uf_expandable :: Bool
    - uf_guidance :: UnfoldingGuidance
    }
- data UnfoldingGuidance
  - = UnfWhen {
    - ug_unsat_ok :: Bool
    - ug_boring_ok :: Bool
    }
  - | UnfIfGoodArgs {
    - ug_args :: [Int]
    - ug_size :: Int
    - ug_res :: Int
    }
  - | UnfNever
- data UnfoldingSource
  - = InlineRhs
  - | InlineStable
  - | InlineCompulsory
- noUnfolding :: Unfolding
- evaldUnfolding :: Unfolding
- mkOtherCon :: [AltCon] -> Unfolding
- unSaturatedOk :: Bool
- needSaturated :: Bool
- boringCxtOk :: Bool
- boringCxtNotOk :: Bool
- unfoldingTemplate :: Unfolding -> CoreExpr
- setUnfoldingTemplate :: Unfolding -> CoreExpr -> Unfolding
- expandUnfolding_maybe :: Unfolding -> Maybe CoreExpr
- maybeUnfoldingTemplate :: Unfolding -> Maybe CoreExpr
- otherCons :: Unfolding -> [AltCon]
- unfoldingArity :: Unfolding -> Arity
- isValueUnfolding :: Unfolding -> Bool
- isEvaldUnfolding :: Unfolding -> Bool
- isCheapUnfolding :: Unfolding -> Bool
- isExpandableUnfolding :: Unfolding -> Bool
- isConLikeUnfolding :: Unfolding -> Bool
- isCompulsoryUnfolding :: Unfolding -> Bool
- isStableUnfolding :: Unfolding -> Bool
- isStableCoreUnfolding_maybe :: Unfolding -> Maybe UnfoldingSource
- isClosedUnfolding :: Unfolding -> Bool
- hasSomeUnfolding :: Unfolding -> Bool
- canUnfold :: Unfolding -> Bool
- neverUnfoldGuidance :: UnfoldingGuidance -> Bool
- isStableSource :: UnfoldingSource -> Bool
- seqExpr :: CoreExpr -> ()
- seqExprs :: [CoreExpr] -> ()
- seqUnfolding :: Unfolding -> ()
- 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 (Tickish Id) (AnnExpr bndr annot)
  - | AnnType Type
  - | AnnCoercion Coercion
- data AnnBind bndr annot
  - = AnnNonRec bndr (AnnExpr bndr annot)
  - | AnnRec [(bndr, AnnExpr bndr annot)]
- type AnnAlt bndr annot = (AltCon, [bndr], AnnExpr bndr annot)
- collectAnnArgs :: AnnExpr b a -> (AnnExpr b a, [AnnExpr b a])
- deAnnotate :: AnnExpr bndr annot -> Expr bndr
- deAnnotate' :: AnnExpr' bndr annot -> Expr bndr
- deAnnAlt :: AnnAlt bndr annot -> Alt bndr
- collectAnnBndrs :: AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
- 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_local :: Bool
    }
  - | BuiltinRule {
    - ru_name :: RuleName
    - ru_fn :: Name
    - ru_nargs :: Int
    - ru_try :: RuleFun
    }
- type RuleName = FastString
- type RuleFun = DynFlags -> InScopeEnv -> Id -> [CoreExpr] -> Maybe CoreExpr
- type IdUnfoldingFun = Id -> Unfolding
- type InScopeEnv = (InScopeSet, IdUnfoldingFun)
- seqRules :: [CoreRule] -> ()
- ruleArity :: CoreRule -> Int
- ruleName :: CoreRule -> RuleName
- ruleIdName :: CoreRule -> Name
- ruleActivation :: CoreRule -> Activation
- setRuleIdName :: Name -> CoreRule -> CoreRule
- isBuiltinRule :: CoreRule -> Bool
- isLocalRule :: CoreRule -> Bool
- data CoreVect
  - = Vect Id CoreExpr
  - | NoVect Id
  - | VectType Bool TyCon (Maybe TyCon)
  - | VectClass TyCon
  - | VectInst Id

# Main data types

data Expr b Source

This is the data type that represents GHCs core intermediate language. Currently GHC uses System FC http://research.microsoft.com/~simonpj/papers/ext-f/ 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] 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
- Primitive literals
- Applications: note that the argument may be a `Type`.

  See CoreSyn for another invariant

- Lambda abstraction
- Recursive and non recursive `let`s. Operationally this corresponds to allocating a thunk for the things bound and then executing the sub-expression.

The right hand sides of all top-level and recursive `let`s must be of lifted type (see Type for the meaning of lifted vs. unlifted).

The right hand side of of a non-recursive `Let` _and_ the argument of an `App`, may be of unlifted type, but only if the expression is ok-for-speculation. This means that the let can be floated around without difficulty. For example, this is OK:

    y::Int# = x +# 1#

But this is not, as it may affect termination if the expression is floated out:

    y::Int# = fac 4#

In this situation you should use `case` rather than a `let`. The function `needsCaseBinding` can help you determine which to generate, or alternatively use `mkCoreLet` rather than this constructor directly, which will generate a `case` if necessary

We allow a non-recursive let to bind a type variable, thus:

    Let (NonRec tv (Type ty)) body

This can be very convenient for postponing type substitutions until the next run of the simplifier.

At the moment, the rest of the compiler only deals with type-let in a Let expression, rather than at top level. We may want to revist this choice.

- Case split. 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

This is one of the more complicated elements of the Core language, and comes with a number of restrictions:

1. The list of alternatives may be empty; See Note [Empty case alternatives]
   1. The `DEFAULT` case alternative must be first in the list, if it occurs at all.
   2. The remaining cases are in order of increasing tag (for `DataAlts`) or lit (for `LitAlts`). This makes finding the relevant constructor easy, and makes comparison easier too.
   3. The list of alternatives must be exhaustive. An exhaustive case does not necessarily mention all constructors:

       	      data Foo = Red | Green | Blue
       	 ... case x of
       	      Red   -> True
       	      other -> f (case x of
       	                      Green -> ...
       	                      Blue  -> ... ) ...

   The inner case does not need a `Red` alternative, because `x` can't be `Red` at that program point.

- 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.
- Notes. These allow general information to be added to expressions in the syntax tree
- 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) Coercion |
Tick (Tickish Id) (Expr b) |
Type Type |
Coercion Coercion |

Instances

Data b => Data (Expr b) |
OutputableBndr b => Outputable (Expr b) |
Typeable (* -> *) Expr |

type Alt b = (AltCon, [b], Expr b) Source

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)`

data Bind b Source

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

Data b => Data (Bind b) |
OutputableBndr b => Outputable (Bind b) |
Typeable (* -> *) Bind |

data AltCon Source

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

Eq AltCon |
Data AltCon |
Ord AltCon |
Outputable AltCon |
Typeable * AltCon |

type Arg b = Expr b Source

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

data Tickish id Source

Allows attaching extra information to points in expressions

Constructors

ProfNote | An `{--}` profiling annotation, either automatically added by the desugarer as a result of -auto-all, or added by the user.
Fields profNoteCC :: CostCentre the cost centre profNoteCount :: !Bool bump the entry count? profNoteScope :: !Bool scopes over the enclosed expression (i.e. not just a tick)
HpcTick | A "tick" used by HPC to track the execution of each subexpression in the original source code.
Fields tickModule :: Module tickId :: !Int
Breakpoint | A breakpoint for the GHCi debugger. This behaves like an HPC tick, but has a list of free variables which will be available for inspection in GHCi when the program stops at the breakpoint. NB. we must take account of these Ids when (a) counting free variables, and (b) substituting (don't substitute for them)
Fields breakpointId :: !Int breakpointFVs :: [id] the order of this list is important: it matches the order of the lists in the appropriate entry in HscTypes.ModBreaks. Careful about substitution! See Note [substTickish] in CoreSubst.

Instances

Eq id => Eq (Tickish id) |
Data id => Data (Tickish id) |
Ord id => Ord (Tickish id) |
Outputable id => Outputable (Tickish id) |
Typeable (* -> *) Tickish |

type CoreProgram = [CoreBind] Source

type CoreExpr = Expr CoreBndr Source

Expressions where binders are `CoreBndr`s

type CoreAlt = Alt CoreBndr Source

Case alternatives where binders are `CoreBndr`s

type CoreBind = Bind CoreBndr Source

Binding groups where binders are `CoreBndr`s

type CoreArg = Arg CoreBndr Source

Argument expressions where binders are `CoreBndr`s

type CoreBndr = Var Source

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) Source

type TaggedAlt t = Alt (TaggedBndr t) Source

type TaggedBind t = Bind (TaggedBndr t) Source

type TaggedArg t = Arg (TaggedBndr t) Source

data TaggedBndr t Source

Binders are tagged with a t

Constructors

TB CoreBndr t |

Instances

Outputable b => OutputableBndr (TaggedBndr b) |
Outputable b => Outputable (TaggedBndr b) |

deTagExpr :: TaggedExpr t -> CoreExpr Source

## `Expr` construction

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

Bind all supplied binding groups over an expression in a nested let expression. Prefer to use `mkCoreLets` if possible

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

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 Source

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 Source

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

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

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

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

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

mkIntLit :: DynFlags -> Integer -> Expr b Source

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

mkIntLitInt :: DynFlags -> Int -> Expr b Source

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

mkWordLit :: DynFlags -> Integer -> Expr b Source

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

mkWordLitWord :: DynFlags -> Word -> Expr b Source

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

mkWord64LitWord64 :: Word64 -> Expr b Source

mkInt64LitInt64 :: Int64 -> Expr b Source

mkCharLit :: Char -> Expr b Source

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

mkStringLit :: String -> Expr b Source

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

mkFloatLit :: Rational -> Expr b Source

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 Source

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 Source

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 Source

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 Source

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 Source

mkTyBind :: TyVar -> Type -> CoreBind Source

Create a binding group where a type variable is bound to a type. Per CoreSyn, this can only be used to bind something in a non-recursive `let` expression

mkCoBind :: CoVar -> Coercion -> CoreBind Source

Create a binding group where a type variable is bound to a type. Per CoreSyn, this can only be used to bind something in a non-recursive `let` expression

varToCoreExpr :: CoreBndr -> Expr b Source

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

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

isId :: Var -> Bool Source

cmpAltCon :: AltCon -> AltCon -> Ordering Source

Compares `AltCon`s within a single list of alternatives

cmpAlt :: (AltCon, a, b) -> (AltCon, a, b) -> Ordering Source

ltAlt :: (AltCon, a, b) -> (AltCon, a, b) -> Bool Source

## Simple `Expr` access functions and predicates

bindersOf :: Bind b -> [b] Source

Extract every variable by this group

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

`bindersOf` applied to a list of binding groups

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

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

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

We often want to strip off leading lambdas before getting down to business. This function is your friend.

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

Collect as many type bindings as possible from the front of a nested lambda

collectValBinders :: CoreExpr -> ([Id], CoreExpr) Source

Collect as many value bindings as possible from the front of a nested lambda

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

Collect type binders from the front of the lambda first, then follow up by collecting as many value bindings as possible from the resulting stripped expression

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

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

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

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

isValArg :: Expr b -> Bool Source

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 Source

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

isTyCoArg :: Expr b -> Bool Source

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

valArgCount :: [Arg b] -> Int Source

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

valBndrCount :: [CoreBndr] -> Int Source

The number of binders that bind values rather than types

isRuntimeArg :: CoreExpr -> Bool Source

Will this argument expression exist at runtime?

isRuntimeVar :: Var -> Bool Source

Will this variable exist at runtime?

tickishCounts :: Tickish id -> Bool Source

A "counting tick" (where tickishCounts is True) is one that counts evaluations in some way. We cannot discard a counting tick, and the compiler should preserve the number of counting ticks as far as possible.

However, we still allow the simplifier to increase or decrease sharing, so in practice the actual number of ticks may vary, except that we never change the value from zero to non-zero or vice versa.

tickishScoped :: Tickish id -> Bool Source

tickishIsCode :: Tickish id -> Bool Source

Return True if this source annotation compiles to some code, or will disappear before the backend.

mkNoCount :: Tickish id -> Tickish id Source

mkNoScope :: Tickish id -> Tickish id Source

tickishCanSplit :: Tickish Id -> Bool Source

Return True if this Tick can be split into (tick,scope) parts with `mkNoScope` and `mkNoCount` respectively.

# Unfolding data types

data Unfolding Source

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 CoreUnfold

Constructors

NoUnfolding | We have no information about the unfolding
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_arity :: Arity uf_is_value :: Bool uf_is_conlike :: Bool uf_is_work_free :: Bool uf_expandable :: Bool uf_guidance :: UnfoldingGuidance

Instances

Outputable Unfolding |

data UnfoldingGuidance Source

`UnfoldingGuidance` says when unfolding should take place

Constructors

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

Instances

Outputable UnfoldingGuidance |

data UnfoldingSource Source

Constructors

InlineRhs |
InlineStable |
InlineCompulsory |

Instances

Outputable UnfoldingSource |

## Constructing `Unfolding`s

noUnfolding :: Unfolding Source

There is no known `Unfolding`

evaldUnfolding :: Unfolding Source

This unfolding marks the associated thing as being evaluated

mkOtherCon :: [AltCon] -> Unfolding Source

unSaturatedOk :: Bool Source

needSaturated :: Bool Source

boringCxtOk :: Bool Source

boringCxtNotOk :: Bool Source

## Predicates and deconstruction on `Unfolding`

unfoldingTemplate :: Unfolding -> CoreExpr Source

Retrieves the template of an unfolding: panics if none is known

setUnfoldingTemplate :: Unfolding -> CoreExpr -> Unfolding Source

expandUnfolding_maybe :: Unfolding -> Maybe CoreExpr Source

maybeUnfoldingTemplate :: Unfolding -> Maybe CoreExpr Source

Retrieves the template of an unfolding if possible

otherCons :: Unfolding -> [AltCon] Source

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

unfoldingArity :: Unfolding -> Arity Source

isValueUnfolding :: Unfolding -> Bool Source

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

isEvaldUnfolding :: Unfolding -> Bool Source

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

isCheapUnfolding :: Unfolding -> Bool Source

Is the thing we will unfold into certainly cheap?

isExpandableUnfolding :: Unfolding -> Bool Source

isConLikeUnfolding :: Unfolding -> Bool Source

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

isCompulsoryUnfolding :: Unfolding -> Bool Source

isStableUnfolding :: Unfolding -> Bool Source

isStableCoreUnfolding_maybe :: Unfolding -> Maybe UnfoldingSource Source

isClosedUnfolding :: Unfolding -> Bool Source

hasSomeUnfolding :: Unfolding -> Bool Source

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

canUnfold :: Unfolding -> Bool Source

neverUnfoldGuidance :: UnfoldingGuidance -> Bool Source

isStableSource :: UnfoldingSource -> Bool Source

# Strictness

seqExpr :: CoreExpr -> () Source

seqExprs :: [CoreExpr] -> () Source

seqUnfolding :: Unfolding -> () Source

# Annotated expression data types

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

Annotated core: allows annotation at every node in the tree

data AnnExpr' bndr annot Source

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 (Tickish Id) (AnnExpr bndr annot) |
AnnType Type |
AnnCoercion Coercion |

data AnnBind bndr annot Source

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

Constructors

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

type AnnAlt bndr annot = (AltCon, [bndr], AnnExpr bndr annot) Source

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

## Operations on annotated expressions

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

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

## Operations on annotations

deAnnotate :: AnnExpr bndr annot -> Expr bndr Source

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

deAnnAlt :: AnnAlt bndr annot -> Alt bndr Source

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

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

# Core rule data types

data CoreRule Source

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 `False` = generated at the users behest Main effect: reporting of orphan-hood 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)
BuiltinRule | Built-in rules are used for constant folding and suchlike. They have no free variables.
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

Outputable CoreRule |

type RuleName = FastString Source

type RuleFun = DynFlags -> InScopeEnv -> Id -> [CoreExpr] -> Maybe CoreExpr Source

type IdUnfoldingFun = Id -> Unfolding Source

type InScopeEnv = (InScopeSet, IdUnfoldingFun) Source

## Operations on `CoreRule`s

seqRules :: [CoreRule] -> () Source

ruleArity :: CoreRule -> Int Source

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

ruleName :: CoreRule -> RuleName Source

ruleIdName :: CoreRule -> Name Source

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

ruleActivation :: CoreRule -> Activation Source

setRuleIdName :: Name -> CoreRule -> CoreRule Source

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

isBuiltinRule :: CoreRule -> Bool Source

isLocalRule :: CoreRule -> Bool Source

# Core vectorisation declarations data type

data CoreVect Source

Constructors

Vect Id CoreExpr |
NoVect Id |
VectType Bool TyCon (Maybe TyCon) |
VectClass TyCon |
VectInst Id |

Instances

Outputable CoreVect |