Note abouts forcing Type fields in the simplifier
I observed that Type fields, including the Type field of a case binder were ending up retaining substitutions from previous passes which stacked up throughout the whole simplifier.
@simonpj pointed out that the simplifier should discard the case field and recompute a new type to put in it's place. So the mystery was why this old expression was still alive after a simplifier iteration.
I fired up ghc-debug and engineered GHC to pause after a simplifier iteration and then looked at what was retaining the the Subst
from SpecConstr
(as originally implicated by #21993 (closed)).
This leak was caused by a thunk in filterAlts
which retain an old copy of a binding (which then retains a lot of other stuff transitively), forcing that thunk reduced maximum residency from around 2.2G to 800MB.
As part of the investigation I looked into forcing the "Type" fields in exprSize
but this regressed runtime performance, and is pointless anyway because as noted above, the type is just discarded and recomputed on each simplifier iteration.
So the conclusion is:
- Forcing
Type
fields inexprSize
is not an improvement as you end up performing a lot of pointless work which is just discarded. - You have to be careful to manually force everything you are going to put inside an Unfolding because that isn't forced by
exprSize
on each simplifier iteration.