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
DELETE_FASThas two uses:delete varwherevaris a local variableA local variable can be deleted with the sequence
PUSH_NULL; STORE_FAST var.Deleting a local variable
Instead of
DELETE_FAST nwe can emitLOAD_FAST n; POP_TOP n; PUSH_NULL; STORE_FAST nwhich the bytecode optimizer will reduce toPUSH_NULL; STORE_FAST nin 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 nwhich can be replaced with
PUSH_NULL; STORE_FAST nThis 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