DELETE_FAST has two uses:
delete var where var is a local variable
- Cleaning up at the end of a named exception block.
A local variable can be deleted with the sequence PUSH_NULL; STORE_FAST var.
Deleting a local variable
Instead of DELETE_FAST n we can emit LOAD_FAST n; POP_TOP n; PUSH_NULL; STORE_FAST n which the bytecode optimizer will reduce to PUSH_NULL; STORE_FAST n in most cases.
Cleaning up at the end of a named exception block.
We currently emit the sequence: LOAD_CONST None; STORE_FAST n; DELETE_FAST n
which can be replaced with PUSH_NULL; STORE_FAST n
This case is far more common than explicitly deleting a local variable, so we can reduce code size as well as freeing up an opcode.
See faster-cpython/ideas#490
Linked PRs