-
-
Notifications
You must be signed in to change notification settings - Fork 162
runtime: a real elements store for class X extends Array (−12% on the wolf-ecs twins, gated off) #8966
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
runtime: a real elements store for class X extends Array (−12% on the wolf-ecs twins, gated off) #8966
Changes from all commits
f875582
ab7447d
7b5d9c9
e622862
a68bd40
6acf82d
d055c2c
66816ac
4f2a825
c96362c
a44fade
35e21b1
a41a67b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,6 +264,44 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result<String> { | |
| .filter(|class| class.extends_expr.is_none() && !class.heritage_lexically_shadowed) | ||
| .and_then(|class| class.extends_name.clone()) | ||
| .filter(|parent| !ctx.classes.contains_key(parent.as_str())); | ||
| // `class X extends Array { constructor(...a) { super(...a) } }`: | ||
| // the Array parent has no registered constructor, so the spread | ||
| // form must run the same subclass init the direct `super(n)` | ||
| // form does (`lower_array_super_init`), handing it the | ||
| // materialized argument array's elements. Without this the | ||
| // instance had no `length` and no Array surface at all. | ||
| // Resolved the way the direct `super(n)` arm resolves its parent | ||
| // (`extends_name`, a lexically shadowed heritage excluded): the | ||
| // heritage of `class X extends Array` also carries `extends_expr`, | ||
| // which the `async_parent` filter above rejects. | ||
| let array_parent = ctx | ||
| .classes | ||
| .get(¤t_class_name) | ||
| .filter(|class| !class.heritage_lexically_shadowed) | ||
| .and_then(|class| class.extends_name.as_deref()) | ||
| .is_some_and(|parent| parent == "Array" && !ctx.classes.contains_key("Array")); | ||
| if array_parent { | ||
| let len_i32 = ctx.block().call(I32, "js_array_length", &[(I64, &arr)]); | ||
| let len = ctx.block().zext(I32, &len_i32, I64); | ||
| let elems_addr = ctx.block().add(I64, &arr, "8"); | ||
| let elems_ptr = ctx.block().inttoptr(I64, &elems_addr); | ||
| let result = ctx.block().call( | ||
| DOUBLE, | ||
| "js_array_subclass_init_args", | ||
| &[ | ||
| (DOUBLE, &this_box), | ||
| (crate::types::PTR, &elems_ptr), | ||
| (I64, &len), | ||
| ], | ||
| ); | ||
| bind_derived_this_after_super(ctx); | ||
| crate::lower_call::apply_field_initializers_recursive( | ||
| ctx, | ||
| ¤t_class_name, | ||
| crate::lower_call::FieldInitMode::SelfOnly, | ||
| )?; | ||
| return Ok(result); | ||
|
Comment on lines
+297
to
+303
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. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Reload the receiver after field initialization.
As per coding guidelines: “A GC-managed value's root store must dominate every subsequent site that can collect.” 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| } | ||
| if matches!( | ||
| async_parent.as_deref(), | ||
| Some("EventEmitterAsyncResource" | "AsyncLocalStorage" | "AsyncResource") | ||
|
|
||
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
Restrict the elements probe to
GC_TYPE_OBJECT.Lines 458-460 send every non-Array receiver into the
ObjectMetaprobe. ABigInt64ArrayorBigUint64Arrayfirst misses the typed-array tier becausekind > 8, then reaches this branch. Lines 462-481 can interpret its typed-array payload as a nonzeroObjectMetapointer and dereference it. This can crash instead of usingjs_packed_arraylike_index_get.Branch to
object_miss_labelunlessgc_type == GC_TYPE_OBJECTbefore loadingelem_meta_i64.🤖 Prompt for AI Agents