◐ Shell
clean mode source ↗

Specialization of some instructions does not conform to PEP 659, and prevents PEP 669

As written, PEP 659 says that individual specializations are restricted to a single instruction.
PEP 669 relies on this, as it also wants to replace instructions at runtime, and it would break if specialization occurs across multiple instructions.

Currently there are a two places where we break this design by specializing pairs of instructions together:

  • COMPARE_OP POP_JUMP_IF_ pairs are specialized together
  • FOR_ITER STORE_FAST are specialized together

The second will go away with the register VM, and doesn't seem to be an issue in practice.
It is the COMPARE_OP POP_JUMP_IF_ specialization that is problematic, as PEP 669 wants to instrument branches.
Instrumenting the POP_JUMP_IF_ doesn't work if the COMPARE_OP specialization jumps over it.

The solution is to replace the COMPARE_OP POP_JUMP_IF_ pair with a single COMPARE_AND_BRANCH instruction that can be specialized or instrumented atomically.

Linked PRs