Note [Do not eta reduce PAPs]
I considered eta-reducing if the result is a PAP: \x. f e1 e2 x ==> f e1 e2 This reduces clutter, sometimes a lot. See Note [Do not eta-expand PAPs] in GHC.Core.Opt.Simplify.Utils, where we are careful not to eta-expand a PAP. If eta-expanding is bad, then eta-reducing is good! Also the code generator likes eta-reduced PAPs; see GHC.CoreToStg.Prep Note [No eta reduction needed in rhsToBody]. But note that we don't want to eta-reduce \x y. f <expensive> x y to f <expensive> The former has arity 2, and repeats <expensive> for every call of the function; the latter has arity 0, and shares <expensive>. We don't want to change behaviour. Hence the call to exprIsCheap in ok_fun. I noticed this when examining #18993 and, although it is delicate, eta-reducing to a PAP happens to fix the regression in #18993. HOWEVER, if we transform \x. f y x ==> f y that might mean that f isn't saturated any more, and does not inline. This led to some other regressions. TL;DR currently we do /not/ eta reduce if the result is a PAP.
References 2
- Do not eta-expand PAPs GHC.Core.Opt.Simplify.Utils
- No eta reduction needed in rhsToBody GHC.CoreToStg.Prep
Referenced by 1
- Eta reduction makes sense GHC.Core.Opt.Arity