HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.Core.Opt.Arity

Arity and eta expansion

  • 2 types
  • 30 values
  • Packageghc-9.10.3
  • Exports32
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceArity.hs
valueexprArity :: CoreExpr -> Arity
#

An approximate, even faster, version of cheapArityType Roughly exprArity e = arityTypeArity (cheapArityType e) But it's a bit less clever about bottoms

We do not guarantee that exprArity e <= typeArity e You may need to do arity trimming after calling exprArity See Note [Arity trimming] Reason: if we do arity trimming here we have take exprType and that can be expensive if there is a large cast

Eta expansion

valueetaExpand :: Arity -> CoreExpr -> CoreExpr
#

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'

Eta reduction

`tryEtaReduce [x,y,z] e sd` returns `Just e'` if `x y z -> e` is evaluated according to sd and can soundly and gainfully be eta-reduced to e'. See Note [Eta reduction soundness] and Note [Eta reduction makes sense] when that is the case.

ArityType

datadata ArityType
#

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: optimistic one-shot-ness]

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

Instances2Eq, Outputable
  • Eq ArityTypeDefined in ghc-9.10.3 · GHC.Core.Opt.Arity
  • Outputable ArityTypeDefined in ghc-9.10.3 · GHC.Core.Opt.Arity

    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 .@.

Bottoming things

typeArity and the state hack

valuetypeArity :: Type -> Arity
#

(typeArity ty) says how many arrows GHC can expose in ty, after looking through newtypes. More generally, (typeOneShots ty) returns ty's [OneShotInfo], based only on the type itself, using typeOneShot on the argument type to access the "state hack".

valueisOneShotBndr :: Var -> Bool
#

Returns whether the lambda associated with the Id is certainly applied at most once This one is the "business end", called externally. It works on type variables as well as Ids, returning True Its main purpose is to encapsulate the Horrible State Hack See Note [The state-transformer hack] in GHC.Core.Opt.Arity

Lambdas

1 declaration

Join points

Coercions and casts

If pushCoValArg co = Just (co_arg, co_res), then

(\x.body) |> co  =  (\y. let { x = y |> co_arg } in body) |> co_res)

or, equivalently

(fun |> co) arg  =  (fun (arg |> co_arg)) |> co_res

If the LHS is well-typed, then so is the RHS. In particular, the argument arg |> co_arg is guaranteed to have a fixed RuntimeRep, in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.