Commit 9ea5992
gh-151321: Fix opcode metadata flags for LOAD_DEREF and LOAD_CLOSURE
LOAD_DEREF and LOAD_CLOSURE were missing HAS_FREE_FLAG in the generated
opcode metadata, and both also carried HAS_LOCAL_FLAG, so dis.hasfree no
longer reported them while dis.haslocal wrongly included them. This
regressed the documented dis.hasfree / dis.haslocal contract: LOAD_CLOSURE
broke in 3.13 (when it became a pseudo-op inheriting LOAD_FAST's flags) and
LOAD_DEREF broke in 3.14 (when it started using _PyCell_GetStackRef, which
the cases generator's has_free heuristic did not recognize).
Teach the cases generator to treat _PyCell_GetStackRef as a free-variable
access, and give the LOAD_CLOSURE pseudo an explicit HAS_FREE flag. A pseudo
that explicitly accesses a free variable now suppresses the inherited
HAS_LOCAL, mirroring the existing "uses_locals and not has_free" rule for
real instructions, so HAS_FREE and HAS_LOCAL are never both set. The change
is to introspection metadata only; the generated interpreter and optimizer
code are unchanged.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 80f9467 commit 9ea5992
6 files changed
Lines changed: 34 additions & 5 deletions
File tree
- Include/internal
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Python
- Tools/cases_generator
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
64 | 81 | | |
65 | 82 | | |
66 | 83 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
| 267 | + | |
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
317 | 325 | | |
318 | 326 | | |
319 | 327 | | |
| |||
970 | 978 | | |
971 | 979 | | |
972 | 980 | | |
| 981 | + | |
973 | 982 | | |
974 | 983 | | |
975 | 984 | | |
| |||
0 commit comments