Note [Function body boxity and call sites]

GHC/Types/Demand.hs:218 compiler

Consider (from T5949)
```
f n p = case n of
  0 -> p :: (a, b)
  _ -> f (n-1) p
Worker/wrapper split if we decide to unbox:
$wf n x y = case n of
  0 -> (# x, y #)
  _ -> $wf (n-1) x y
f n (x,y) = case $wf n x y of (# r, s #) -> (r,s)
```
When is it better to /not/ to unbox 'p'? That depends on the callers of 'f'!
If all call sites

 1. Wouldn't need to allocate fresh boxes for 'p', and
 2. Needed the result pair of 'f' boxed

Only then we'd see an increase in allocation resulting from unboxing. But as
soon as only one of (1) or (2) holds, it really doesn't matter if 'f' unboxes
'p' (and its result, it's important that CPR follows suit). For example
```
res = ... case f m (field t) of (r1,r2) -> ...  -- (1) holds
arg = ... [ f m (x,y) ] ...                     -- (2) holds
```
Because one of the boxes in the call site can cancel away:
```
res = ... case field1 t of (x1,x2) ->
          case field2 t of (y1,y2) ->
          case $wf x1 x2 y1 y2 of (#r1,r2#) -> ...
arg = ... [ case $wf x1 x2 y1 y2 of (#r1,r2#) -> (r1,r2) ] ...
```
And when call sites neither have arg boxes (1) nor need the result boxed (2),
then hesitating to unbox means /more/ allocation in the call site because of the
need for fresh argument boxes.

Summary: If call sites that satisfy both (1) and (2) occur more often than call
sites that satisfy neither condition, then it's best /not/ to unbox 'p'.

References 0

This Note does not link to any other.

Referenced by 2