ghc-9.2.4: The GHC API
Safe HaskellSafe-Inferred
LanguageHaskell2010

GHC.Core.Opt.Arity

Description

Arity and eta expansion

Synopsis

Documentation

manifestArity :: CoreExpr -> Arity Source #

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

exprArity :: CoreExpr -> Arity Source #

An approximate, fast, version of exprEtaExpandArity

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

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

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'

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 OneShotInfos 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 Source #

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 Source # 
Instance details

Defined in GHC.Core.Opt.Arity

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.

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.

Coercions and casts