Note [unboxedWins]

GHC/Types/Demand.hs:336 compiler 3 tickets

We used to use '_unboxedWins' below in 'lubBoxity', which was too optimistic.

While it worked around some shortcomings of the phase separation between Boxity
analysis and CPR analysis, it was a gross hack which caused regressions itself
that needed all kinds of fixes and workarounds. Examples (from #21119):

  * As #20767 says, L and B were no longer top and bottom of our lattice
  * In #20746 we unboxed huge Handle types that were never needed boxed in the
    first place. See Note [deferAfterPreciseException].
  * It also caused unboxing of huge records where we better shouldn't, for
    example in T19871.absent.
  * It became impossible to work with when implementing !7599, mostly due to the
    chaos that results from #20767.

Conclusion: We should use 'boxedWins' in 'lubBoxity', #21119.
Fortunately, we could come up with a number of better mechanisms to make up for
the sometimes huge regressions that would have otherwise incured:

1. A beefed up Note [Unboxed demand on function bodies returning small products]
   that works recursively fixes most regressions. It's a bit unsound, but
   pretty well-behaved.
2. We saw bottoming functions spoil boxity in some less severe cases and
   countered that with Note [Boxity for bottoming functions].

References 3

Referenced by 2