
#14816: Missed Called Arity opportunity?
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.6.1
Component: Compiler | Version: 8.2.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by sgraf):
OK, that didn't work, but for reasons I didn't expect. If we apply that
change, suddenly some bindings get *worse* *strictness* annotations,
although it should only make for *less conservative* (possibly unsound)
*usage* annotations, as `reuseEnv` will only affect usage information.
It turns out that this is due to the interaction between the lazy fv hack
and the fix-pointing algorithm. An example is adapted from T876:
{{{
foo :: Int -> Int
foo n = sum [ length [i..n] | i <- [1..n] ]
main = print (foo 100)
}}}
The variant that does get rid of the call to `reuseEnv` altogether will
produce something like this code:
{{{
foo
= \ (n_aYV [Dmd=] :: [Int])
(eta_B1 [Dmd=] ->
case y_a2c9 of { GHC.Types.I# x_a3jq [Dmd=] ->
case n_aYV of { GHC.Types.I# y_a3jz [Dmd=] ->
case GHC.List.$wlenAcc @ Int (GHC.Enum.eftInt x_a3jq
y_a3jz) 0#
of ww2_a4JP [Dmd=]
{ __DEFAULT ->
GHC.Types.I# (GHC.Prim.+# x_a3ii ww2_a4JP)
}
}
}
})
}; } in
jump go_a2c3
(case n_aYV of { GHC.Types.I# y_a3jz [Dmd=] ->
GHC.Enum.eftInt 1# y_a3jz
})
lvl_s4Jd
}}}
Note that `go` is clearly strict in `n` (that's what HEAD finds out), but
this variant is too conservative. Some printfs revealed that's due to
abortion of fix-pointing. This is a log for the `lazy_fv`s and the
`sig_fv` envs:
{{{
dmdAnalRhsLetDown go_a2c3 [] []
dmdAnalRhsLetDown go_a2c3 [] [aYV :->