exprIsConApp_maybe leads to multiple simplifier iterations
Suppose we have a simple data constructor wrapper like this (this one might have come from a data family instance):
$WK x y = K x y |> co
Now suppose the simplifier sees
case ($WK e1 e2) |> co2 of
K p q -> case q of ...
exprIsConApp_maybe
expands the wrapper on the fly (see Note [beta-reduction in exprIsConApp_maybe]
).
It effectively expands that ($WK e1 e2)
to let x = e1; y = e2 in K x y |> co
. So the Simplifier
ends up producing this:
let x = e1; y = e2
in case x of ...
But suppose q
was used just once in the body of the K p q
alternative; we don't
want to wait a whole Simplifier iteration to inline that x
. (e1
might be another
constructor for example.)
The error is that in exprIsConApp_maybe
we are creating a let
for every (non-trivial)
argument. It would be easy instead to take advantage of the occurrence-info on x
and
y
in the unfolding of $WK
. Since in $WK
both x
and y
occur once, we want to effectively
expand ($WK e1 e2)
to K e1 e2 |> co
. Easy really. A one line change. Take much longer to describe than to implement!