-
-
Notifications
You must be signed in to change notification settings - Fork 161
fix(runtime): resolve instanceof against a ClassExprFresh parent per evaluation #10640
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
40646a6
fix(runtime): resolve instanceof against a ClassExprFresh parent per …
b34da1c
changelog: add fragment for #10640
a9d2018
refactor(runtime): split instanceof.rs for the file-size cap
perry-bot 2fa7886
chore: update addr-class gates for the instanceof.rs split
perry-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ### Fixed | ||
|
|
||
| - `instanceof` against a `ClassExprFresh` parent (a heritage-carrying class | ||
| expression — captures, statics, private elements, or a self-binding) | ||
| resolved the dynamic parent by the SHARED template `class_id` rather than | ||
| per evaluation. An instance built from an EARLIER evaluation of a | ||
| repeatedly-evaluated factory, constructed after a LATER evaluation of the | ||
| same factory had run, constructed with the correct parent (a prior fix, | ||
| #9364/#6438, already gives each evaluation its own pinned heritage for | ||
| `super()`/capture resolution) but could fail `instanceof` against its own | ||
| true parent — the later evaluation's parent shadowed it in the shared, | ||
| last-write-wins `CLASS_REGISTRY` that `instanceof`'s class-chain walk read. | ||
| Fixed by pinning the constructing class object onto each new instance too | ||
| (`class_registry/evaluation_heritage.rs`) and giving `instanceof`'s chain | ||
| walk a value-aware path (`instanceof.rs`'s `class_chain_reaches_dynamic`) | ||
| that prefers a pinned VALUE at each hop over the shared class_id table, | ||
| gated behind a monotone latch so the common (never-evaluated-twice) case | ||
| is unaffected. Runtime-only; no codegen changes. (#10624) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 18935
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 10142
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50371
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 28240
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 32073
Root the instance and class value before creating the key.
js_string_from_bytesallocates throughstring_storage_alloc, which can trigger a moving collection. The collection rewrites the caller's handles, but the helper's rawinstpointer and copiedclassobj_valueremain stale. The setter roots and refreshes its own arguments only after it receives them.Root the key as a
StringHeaderpointer. Do not pass it throughroot_nanbox_f64.Proposed fix
pub(crate) fn pin_instance_constructing_class(inst: *mut ObjectHeader, classobj_value: f64) { if inst.is_null() || !is_class_object_value(classobj_value) { return; } - let class_ptr = crate::value::js_nanbox_get_pointer(classobj_value) as *const ObjectHeader; + let scope = crate::gc::RuntimeHandleScope::new(); + let inst_handle = scope.root_raw_mut_ptr(inst); + let classobj_handle = scope.root_nanbox_f64(classobj_value); + let class_ptr = + crate::value::js_nanbox_get_pointer(classobj_handle.get_nanbox_f64()) as *const ObjectHeader; if class_ptr.is_null() || class_object_pinned_parent(class_ptr).is_none() { return; } let key_bytes = INSTANCE_CONSTRUCTING_CLASS_KEY.as_bytes(); - let key = crate::string::js_string_from_bytes(key_bytes.as_ptr(), key_bytes.len() as u32); - crate::object::js_object_set_field_by_name(inst, key, classobj_value); + let key_handle = scope.root_string_ptr( + crate::string::js_string_from_bytes(key_bytes.as_ptr(), key_bytes.len() as u32), + ); + inst_handle.with_mut_ptr::<ObjectHeader, _>(|inst| { + crate::object::js_object_set_field_by_name( + inst, + key_handle.get_raw_const_ptr::<crate::StringHeader>(), + classobj_handle.get_nanbox_f64(), + ); + }); }🤖 Prompt for AI Agents