Making INLINE functions behave more like normal functions
See also
If you have
f x y z = <expr>
h xs = map (f True (\v. not v)) xs
then GHC may well inline f
at its call site, and thereby specialise it with x=True
and y=\v.not v
, which is great.
But if you say {-# INLINE f #-}
we insist on only inlning f
when it is applied to as many argument as appear on the LHS of the function defintion (3 in this case). So adding INLINE will make the code optimise worse. That's not a good look. The regressions in #22886 are an example of what can happen.
So here's the proposal: allow INLINE functions to inline even if not applied to the number of args on the LHS.
Why do we have this "inline only if saturated" rule? The reasons seem to be lost in the mists of time. Clearly we should be rather cautious about changing this, but
- we have no documented reason for why it is a good idea
- it can make INLINE functions behave worse than non-INLINE ones
To mitigate the risks, one could imagine having a flag to let you get back the old behaiour.