Remove `DELETE_FAST` bytecode instruction
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
DELETE_FAST has two uses:
delete varwherevaris 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 https://github.com/faster-cpython/ideas/issues/490
Linked PRs
- gh-145983
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the compiler entry points that emit DELETE_FAST for local deletion and named-exception cleanup. Compare their bytecode output with the proposed PUSH_NULL; STORE_FAST sequences, then verify that DELETE_FAST is no longer emitted and existing bytecode tests still pass; the issue references linked PR gh-145983.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100