Note [No free join points in arityType]
Suppose we call arityType on this expression (EX1)
\x . case x of True -> \y. e
False -> $j 3
where $j is a join point. It really makes no sense to talk of the arity
of this expression, because it has a free join point. In particular, we
can't eta-expand the expression because we'd have do the same thing to the
binding of $j, and we can't see that binding.
If we had (EX2)
\x. join $j y = blah
case x of True -> \y. e
False -> $j 3
then it would make perfect sense: we can determine $j's ArityType, and
propagate it to the usage site as usual.
But how can we get (EX1)? It doesn't make much sense, because $j can't
be a join point under the \x anyway. So we make it a precondition of
arityType that the argument has no free join-point Ids. (This is checked
with an assert in the Var case of arityType.)
Wrinkles
* We /do/ allow free join point when doing findRhsArity for join-point
right-hand sides. See Note [Arity for recursive join bindings]
point (5) in GHC.Core.Opt.Simplify.Utils.
* The invariant (no free join point in arityType) risks being
invalidated by one very narrow special case: runRW#
join $j y = blah
runRW# (\s. case x of True -> \y. e
False -> $j x)
We have special magic in OccurAnal, and Simplify to allow continuations to
move into the body of a runRW# call.
So we are careful never to attempt to eta-expand the (\s.blah) in the
argument to runRW#, at least not when there is a literal lambda there,
so that OccurAnal has seen it and allowed join points bound outside.
See Note [No eta-expansion in runRW#] in GHC.Core.Opt.Simplify.Iteration. References 2
- Arity for recursive join bindings GHC.Core.Opt.Arity
- No eta-expansion in runRW# GHC.Core.Opt.Simplify.Iteration
Referenced by 5
- GHC.Core.Opt.Arity call site ×2
- Arity for recursive join bindings GHC.Core.Opt.Arity
- arityType for recursive let-bindings GHC.Core.Opt.Arity
- No eta-expansion in runRW# GHC.Core.Opt.Simplify.Iteration