Repository navigation
Conversation
Replace DELETE_DEREF with the sequence LOAD_DEREF + POP_TOP + PUSH_NULL + STORE_DEREF in the compiler. Adapt STORE_DEREF to handle NULL stackref for cell clearing.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
This PR is stale because it has been open for 30 days with no activity. |
|
This looks good. Thanks for doing this, and sorry for leaving it hanging for so long. |
|
This PR is stale because it has been open for 90 days with no activity. |
Compile `del` of a closure variable as PUSH_NULL + STORE_DEREF, like the DELETE_NAME, DELETE_GLOBAL and DELETE_ATTR removals. STORE_DEREF with NULL clears the cell with PyCell_SwapTakeRef and raises if it was already empty, as DELETE_DEREF did. With LOAD_DEREF + POP_TOP before the store, two threads of the free-threaded build could both delete the same value. Also move the What's New entry to 3.16 and add a codegen test.
|
The following commit authors need to sign the Contributor License Agreement: |
|
Sorry for the long delay. I merged main and resolved the conflicts (magic number 3709, What's New entry moved to 3.16). I also found that |
Documentation build overview
|
Summary
Remove the
DELETE_DEREFopcode. The compiler now emitsPUSH_NULL+STORE_DEREFfordelof a closure variable, like theDELETE_NAME,DELETE_GLOBALandDELETE_ATTRremovals.STORE_DEREFwithNULLclearsthe cell with
PyCell_SwapTakeRefand raises if it was already empty, so thedeletion stays atomic on the free-threaded build.
This frees up one opcode slot.
Changes
codegen_nameop()now emitsPUSH_NULL+STORE_DEREFinstead ofDELETE_DEREFforDelcontext on deref variablesDELETE_DEREFinstruction definition;STORE_DEREFwith aNULLstackref clears the cell and raises if it wasalready empty
DELETE_DEREFfrom offset fixup switchPYC_MAGIC_NUMBER3708 → 3709delof aclosure variable
Test plan
The test plan, the stress and benchmark scripts and their results below are
from the earlier
LOAD_DEREF+POP_TOP+PUSH_NULL+STORE_DEREFversion of this PR.
test_scope,test_dis,test_compile,test_compiler_assemble,test_peepholer,test_opcodes: all passrefcount/leak detection, nested closures, 8-thread concurrent del
Stress test script
stress_delete_deref.py
Benchmark script
bench_delete_deref.py
Results (free-threading debug build, dedicated server,
taskset -c 0)DELETE_DEREFbytecode instruction #145858📚 Documentation preview 📚: https://cpython-previews--148185.org.readthedocs.build/