Note [Check the output scrutinee for exprIsHNF]
Consider this:
case x of y {
A -> ....(case y of alts)....
}
Because of the binder-swap, the inner case will get substituted to
(case x of ..). So when testing whether the scrutinee is in HNF we
must be careful to test the *result* scrutinee ('x' in this case), not
the *input* one 'y'. The latter *is* in HNF here (because y is
evaluated), but the former is not -- and indeed we can't float the
inner case out, at least not unless x is also evaluated at its binding
site. See #5453.
That's why we apply exprIsHNF to scrut' and not to scrut.
See Note [Floating single-alternative cases] for why
we use exprIsHNF in the first place. References 1
- Floating single-alternative cases GHC.Core.Opt.SetLevels
Referenced by 1
- GHC.Core.Opt.SetLevels call site