| ||||||||||||

| ||||||||||||

| ||||||||||||

Description | ||||||||||||

Commonly useful utilites for manipulating the Core language | ||||||||||||

Synopsis | ||||||||||||

Constructing expressions | ||||||||||||

mkInlineMe :: CoreExpr -> CoreExpr | ||||||||||||

Wraps the given expression in an inlining hint unless the expression is trivial in some sense, so that doing so would usually hurt us | ||||||||||||

mkSCC :: CostCentre -> Expr b -> Expr b | ||||||||||||

Wraps the given expression in the cost centre unless in a way that maximises their utility to the user | ||||||||||||

mkCoerce :: Coercion -> CoreExpr -> CoreExpr | ||||||||||||

Wrap the given expression in the coercion safely, coalescing nested coercions | ||||||||||||

mkCoerceI :: CoercionI -> CoreExpr -> CoreExpr | ||||||||||||

Wrap the given expression in the coercion, dropping identity coercions and coalescing nested coercions | ||||||||||||

bindNonRec :: Id -> CoreExpr -> CoreExpr -> CoreExpr | ||||||||||||

let x = r in b or: case r of x { _DEFAULT_ -> b } depending on whether we have to use a | ||||||||||||

needsCaseBinding :: Type -> CoreExpr -> Bool | ||||||||||||

Tests whether we have to use a case rather than let binding for this expression
as per the invariants of CoreExpr: see CoreSyn
| ||||||||||||

mkIfThenElse :: CoreExpr -> CoreExpr -> CoreExpr -> CoreExpr | ||||||||||||

mkAltExpr | ||||||||||||

| ||||||||||||

mkPiType :: Var -> Type -> Type | ||||||||||||

Makes a (->) type or a forall type, depending
on whether it is given a type variable or a term variable.
| ||||||||||||

mkPiTypes :: [Var] -> Type -> Type | ||||||||||||

mkPiType for multiple type or value arguments
| ||||||||||||

Taking expressions apart | ||||||||||||

findDefault :: [CoreAlt] -> ([CoreAlt], Maybe CoreExpr) | ||||||||||||

Extract the default case alternative | ||||||||||||

findAlt :: AltCon -> [CoreAlt] -> CoreAlt | ||||||||||||

Find the case alternative corresponding to a particular constructor: panics if no such constructor exists | ||||||||||||

isDefaultAlt :: CoreAlt -> Bool | ||||||||||||

mergeAlts :: [CoreAlt] -> [CoreAlt] -> [CoreAlt] | ||||||||||||

Merge alternatives preserving order; alternatives in the first argument shadow ones in the second | ||||||||||||

trimConArgs :: AltCon -> [CoreArg] -> [CoreArg] | ||||||||||||

Given: case (C a b x y) of C b x y -> ... We want to drop the leading type argument of the scrutinee leaving the arguments to match agains the pattern | ||||||||||||

Properties of expressions | ||||||||||||

exprType :: CoreExpr -> Type | ||||||||||||

Recover the type of a well-typed Core expression. Fails when
applied to the actual Type expression as it cannot
really be said to have a type
| ||||||||||||

coreAltType :: CoreAlt -> Type | ||||||||||||

Returns the type of the alternatives right hand side | ||||||||||||

coreAltsType :: [CoreAlt] -> Type | ||||||||||||

Returns the type of the first alternative, which should be the same as for all alternatives | ||||||||||||

exprIsDupable :: CoreExpr -> Bool | ||||||||||||

exprIsTrivial :: CoreExpr -> Bool | ||||||||||||

exprIsCheap :: CoreExpr -> Bool | ||||||||||||

exprIsHNF :: CoreExpr -> Bool | ||||||||||||

This returns true for expressions that are certainly case x of _ -> e into: e and to decide whether it's safe to discard a (:) (f x) (map f xs) map (...redex...) Because For unlifted argument types, we have to be careful: C (f x :: Int#) Suppose | ||||||||||||

exprOkForSpeculation :: CoreExpr -> Bool | ||||||||||||

- Safe to evaluate even if normal order eval might not evaluate the expression at all, or
- Safe
*not*to evaluate even if normal order would do so
Precisely, it returns - The expression guarantees to terminate,
- soon,
- without raising an exception,
- without causing a side effect (e.g. writing a mutable variable)
Note that if let x = case y# +# 1# of { r# -> I# r# } in E being translated to: case y# +# 1# of { r# -> let x = I# r# in E } We can only do this if the | ||||||||||||

exprIsBig :: Expr b -> Bool | ||||||||||||

Returns True of expressions that are too big to be compared by cheapEqExpr
| ||||||||||||

exprIsConApp_maybe :: CoreExpr -> Maybe (DataCon, [CoreExpr]) | ||||||||||||

Returns The Arity returned is the number of value args the expression can be applied to without doing much work | ||||||||||||

exprIsBottom :: CoreExpr -> Bool | ||||||||||||

True of expressions that are guaranteed to diverge upon execution | ||||||||||||

rhsIsStatic :: PackageId -> CoreExpr -> Bool | ||||||||||||

This function is called only on *top-level* right-hand sides.
Returns True if the RHS can be allocated statically in the output,
with no thunks involved at all.
| ||||||||||||

Arity and eta expansion | ||||||||||||

manifestArity :: CoreExpr -> Arity | ||||||||||||

exprArity :: CoreExpr -> Arity | ||||||||||||

An approximate, fast, version of exprEtaExpandArity
| ||||||||||||

exprEtaExpandArity :: DynFlags -> CoreExpr -> Arity | ||||||||||||

etaExpand | ||||||||||||

| ||||||||||||

Expression and bindings size | ||||||||||||

coreBindsSize :: [CoreBind] -> Int | ||||||||||||

exprSize :: CoreExpr -> Int | ||||||||||||

A measure of the size of the expressions, strictly greater than 0 It also forces the expression pretty drastically as a side effect | ||||||||||||

Hashing | ||||||||||||

hashExpr :: CoreExpr -> Int | ||||||||||||

Two expressions that hash to the same The emphasis is on a crude, fast hash, rather than on high precision. But unequal here means "not identical"; two alpha-equivalent expressions may hash to the different Ints. We must be careful that | ||||||||||||

Equality | ||||||||||||

cheapEqExpr :: Expr b -> Expr b -> Bool | ||||||||||||

A cheap equality test which bales out fast!
If it returns See also | ||||||||||||

tcEqExpr :: CoreExpr -> CoreExpr -> Bool | ||||||||||||

A kind of shallow equality used in rule matching, so does
not look through newtypes or predicate types
| ||||||||||||

tcEqExprX :: RnEnv2 -> CoreExpr -> CoreExpr -> Bool | ||||||||||||

Manipulating data constructors and types | ||||||||||||

applyTypeToArgs :: CoreExpr -> Type -> [CoreExpr] -> Type | ||||||||||||

A more efficient version of applyTypeToArg when we have several arguments.
The first argument is just for debugging, and gives some context
| ||||||||||||

applyTypeToArg :: Type -> CoreExpr -> Type | ||||||||||||

Determines the type resulting from applying an expression to a function with the given type | ||||||||||||

dataConOrigInstPat :: [Unique] -> DataCon -> [Type] -> ([TyVar], [CoVar], [Id]) | ||||||||||||

dataConRepInstPat :: [Unique] -> DataCon -> [Type] -> ([TyVar], [CoVar], [Id]) | ||||||||||||

dataConRepFSInstPat :: [FastString] -> [Unique] -> DataCon -> [Type] -> ([TyVar], [CoVar], [Id]) | ||||||||||||

Produced by Haddock version 2.4.2 |