simplifier: Zap Id unfoldings before constructing InScopeSet in simpleOptExpr
Care must be taken to remove unfoldings from Var
s collected by exprFreeVars
before using them to construct an in-scope set.
Consider calling simpleOptExpr
on an expression like
case x of (a,b) -> (x,a)
- One of those two occurrences of x has an unfolding (the one in (x,a), with unfolding x = (a,b)) and the other does not. (Inside a case GHC adds unfolding-info to the scrutinee's Id.)
- But exprFreeVars just builds a set, so it's a bit random which occurrence is collected.
- Then simpleOptExpr replaces each occurrence of x with the one in the in-scope set.
- ! Bad bad bad: then the x in case x of ... may be replaced with a version that has an unfolding.
Fixes #25790 (closed)