Note [Eta expanding primops]

GHC/Builtin/PrimOps.hs:801 compiler 3 tickets

STG requires that primop applications be saturated. This makes code generation
significantly simpler since otherwise we would need to define a calling
convention for curried applications that can accommodate representation
polymorphism.

To ensure saturation, CorePrep eta expands all primop applications as
described in Note [Eta expansion of hasNoBinding things in CorePrep] in
GHC.Core.Prep.

Historical Note:

For a short period around GHC 8.8 we rewrote unsaturated primop applications to
rather use the primop's wrapper (see Note [Primop wrappers] in
GHC.Builtin.PrimOps) instead of eta expansion. This was because at the time
CoreTidy would try to predict the CAFfyness of bindings that would be produced
by CorePrep for inclusion in interface files. Eta expanding during CorePrep
proved to be very difficult to predict, leading to nasty inconsistencies in
CAFfyness determinations (see #16846).

Thankfully, we now no longer try to predict CAFfyness but rather compute it on
GHC STG (see Note [SRTs] in GHC.Cmm.Info.Build) and inject it into the interface
file after code generation (see TODO: Refer to whatever falls out of #18096).
This is much simpler and avoids the potential for inconsistency, allowing us to
return to the somewhat simpler eta expansion approach for unsaturated primops.

See #18079.

References 3

Referenced by 3