sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[dart2js] Improve HInstruction/HPhi type hierarchy

Open fishythefish opened this issue 1 year ago • 0 comments

Currently, HPhi is just one of the many subclasses of HInstruction, but it would be nice to have a stronger separation between phis and non-phis. Our current type hierarchy is insufficient to express some important invariants:

  • HPhi.next, if it exists, is another phi. Currently, we cast when necessary.
  • Phis can only be added to/removed from a basic block in certain ways. (Corollary: certain nodes are known to be HInstructions which are not HPhis.) Currently, we "enforce" this with assertions.

Likewise, it would be nice to have a clearer distinction between HInstructionList and HPhiList.

One hurdle is that the relevant features in the Dart system are not totally free:

  • Some subclassing is okay, but we want to avoid virtual dispatch on hot APIs (e.g. HInstruction.next). This is why we cast HPhi.next rather than overriding.
  • Generics (and covariant members) incur parameter checks.

/cc @rakudrama - feel free to add other invariants/hurdles.

fishythefish avatar Feb 15 '24 02:02 fishythefish