Skip to content

Demand: Better representation (#19050)

Sebastian Graf requested to merge wip/T19050 into master

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,

  1. 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.

  1. So I refactored the Demand representation so that it has two new data constructors for AbsDmd and BotDmd. 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 new Demand data constructor now carries a CardNonAbs and only occurs in a very limited number of internal call sites.
  2. Wherever a full-blown Card might end up in a CardNonAbs field (like that of D or Call), I assert the consistency. When the smart builder of (:*) is called with an absent Card, I assert that the SubDemand is the same that we would expand to in the matcher.
  3. Poly now takes a CardNonOnce and encodes the previously noticed invariant that we never produce Poly C_11 or Poly C_01. I made sure that we never construct a Poly with C_11 or C_01.

Fixes #19050 (closed).

Edited by Sebastian Graf

Merge request reports