Note [Don't eta expand in w/w]
A binding where the manifestArity of the RHS is less than idArity of the binder means GHC.Core.Opt.Arity didn't eta expand that binding When this happens, it does so for a reason (see Note [Arity invariants for bindings] in GHC.Core.Opt.Arity) and we probably have a PAP, cast or trivial expression as RHS. Below is a historical account of what happened when w/w still did eta expansion. Nowadays, it doesn't do that, but will simply w/w for the wrong arity, unleashing a demand signature meant for e.g. 2 args to be unleashed for e.g. 1 arg (manifest arity). That's at least as terrible as doing eta expansion, so don't do it. When worker/wrapper did eta expansion, it implictly eta expanded the binding to idArity, overriding GHC.Core.Opt.Arity's decision. Other than playing fast and loose with divergence, it's also broken for newtypes: f = (\xy.blah) |> co where co :: (Int -> Int -> Char) ~ T Then idArity is 2 (despite the type T), and it can have a DmdSig based on a threshold of 2. But we can't w/w it without a type error. The situation is less grave for PAPs, but the implicit eta expansion caused a compiler allocation regression in T15164, where huge recursive instance method groups, mostly consisting of PAPs, got w/w'd. This caused great churn in the simplifier, when simply waiting for the PAPs to inline arrived at the same output program. Note there is the worry here that such PAPs and trivial RHSs might not *always* be inlined. That would lead to reboxing, because the analysis tacitly assumes that we W/W'd for idArity and will propagate analysis information under that assumption. So far, this doesn't seem to matter in practice. See https://gitlab.haskell.org/ghc/ghc/merge_requests/312#note_192064.
References 1
- Arity invariants for bindings GHC.Core.Opt.Arity
Referenced by 3
- Arity trimming for CPR signatures GHC.Core.Opt.CprAnal
- The demand for the RHS of a binding GHC.Core.Opt.DmdAnal
- GHC.Core.Opt.WorkWrap call site