GHC.Core.SimpleOpt

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

Safe Haskell | Ignore
Language | GHC2021

GHC.Core.SimpleOpt

Contents

- Simple expression optimiser
- Join points
- Predicates on expressions

Synopsis

- data SimpleOpts = SimpleOpts {
  - so_uf_opts :: !UnfoldingOpts
  - so_co_opts :: !OptCoercionOpts
  - so_eta_red :: !Bool
  }
- defaultSimpleOpts :: SimpleOpts
- simpleOptPgm :: SimpleOpts -> Module -> CoreProgram -> [CoreRule] -> (CoreProgram, [CoreRule], CoreProgram)
- simpleOptExpr :: HasDebugCallStack => SimpleOpts -> CoreExpr -> CoreExpr
- simpleOptExprWith :: HasDebugCallStack => SimpleOpts -> Subst -> InExpr -> OutExpr
- joinPointBinding_maybe :: InBndr -> InExpr -> Maybe (InBndr, InExpr)
- joinPointBindings_maybe :: [(InBndr, InExpr)] -> Maybe [(InBndr, InExpr)]
- exprIsConApp_maybe :: HasDebugCallStack => InScopeEnv -> CoreExpr -> Maybe (InScopeSet, [FloatBind], DataCon, [Type], [CoreExpr])
- exprIsLiteral_maybe :: InScopeEnv -> CoreExpr -> Maybe Literal
- exprIsLambda_maybe :: HasDebugCallStack => InScopeEnv -> CoreExpr -> Maybe (Var, CoreExpr, [CoreTickish])

# Documentation

data SimpleOpts #

Simple optimiser options

Constructors

SimpleOpts |
Fields so_uf_opts :: !UnfoldingOpts Unfolding options so_co_opts :: !OptCoercionOpts Coercion optimiser options so_eta_red :: !Bool Eta reduction on?

defaultSimpleOpts :: SimpleOpts #

Default options for the Simple optimiser.

## Simple expression optimiser

simpleOptPgm :: SimpleOpts -> Module -> CoreProgram -> [CoreRule] -> (CoreProgram, [CoreRule], CoreProgram) #

simpleOptExpr :: HasDebugCallStack => SimpleOpts -> CoreExpr -> CoreExpr #

simpleOptExprWith :: HasDebugCallStack => SimpleOpts -> Subst -> InExpr -> OutExpr #

## Join points

joinPointBinding_maybe :: InBndr -> InExpr -> Maybe (InBndr, InExpr) #

Returns Just (bndr,rhs) if the binding is a join point: If it's a JoinId, just return it If it's not yet a JoinId but is always tail-called, make it into a JoinId and return it. In the latter case, eta-expand the RHS if necessary, to make the lambdas explicit, as is required for join points

Precondition: the InBndr has been occurrence-analysed, so its OccInfo is valid

joinPointBindings_maybe :: [(InBndr, InExpr)] -> Maybe [(InBndr, InExpr)] #

## Predicates on expressions

exprIsConApp_maybe :: HasDebugCallStack => InScopeEnv -> CoreExpr -> Maybe (InScopeSet, [FloatBind], DataCon, [Type], [CoreExpr]) #

Returns `Just ([b1..bp], dc, [t1..tk], [x1..xn])` if the argument expression is a *saturated* constructor application of the form `let b1 in .. let bp in dc t1..tk x1 .. xn`, where t1..tk are the *universally-quantified* type args of `dc`. Floats can also be (and most likely are) single-alternative case expressions. Why does `exprIsConApp_maybe` return floats? We may have to look through lets and cases to detect that we are in the presence of a data constructor wrapper. In this case, we need to return the lets and cases that we traversed. See Note [exprIsConApp_maybe on data constructors with wrappers]. Data constructor wrappers are unfolded late, but we really want to trigger case-of-known-constructor as early as possible. See also Note [Activation for data constructor wrappers] in GHC.Types.Id.Make.

We also return the incoming InScopeSet, augmented with the binders from any [FloatBind] that we return

exprIsLiteral_maybe :: InScopeEnv -> CoreExpr -> Maybe Literal #

exprIsLambda_maybe :: HasDebugCallStack => InScopeEnv -> CoreExpr -> Maybe (Var, CoreExpr, [CoreTickish]) #