Demand: Better representation (#19050)
In #19050 (closed), we identified several ways in which we could make more illegal
states irrepresentable. This patch introduces a few representation changes
around Demand
and Card
with a better and earlier-failing API exported
through pattern synonyms. Specifically,
- The old enum definition of
Card
led to severely bloated code of operations on it. I switched to a bit vector representation; much nicer overall IMO. See Note [Bit vector representation for Card].
Most of the gripes with the old representation were related to where which kind
of Card
was allowed and the fact that it doesn't make sense for an absent or
bottoming demand to carry a SubDemand
that describes an evaluation context
that is never realised.
- So I refactored the
Demand
representation so that it has two new data constructors forAbsDmd
andBotDmd
. The old(:*)
data constructor becomes a pattern synonym which expands absent demands as needed, so that it still forms a complete match and a versatile builder. The newDemand
data constructor now carries aCardNonAbs
and only occurs in a very limited number of internal call sites. - Wherever a full-blown
Card
might end up in aCardNonAbs
field (like that ofD
orCall
), I assert the consistency. When the smart builder of(:*)
is called with an absentCard
, I assert that theSubDemand
is the same that we would expand to in the matcher. -
Poly
now takes aCardNonOnce
and encodes the previously noticed invariant that we never producePoly C_11
orPoly C_01
. I made sure that we never construct aPoly
withC_11
orC_01
.
Fixes #19050 (closed).