Note [Boxity in Poly]

GHC/Types/Demand.hs:1322 compiler

To support Note [Boxity analysis], it makes sense that 'Prod' carries a
'Boxity'. But why does 'Poly' have to carry a 'Boxity', too? Shouldn't all
'Poly's be 'Boxed'? Couldn't we simply use 'Prod Unboxed' when we need to
express an unboxing demand?

'botSubDmd' (B) needs to be the bottom of the lattice, so it needs to be an
Unboxed demand (and deeply, at that). Similarly, 'seqSubDmd' (A) is an Unboxed
demand. So why not say that Polys with absent cardinalities have Unboxed boxity?
That doesn't work, because we also need the boxed equivalents. Here's an example
for A (function 'absent' in T19871):
```
f _ True  = 1
f a False = a `seq` 2
  demand on a: MA, the A is short for `Poly Boxed C_00`

g a = a `seq` f a True
  demand on a: SA, which is `Poly Boxed C_00`

h True  p       = g p -- SA on p (inherited from g)
h False p@(x,y) = x+y -- S!P(1!L,1!L) on p
```
If A is treated as Unboxed, we get reboxing in the call site to 'g'.
So we obviously would need a Boxed variant of A. Rather than introducing a lot
of special cases, we just carry the Boxity in 'Poly'. Plus, we could most likely
find examples like the above for any other cardinality.

References 1

Referenced by 2