Align specialization guards and caching with CPython by youknowone · Pull Request #7341 · RustPython/RustPython
Repository navigation
Align specialization guards and caching with CPython - #7341
Merged
youknowone merged 31 commits into RustPython:main from youknowone:specialization Mar 4, 2026
Merged
Align specialization guards and caching with CPython #7341 youknowone merged 31 commits into RustPython:main from youknowone:specialization
Conversation
youknowone
commented
Mar 4, 2026
·
edited by coderabbitai
Bot
Loading
Copy link Copy Markdown
Member
Summary by CodeRabbit
-
Bug Fixes
- Improved tuple index bounds checking with clearer "tuple index out of range" errors.
-
Refactor
- Revamped bytecode storage and adaptive counter handling for safer concurrent access and more stable instruction iteration.
- De-specialized instruction streams to avoid runtime-mutated code during compilation.
- Hardened JIT code caching and invalidation.
-
Performance
- Added hint-based fast-paths for exact-dict lookups to speed common dictionary accesses.
-
Behavior
- Expanded instrumentation to treat an additional resume instruction as traceable.
coderabbitai
Bot
commented
Mar 4, 2026
·
edited
Loading
Copy link Copy Markdown
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info ⚙️ Run configurationConfiguration used : Path: .coderabbit.yml Review profile : CHILL Plan : Pro Run ID : Reviewing files that changed from the base of the PR and between 968372a and cc3fd09 . 📒 Files selected for processing (2)
📝 Walkthrough WalkthroughRefactors adaptive counters into out-of-line bit‑encoded AtomicU16 storage and updates CodeUnits layout/APIs; routes JIT compilation over cleaned bytecode bytes; adds dict hint/get_hint fast‑path helpers; adds PyBoundMethod accessors and JIT guards; tightens tuple index bounds handling and expands instrumentation trace detection. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem🚥 Pre-merge checks | ✅ 3 ✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches 🧪 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. ❤️ ShareComment |
d1dc3d6 to
2d7c2f7
Compare
March 4, 2026 11:00 youknowone changed the title Specialization Align specialization guards and caching with CPython Mar 4, 2026 youknowone force-pushed the specialization branch from
c03189d to
6d096fe
Compare
March 4, 2026 12:04
github-actions
Bot
commented
Mar 4, 2026
·
edited
Loading
Copy link Copy Markdown
Contributor
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/pickle.py dependencies:
dependent tests: (97 tests)
Legend:
|
fix jit
c6b6842
vm: complete specialized opcode dispatch paths
b379239
vm: cache LOAD_GLOBAL with dict entry hints
bdeca2b
vm: align adaptive specialization counters with CPython backoff
ca3814a
vm: apply cooldown counter on specialization success paths
f04bf22
vm: retain LOAD_GLOBAL specializations on misses
02a1495
vm: keep attr and call specializations on guard misses
13125d8
vm: retain store-attr and store-subscr specializations on misses
c7007b5
vm: retain specialization opcodes on generic fallback paths
453294d
vm: align jump-backward specialization defaults with CPython
b8f6cc2
vm: retain exact-args call specializations on misses
7bfa961
vm: retain SEND_GEN specialization on non-coroutine sends
c852994
vm: specialize list.append calls like CPython CALL_LIST_APPEND
1a1bbf5
vm: set cooldown on LOAD_ATTR_CLASS specialization
bdd87f4
vm: specialize bound method object CALL paths
696e57a
vm: specialize CALL_KW for bound method objects
3dc64cc
vm: use current-state function version for CALL_KW specialization
f220a24
vm: align CALL/CALL_KW pyfunction specialization with CPython
a66c706
vm: drop call-site identity caches in generic CALL specializations
59545f5
vm: align builtin type call specializations with CPython guards
f8eebec
vm: align builtin CALL guards with CPython self_or_null semantics
58bb1ea
vm: require exact list in CALL_LIST_APPEND fast path
157a2c3
vm: align CALL builtin/class specialization flow with CPython
cae26d4
vm: tighten len/isinstance CALL specializations to builtin guards
0d01f7e
youknowone
added 5 commits
March 4, 2026 23:30
vm: gate CALL_BUILTIN_CLASS on type vectorcall like CPython
22cccae
vm: run non-py CALL specializations via direct vectorcall
30e8a75
vm: align class-call specialization branching with CPython
da36859
Fix CI: disable ForIterGen, tighten CALL guards
42d81ff
- Disable ForIterGen specialization (falls through to generic path) because inline generator frame resumption is needed for correct debugger StopIteration visibility (test_bdb) - Use downcast_ref_if_exact for PyNativeFunction in CALL specialization guards - Add can_specialize_call guard for class __init__ specialization - Remove expectedFailure for test_bad_newobj_args (now passing)
vm: restore FOR_ITER_GEN specialization and tuple index parity
d464119
youknowone
force-pushed
the
specialization
branch
from
6d096fe to
d464119
Compare
March 4, 2026 14:30 youknowone marked this pull request as ready for review March 4, 2026 14:36 coderabbitai
Bot
reviewed Mar 4, 2026
View reviewed changes
coderabbitai
Bot
left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agentsVerify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/vm/src/dict_inner.rs`:
- Around line 366-374: Snapshot the entry's key and value while holding the dict
read guard, drop the guard, then perform equality; specifically, in the block
that uses self.read() and inner.entries.get(hint) (and currently calls
key.key_is and key.key_eq on entry.key), clone/copy the entry.key and
entry.value out of the inner guard, release the guard, and then run
key.key_is(&cloned_key) and only if needed call key.key_eq(vm, &cloned_key) to
decide the result and return the cloned value; this avoids invoking key_eq while
holding the read lock.
ℹ️ Review info ⚙️ Run configuration
Configuration used : Path: .coderabbit.yml
Review profile : CHILL
Plan : Pro
Run ID : 1b01ab44-3238-428f-8cd8-393e5623cbb5
Reviewing files that changed from the base of the PR and between 68ad332 and d464119 .
⛔ Files ignored due to path filters (1)Lib/test/test_pickle.pyis excluded by!Lib/**
crates/compiler-core/src/bytecode.rscrates/jit/src/instructions.rscrates/vm/src/builtins/dict.rscrates/vm/src/builtins/function.rscrates/vm/src/builtins/tuple.rscrates/vm/src/dict_inner.rscrates/vm/src/frame.rscrates/vm/src/stdlib/sys/monitoring.rs
Bot
reviewed Mar 4, 2026
View reviewed changes
chatgpt-codex-connector
Bot
left a comment
Copy link Copy Markdown
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d464119937
Your team has set up Codex to review pull requests in this repo . Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Comment thread crates/vm/src/frame.rs Comment on lines 322 to 324| builtins: PyObjectRef, | ||
| closure: &[PyCellRef], | ||
| func_obj: Option<PyObjectRef>, |
Add datastack-backed FastLocals for non-generator frames
0f044d6
Introduce FastLocalsData enum with Heap and DataStack variants so non-generator/coroutine frames allocate localsplus on the VM datastack instead of the heap. Includes materialize_to_heap for migration when needed (e.g. generator suspension).youknowone force-pushed the specialization branch from
968372a to
0f044d6
Compare
March 4, 2026 15:17 youknowone marked this pull request as ready for review March 4, 2026 15:19
Drop read lock before key_eq in dict get_hint
cc3fd09
Move key_eq call outside the read lock guard to avoid potential deadlock when Python __eq__ re-enters dict mutation paths. Matches the existing pattern in lookup().chatgpt-codex-connector
Bot
reviewed Mar 4, 2026
View reviewed changes
chatgpt-codex-connector
Bot
left a comment
Copy link Copy Markdown
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc3fd09611
Your team has set up Codex to review pull requests in this repo . Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Comment thread crates/vm/src/frame.rs| @@ -2805,7 +2828,7 @@ impl ExecutingFrame<'_> { | ||
| Ok(None) |
9a0511b
into
RustPython : main
Mar 4, 2026
13 checks passed
youknowone
deleted the
specialization
branch
March 4, 2026 16:59
This was referenced Mar 5, 2026
Fix thread-safety in GC, type cache, and instruction cache
#7355
Merged
Refine specialization caches and extend binary-op coverage
#7386
Merged
youknowone
added a commit
to youknowone/RustPython
that referenced
this pull request
Mar 22, 2026
Align specialization guards and caching with CPython (RustPython#7341)
a648880
* vm: complete specialized opcode dispatch paths * vm: cache LOAD_GLOBAL with dict entry hints * vm: align adaptive specialization counters with CPython backoff * vm: apply cooldown counter on specialization success paths * vm: retain LOAD_GLOBAL specializations on misses * vm: keep attr and call specializations on guard misses * vm: retain store-attr and store-subscr specializations on misses * vm: retain specialization opcodes on generic fallback paths * vm: align jump-backward specialization defaults with CPython * vm: retain exact-args call specializations on misses * vm: retain SEND_GEN specialization on non-coroutine sends * vm: specialize list.append calls like CPython CALL_LIST_APPEND * vm: set cooldown on LOAD_ATTR_CLASS specialization * vm: specialize bound method object CALL paths * vm: specialize CALL_KW for bound method objects * vm: use current-state function version for CALL_KW specialization * vm: align CALL/CALL_KW pyfunction specialization with CPython * vm: drop call-site identity caches in generic CALL specializations * vm: align builtin type call specializations with CPython guards * vm: align builtin CALL guards with CPython self_or_null semantics * vm: require exact list in CALL_LIST_APPEND fast path * vm: align CALL builtin/class specialization flow with CPython * vm: tighten len/isinstance CALL specializations to builtin guards * vm: gate CALL_BUILTIN_CLASS on type vectorcall like CPython * vm: run non-py CALL specializations via direct vectorcall * vm: align class-call specialization branching with CPython * Fix CI: disable ForIterGen, tighten CALL guards - Disable ForIterGen specialization (falls through to generic path) because inline generator frame resumption is needed for correct debugger StopIteration visibility (test_bdb) - Use downcast_ref_if_exact for PyNativeFunction in CALL specialization guards - Add can_specialize_call guard for class __init__ specialization - Remove expectedFailure for test_bad_newobj_args (now passing)coderabbitai
Bot
mentioned this pull request Mar 22, 2026 marshal #7467 Merged youknowone added a commit that referenced this pull request Sep 16, 2026
Align specialization guards and caching with CPython (#7341)
05f3759
* vm: complete specialized opcode dispatch paths * vm: cache LOAD_GLOBAL with dict entry hints * vm: align adaptive specialization counters with CPython backoff * vm: apply cooldown counter on specialization success paths * vm: retain LOAD_GLOBAL specializations on misses * vm: keep attr and call specializations on guard misses * vm: retain store-attr and store-subscr specializations on misses * vm: retain specialization opcodes on generic fallback paths * vm: align jump-backward specialization defaults with CPython * vm: retain exact-args call specializations on misses * vm: retain SEND_GEN specialization on non-coroutine sends * vm: specialize list.append calls like CPython CALL_LIST_APPEND * vm: set cooldown on LOAD_ATTR_CLASS specialization * vm: specialize bound method object CALL paths * vm: specialize CALL_KW for bound method objects * vm: use current-state function version for CALL_KW specialization * vm: align CALL/CALL_KW pyfunction specialization with CPython * vm: drop call-site identity caches in generic CALL specializations * vm: align builtin type call specializations with CPython guards * vm: align builtin CALL guards with CPython self_or_null semantics * vm: require exact list in CALL_LIST_APPEND fast path * vm: align CALL builtin/class specialization flow with CPython * vm: tighten len/isinstance CALL specializations to builtin guards * vm: gate CALL_BUILTIN_CLASS on type vectorcall like CPython * vm: run non-py CALL specializations via direct vectorcall * vm: align class-call specialization branching with CPython * Fix CI: disable ForIterGen, tighten CALL guards - Disable ForIterGen specialization (falls through to generic path) because inline generator frame resumption is needed for correct debugger StopIteration visibility (test_bdb) - Use downcast_ref_if_exact for PyNativeFunction in CALL specialization guards - Add can_specialize_call guard for class __init__ specialization - Remove expectedFailure for test_bad_newobj_args (now passing)Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment