GHC.Core.Opt.Arity

ghc-9.2.0.20210422: The GHC API

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Core.Opt.Arity

Contents

- ArityType
- Join points
- Coercions and casts

Description

Arity and eta expansion

Synopsis

- manifestArity :: CoreExpr -> Arity
- joinRhsArity :: CoreExpr -> JoinArity
- exprArity :: CoreExpr -> Arity
- typeArity :: Type -> [OneShotInfo]
- exprEtaExpandArity :: DynFlags -> CoreExpr -> ArityType
- findRhsArity :: DynFlags -> Id -> CoreExpr -> Arity -> ArityType
- etaExpand :: Arity -> CoreExpr -> CoreExpr
- etaExpandAT :: ArityType -> CoreExpr -> CoreExpr
- exprBotStrictness_maybe :: CoreExpr -> Maybe (Arity, StrictSig)
- data ArityType = AT ![OneShotInfo] !Divergence
- mkBotArityType :: [OneShotInfo] -> ArityType
- mkTopArityType :: [OneShotInfo] -> ArityType
- expandableArityType :: ArityType -> Bool
- arityTypeArity :: ArityType -> Arity
- maxWithArity :: ArityType -> Arity -> ArityType
- idArityType :: Id -> ArityType
- etaExpandToJoinPoint :: JoinArity -> CoreExpr -> ([CoreBndr], CoreExpr)
- etaExpandToJoinPointRule :: JoinArity -> CoreRule -> CoreRule
- pushCoArg :: CoercionR -> CoreArg -> Maybe (CoreArg, MCoercion)
- pushCoArgs :: CoercionR -> [CoreArg] -> Maybe ([CoreArg], MCoercion)
- pushCoValArg :: CoercionR -> Maybe (MCoercionR, MCoercionR)
- pushCoTyArg :: CoercionR -> Type -> Maybe (Type, MCoercionR)
- pushCoercionIntoLambda :: InScopeSet -> Var -> CoreExpr -> CoercionR -> Maybe (Var, CoreExpr)
- pushCoDataCon :: DataCon -> [CoreExpr] -> Coercion -> Maybe (DataCon, [Type], [CoreExpr])
- collectBindersPushingCo :: CoreExpr -> ([Var], CoreExpr)

# Documentation

manifestArity :: CoreExpr -> Arity Source #

manifestArity sees how many leading value lambdas there are, after looking through casts

joinRhsArity :: CoreExpr -> JoinArity Source #

exprArity :: CoreExpr -> Arity Source #

An approximate, fast, version of `exprEtaExpandArity`

typeArity :: Type -> [OneShotInfo] Source #

exprEtaExpandArity :: DynFlags -> CoreExpr -> ArityType Source #

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

findRhsArity :: DynFlags -> Id -> CoreExpr -> Arity -> ArityType Source #

etaExpand :: Arity -> CoreExpr -> CoreExpr Source #

`etaExpand n e` returns an expression with the same meaning as `e`, but with arity `n`.

Given:

    e' = etaExpand n e

We should have that:

    ty = exprType e = exprType e'

etaExpandAT :: ArityType -> CoreExpr -> CoreExpr Source #

exprBotStrictness_maybe :: CoreExpr -> Maybe (Arity, StrictSig) Source #

## ArityType

data ArityType Source #

The analysis lattice of arity analysis. It is isomorphic to

       data ArityType'
         = AEnd Divergence
         | ALam OneShotInfo ArityType'

Which is easier to display the Hasse diagram for:

     ALam OneShotLam at
             |
         AEnd topDiv
             |
     ALam NoOneShotInfo at
             |
         AEnd exnDiv
             |
         AEnd botDiv

where the `at` fields of `ALam` are inductively subject to the same order. That is, `ALam os at1 < ALam os at2` iff `at1 < at2`.

Why the strange Top element? See Note [Combining case branches].

We rely on this lattice structure for fixed-point iteration in `findRhsArity`. For the semantics of `ArityType`, see Note [ArityType].

Constructors

AT ![OneShotInfo] !Divergence | `AT oss div` means this value can safely be eta-expanded `length oss` times, provided use sites respect the `OneShotInfo`s in `oss`. A `OneShotLam` annotation can come from two sources: * The user annotated a lambda as one-shot with `oneShot` * It's from a lambda binder of a type affected by `-fstate-hack`. See `idStateHackOneShotInfo`. In both cases, `OneShotLam` should win over `NoOneShotInfo`, see Note [Combining case branches]. If `div` is dead-ending (`isDeadEndDiv`), then application to `length os` arguments will surely diverge, similar to the situation with `DmdType`.

#### Instances

Instances details

Outputable ArityType # | This is the BNF of the generated output:
    @

    We format
AT [o1,..,on] topDiv`as` o1..on.T`and` AT [o1,..,on] botDiv`as` o1..on.⊥`, respectively. More concretely,` AT [NOI,OS,OS] topDiv`is formatted as` ?11.T`. If the one-shot info is empty, we omit the leading` .@.
Instance details Defined in GHC.Core.Opt.Arity Methods ppr :: ArityType -> SDoc Source #
Eq ArityType # |
Instance details Defined in GHC.Core.Opt.Arity Methods (==) :: ArityType -> ArityType -> Bool # (/=) :: ArityType -> ArityType -> Bool #

mkBotArityType :: [OneShotInfo] -> ArityType Source #

mkTopArityType :: [OneShotInfo] -> ArityType Source #

expandableArityType :: ArityType -> Bool Source #

True = eta-expansion will add at least one lambda

arityTypeArity :: ArityType -> Arity Source #

The number of value args for the arity type

maxWithArity :: ArityType -> Arity -> ArityType Source #

Expand a non-bottoming arity type so that it has at least the given arity.

idArityType :: Id -> ArityType Source #

## Join points

etaExpandToJoinPoint :: JoinArity -> CoreExpr -> ([CoreBndr], CoreExpr) Source #

Split an expression into the given number of binders and a body, eta-expanding if necessary. Counts value *and* type binders.

etaExpandToJoinPointRule :: JoinArity -> CoreRule -> CoreRule Source #

## Coercions and casts

pushCoArg :: CoercionR -> CoreArg -> Maybe (CoreArg, MCoercion) Source #

pushCoArgs :: CoercionR -> [CoreArg] -> Maybe ([CoreArg], MCoercion) Source #

pushCoValArg :: CoercionR -> Maybe (MCoercionR, MCoercionR) Source #

pushCoTyArg :: CoercionR -> Type -> Maybe (Type, MCoercionR) Source #

pushCoercionIntoLambda :: InScopeSet -> Var -> CoreExpr -> CoercionR -> Maybe (Var, CoreExpr) Source #

pushCoDataCon :: DataCon -> [CoreExpr] -> Coercion -> Maybe (DataCon, [Type], [CoreExpr]) Source #

collectBindersPushingCo :: CoreExpr -> ([Var], CoreExpr) Source #