-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implement LOAD_ATTR inline caching with adaptive specialization #7292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
023bbd4
ff073c8
0fa6fa7
5f23161
a831e4f
79ca9c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Add bounds checks to read_cache_u16/u32/u64 - Fix quicken() aliasing UB by using &mut directly - Add JumpBackwardJit/JumpBackwardNoJit to deoptimize() - Guard can_specialize_call with NEWLOCALS flag check - Use compare_exchange_weak for version tag to prevent wraparound - Propagate dict lookup errors in LoadAttrMethodWithValues - Apply adaptive backoff on version tag assignment failure - Remove duplicate imports in frame.rs
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -201,12 +201,19 @@ fn is_subtype_with_mro(a_mro: &[PyTypeRef], a: &Py<PyType>, b: &Py<PyType>) -> b | |||||||||||||||||||||||||||||||||||||||||
| impl PyType { | ||||||||||||||||||||||||||||||||||||||||||
| /// Assign a fresh version tag. Returns 0 on overflow (all caches invalidated). | ||||||||||||||||||||||||||||||||||||||||||
| pub fn assign_version_tag(&self) -> u32 { | ||||||||||||||||||||||||||||||||||||||||||
| let v = NEXT_TYPE_VERSION.fetch_add(1, Ordering::Relaxed); | ||||||||||||||||||||||||||||||||||||||||||
| if v == 0 { | ||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||
| loop { | ||||||||||||||||||||||||||||||||||||||||||
| let current = NEXT_TYPE_VERSION.load(Ordering::Relaxed); | ||||||||||||||||||||||||||||||||||||||||||
| let Some(next) = current.checked_add(1) else { | ||||||||||||||||||||||||||||||||||||||||||
| return 0; // Overflow: version space exhausted | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| if NEXT_TYPE_VERSION | ||||||||||||||||||||||||||||||||||||||||||
| .compare_exchange_weak(current, next, Ordering::Relaxed, Ordering::Relaxed) | ||||||||||||||||||||||||||||||||||||||||||
| .is_ok() | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| self.tp_version_tag.store(current, Ordering::Release); | ||||||||||||||||||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| self.tp_version_tag.store(v, Ordering::Release); | ||||||||||||||||||||||||||||||||||||||||||
| v | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+202
to
+217
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Version-tag overflow can reintroduce stale tag matches. After counter wraparound, non-zero tags can be reused. Returning 🛠️ Proposed fix pub fn assign_version_tag(&self) -> u32 {
let v = NEXT_TYPE_VERSION.fetch_add(1, Ordering::Relaxed);
- if v == 0 {
+ if v == 0 || v == u32::MAX {
+ NEXT_TYPE_VERSION.store(0, Ordering::Relaxed);
+ self.tp_version_tag.store(0, Ordering::Release);
return 0;
}
self.tp_version_tag.store(v, Ordering::Release);
v
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /// Invalidate this type's version tag and cascade to all subclasses. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.