WorkerWrapper produces wrappers with wrong arity.
In one of my patches I look at a case where we produce a invalid wrapper unfolding for a join point.
What we get is this:
join {
$j_s8Bi [InlPrag=[2], Dmd=SCS(C1(!L))]
:: Word# -> BitMap -> StrictPair IntSet IntSet
[LclId[JoinId(2)(Nothing)],
Arity=2,
Str=<SL><L>,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=False)
Tmpl= jump $w$j_s8J5}]
$j_s8Bi (ipv_s8J2 [Dmd=SL, OS=OneShot] :: Word#)
(bm1_s8J3 [OS=OneShot]
:: BitMap
Unf=OtherCon [])
= jump $w$j_s8J5 ipv_s8J2 bm1_s8J3 } in
Here we get a unfolding without any lambdas. However this is wrong:
2. For join arity n, the right-hand side must begin with at least n lambdas.
No ticks, no casts, just lambdas! C.f. GHC.Core.Utils.joinRhsArity.
2a. Moreover, this same constraint applies to any unfolding of
the binder. Reason: if we want to push a continuation into
the RHS we must push it into the unfolding as well.
One thing I noticed is that we set the unfolding arity to the IdArity not the JoinArity. Which can be lower. Not sure if it that matters though.
We generate the unfolding via this snippet: wrap_unf = mkWrapperUnfolding simpl_opts wrap_rhs arity
. wrap_rhs still has the lambdas. They seem to disappear when we run (simpleOptExpr opts expr)
with expr being the RHS.
simplOptExpr goes on to collect the binders and then calls out to tryEtaReduce
for an attempt at eta-reduction.
There aren't any checks in tryEtaReduce that look for join points. I will add one.