eval/importing parity: IMPORT_STAR sync, SETUP_ANNOTATIONS probe, IMPORT_NAME __import__ - #470
Conversation
IMPORT_STAR fetched the locals mapping via get_or_create_w_locals, skipping both the fast2locals pre-sync and the locals2fast writeback. Port the pyopcode.py IMPORT_STAR shape: getdictscope() before import_all_from_w, setdictscope() after. SETUP_ANNOTATIONS probed for __annotations__ with a membership check; pyopcode.py uses finditem_str item lookup, which a custom mapping's __contains__ can disagree with. The store keeps setitem with a w_str_new key since pyre has no setitem_str. Assisted-by: Claude
Comment-only: the hand-run write barriers in function_write_barrier and the Object-strategy list barrier now cite the GC-transform insertions they stand in for (minimark.py write_barrier, rgc.py ll_writebarrier); pyre has no transform pass, so callers run them by hand. Assisted-by: Claude
WalkthroughImport-name handling is centralized through a frame-aware helper used by interpreter and JIT paths. Annotation and star-import locals handling is adjusted, while function and list write-barrier documentation is expanded. ChangesImport and locals execution
Write-barrier documentation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant PyFrame
participant import_name
participant BuiltinImport
PyFrame->>import_name: provide import name, fromlist, and flag
import_name->>PyFrame: resolve builtins and frame locals
import_name->>BuiltinImport: invoke __import__
BuiltinImport-->>import_name: return module
import_name-->>PyFrame: push imported module
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🤖 Codex parity reviewStatic analysis of this diff vs the local RPython/PyPy sources (commit 970958f). 1. Regressions to PyPy parity introduced by this patch
2. Other mismatches introduced by this patchNone. 3. Pre-existing mismatches (already present before this patch)None. 4. Structural adaptations
|
IMPORT_NAME resolved modules by calling importhook directly, so a monkeypatched builtins.__import__ was ignored. Port the pyopcode.py IMPORT_NAME shape into importing::import_name: fetch __import__ from the frame's builtins (ImportError "__import__ not found" when missing), take w_locals from the frame debug slot or None, and call it with (w_modulename, w_globals, w_locals, w_fromlist, w_flag). The eval-loop opcode and the JIT residual bh_import_name_fn both route through the new helper; the residual's level operand is passed through as the flag object instead of being unboxed to an int. extra_tests/snippets/import.py now passes its __import__-override assertions. Assisted-by: Codex Assisted-by: Claude
Two follow-up slices from the same sub-agent batch as #465.
eval: IMPORT_STAR dictscope sync, annotations item probe
Ports two
pyopcode.pyshapes inpyre-interpreter/src/eval.rs:get_or_create_w_locals, skipping both thefast2localspre-sync and thelocals2fastwriteback. Now follows pyopcode.pyIMPORT_STAR:getdictscope()→import_all_from_w→setdictscope(w_locals), so the mapping reflects live fast locals before the merge and the merged names are written back into the frame's fast locals.__annotations__with a membership check (contains); pyopcode.py usesfinditem_stritem lookup, which a custom mapping's__contains__can disagree with. The store keepssetitemwith aw_str_newkey since pyre has nosetitem_str.Parity spot checks (pyre vs CPython, identical output/exit):
from module import *with local writeback, and class-level annotations including re-annotation.gc: cite upstream write-barrier decision points
Comment-only: the hand-run write barriers (
function_write_barrier, Object-strategy list barrier) now cite the GC-transform insertions they stand in for (minimark.pywrite_barrier,rgc.pyll_writebarrier); pyre has no transform pass, so callers run them by hand.Verification
cargo test -p pyre-interpreter --features dynasm --lib— 375 passed, 0 failedpython ./pyre/check.py --backend cranelift— 161/161 ALL PASSEDpython ./pyre/check.py --backend dynasm— 160/161: the one failure is thenested_loopperf-ratio gate (0.47s vs pypy 0.22s, stable across direct reruns), pre-existing on the current main base:nested_loop.pycontains noimport */ annotations, so this diff's opcode bodies never execute there. It first appears with the base advance that brought in jit-regalloc: retire walker-slot cross-slot coalesce filter for pcdep-sourced interference (#371) #424 (dynasm regalloc walker-slot coalesce filter retirement); cranelift is unaffected. Worth a separate look.importing: IMPORT_NAME calls builtins import
Found while verifying the above:
IMPORT_NAMEignored a monkeypatchedbuiltins.__import__and always performed a real import (extra_tests/snippets/import.pyfailed its__import__-override assertions). Ported the pyopcode.pyIMPORT_NAMEshape intoimporting::import_name— fetch__import__from the frame's builtins (ImportError "__import__ not found"when missing),w_localsfrom the frame debug slot orNone, call it with(w_modulename, w_globals, w_locals, w_fromlist, w_flag). Both the eval-loop opcode and the JIT residualbh_import_name_fnroute through the helper. With this commit the full gate is green on both backends: dynasm 161/161, cranelift 161/161 (includingnested_loop, confirming the earlier perf-gate failure was borderline load sensitivity).🤖 Generated with Claude Code
Summary by CodeRabbit
__annotations__for custom local mappings, ensuring consistent lookup behavior.