Skip to content

Demand: Let `Boxed` win in `lubBoxity`

This ticket tracks the motivation for !7609 (closed).

!5790 (closed) introduced a rather gross hack to work around various regressions introduced by conservative boxity analysis. We let Unboxed win in lubBoxity, which is unsoundly optimistic. "Unsoundly" in the sense that we sometimes unbox parameters that we better shouldn't unbox. Here's a list where that bites us:

  • #18907 (closed) and T19871.absent unbox huge records when they shouldn't
  • In #20746 (closed), we saw that the simple definition of deferAfterPreciseException = lubDmdType exnDmdTyp unboxes huge Handle types in GHC.IO.Handle.Text, although all actual use sites of the Handle were Boxed. The reason we unboxed it was the Unboxed flag coming from the absent free variable demand of exnDmdType, which will ultimately win against the Boxed use sites.
  • The implementation of lubDmd became complex to reason about, working around the issue of too much (and unsound) unboxing by letting Boxed win when lubbing with the bottom demand B, whereas when lubbing with A, we let Unboxed win.
  • #20767 (closed) gives other, similar examples where we show that B and L aren't actually bottom and top of the lattice at the moment. That's terrible!
  • In the implementation of !7599 (merged), which fixes #21081 (closed), I found that I had contradicting requirements of lub and plus because of these last two points.
Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information