sdk
sdk copied to clipboard
[dart2js] Improve HInstruction/HPhi type hierarchy
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 notHPhis.) 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 castHPhi.nextrather than overriding. - Generics (and
covariantmembers) incur parameter checks.
/cc @rakudrama - feel free to add other invariants/hurdles.