-
-
Notifications
You must be signed in to change notification settings - Fork 158
Fix remaining Array Test262 clusters #8858
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 all commits
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 |
|---|---|---|
|
|
@@ -457,6 +457,22 @@ pub(crate) fn lower_ident_assignment( | |
| throw_type_error_const_assignment(&name), | ||
| ])); | ||
| } | ||
| // A JavaScript `var` inferred from an array literal can later hold an | ||
| // ordinary object. Lowering is source-ordered, so revoke the local's | ||
| // Array specialization as soon as a certainly non-array object is | ||
| // assigned; subsequent `x.unshift(...)` / indexed reads must use | ||
| // dynamic dispatch rather than ArrayHeader intrinsics. The module-wide | ||
| // type-widening pass mirrors this decision onto the already-emitted | ||
| // `Stmt::Let` declaration for codegen. | ||
| let invalidate_array_type = matches!( | ||
| ctx.lookup_local_type(&name), | ||
| Some(Type::Array(_)) | Some(Type::Tuple(_)) | ||
| ) && assignment_is_certainly_non_array_object(&value); | ||
| if invalidate_array_type { | ||
| if let Some(ty) = ctx.locals.lookup_type_mut(&name) { | ||
| *ty = Type::Any; | ||
| } | ||
| } | ||
| let local_set = Expr::LocalSet(id, value); | ||
| let mirrors_script_var = super::lower_expr::global_script_this_enabled() | ||
| && ctx.script_var_decl_names.contains(&name) | ||
|
|
@@ -540,6 +556,19 @@ pub(crate) fn lower_ident_assignment( | |
| } | ||
| } | ||
|
|
||
| fn assignment_is_certainly_non_array_object(value: &Expr) -> bool { | ||
| matches!( | ||
| value, | ||
| Expr::This | ||
| | Expr::Object(_) | ||
| | Expr::ObjectSpread { .. } | ||
| | Expr::ObjectAssign { .. } | ||
| | Expr::Closure { .. } | ||
| | Expr::Null | ||
| | Expr::Undefined | ||
| ) || matches!(value, Expr::New { class_name, .. } if class_name != "Array") | ||
| } | ||
|
Comment on lines
+559
to
+570
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: printf '%s\n' '--- repository guidance ---'
head -5 /tmp/coderabbit-repo-knowledge/perryts-perry-d4a878bc/*/*.md 2>/dev/null
printf '%s\n' '--- target definitions ---'
sed -n '520,590p' crates/perry-hir/src/lower/expr_assign.rs
sed -n '1,105p' crates/perry-hir/src/lower/type_widening.rs
printf '%s\n' '--- Expr variants and relevant lowering uses ---'
rg -n -A4 -B4 'enum Expr|FuncRef|ClassRef|assignment_is_certainly_non_array_object|rhs_certainly_non_array_object|ArrayUnshift|unshift' crates/perry-hir/srcRepository: PerryTS/perry Length of output: 50370 🏁 Script executed: printf '%s\n' '--- available repository guidance and learnings ---'
find /tmp/coderabbit-repo-knowledge/perryts-perry-d4a878bc -type f -maxdepth 3 -print
printf '%s\n' '--- target classifier and assignment flow ---'
sed -n '430,485p' crates/perry-hir/src/lower/expr_assign.rs
sed -n '559,575p' crates/perry-hir/src/lower/expr_assign.rs
printf '%s\n' '--- type-widening classifier and consumers ---'
sed -n '1,95p' crates/perry-hir/src/lower/type_widening.rs
printf '%s\n' '--- exact Expr declaration ---'
rg -n -A8 -B3 'pub enum Expr|enum Expr' crates/perry-hir/src
printf '%s\n' '--- array specialization flow ---'
rg -n -A12 -B12 'ArrayUnshift|array_id|Type::Array|Type::Tuple' crates/perry-hir/src/lower/expr_assign.rs crates/perry-hir/src/lower/type_widening.rs crates/perry-hir/src/lowerRepository: PerryTS/perry Length of output: 50370 🏁 Script executed: printf '%s\n' '--- applicable repository conventions ---'
cat /tmp/coderabbit-repo-knowledge/perryts-perry-d4a878bc/conventions/claude-md.md
printf '%s\n' '--- applicable HIR learnings ---'
cat /tmp/coderabbit-repo-knowledge/perryts-perry-d4a878bc/learnings/crates-perry-hir-src.md
printf '%s\n' '--- Expr reference variants ---'
sed -n '80,145p' crates/perry-hir/src/ir/expr.rs
printf '%s\n' '--- complete type-widening traversal and application ---'
sed -n '80,215p' crates/perry-hir/src/lower/type_widening.rs
printf '%s\n' '--- array method lowering ---'
rg -n -B18 -A35 'unshift|ArrayUnshift' crates/perry-hir/src/lower/expr_member.rs crates/perry-hir/src/lowerRepository: PerryTS/perry Length of output: 50369 🏁 Script executed: printf '%s\n' '--- local array method decision and unshift emission ---'
sed -n '180,315p' crates/perry-hir/src/lower/expr_call/local_array_methods.rs
sed -n '315,455p' crates/perry-hir/src/lower/expr_call/local_array_methods.rs
printf '%s\n' '--- identifier lowering to function/class references ---'
rg -n -B15 -A25 'lookup_func|lookup_class|Expr::FuncRef|Expr::ClassRef' crates/perry-hir/src/lower/expr*.rs crates/perry-hir/src/lower/lower_expr.rs crates/perry-hir/src/lower
printf '%s\n' '--- array classifier tests and nearby lowering tests ---'
rg -n -B8 -A25 'array_inference|FuncRef|ClassRef|ArrayUnshift|unshift' crates/perry-hir/src/lower/*test* crates/perry-hir/src/lower/**/*.rsRepository: PerryTS/perry Length of output: 50370 🏁 Script executed: printf '%s\n' '--- local array method lowering, focused ---'
sed -n '180,285p' crates/perry-hir/src/lower/expr_call/local_array_methods.rs
sed -n '360,450p' crates/perry-hir/src/lower/expr_call/local_array_methods.rs
printf '%s\n' '--- lower_expr files ---'
fd -t f 'lower_expr|expr.rs' crates/perry-hir/src/lower crates/perry-hir/src
printf '%s\n' '--- direct identifier lowering references ---'
rg -n -m30 -B8 -A12 'ast::Expr::Ident|Expr::FuncRef\(func_id\)|Expr::ClassRef\(class_name\)' crates/perry-hir/src/lower/lower_expr crates/perry-hir/src/lower/expr*.rs crates/perry-hir/src/lower_declRepository: PerryTS/perry Length of output: 50370 🏁 Script executed: printf '%s\n' '--- identifier lowering in lower_expr.rs ---'
rg -n -B12 -A28 'Ident\(ident\)|lookup_local\(|lookup_func\(|lookup_class\(' crates/perry-hir/src/lower/lower_expr.rs
printf '%s\n' '--- local array method setup and type source ---'
sed -n '120,205p' crates/perry-hir/src/lower/expr_call/local_array_methods.rs
printf '%s\n' '--- reference variants in Expr ---'
rg -n -B5 -A8 'FuncRef|ClassRef|Closure' crates/perry-hir/src/ir/expr.rs
printf '%s\n' '--- function declaration binding forms ---'
sed -n '530,575p' crates/perry-hir/src/lower_decl/body_stmt.rs
sed -n '1,115p' crates/perry-hir/src/lower_decl/body_stmt/nested_fn_decl.rsRepository: PerryTS/perry Length of output: 19237 🏁 Script executed: printf '%s\n' '--- lower_ident_expr implementation ---'
rg -n 'fn lower_ident_expr' crates/perry-hir/src
sed -n '1,220p' crates/perry-hir/src/lower/lower_expr/ident.rs 2>/dev/null
sed -n '1,220p' crates/perry-hir/src/lower/lower_expr.rs
printf '%s\n' '--- local array method function signature and type_info initialization ---'
sed -n '1,185p' crates/perry-hir/src/lower/expr_call/local_array_methods.rs
printf '%s\n' '--- type-widening invocation ---'
rg -n -B8 -A12 'TypeWidening|type_widening|widen' crates/perry-hir/src/lower crates/perry-hir/src/lib.rsRepository: PerryTS/perry Length of output: 50370 🏁 Script executed: printf '%s\n' '--- exact identifier resolution ---'
sed -n '1,180p' crates/perry-hir/src/lower/lower_expr/arm_ident.rs
printf '%s\n' '--- array fast-path gate and local-id extraction ---'
sed -n '275,370p' crates/perry-hir/src/lower/expr_call/local_array_methods.rs
printf '%s\n' '--- type inference for references and locals ---'
rg -n -B6 -A18 'Expr::LocalGet|Expr::FuncRef|Expr::ClassRef' crates/perry-hir/src/analysis/value_types.rsRepository: PerryTS/perry Length of output: 18478 🏁 Script executed: printf '%s\n' '--- ArrayUnshift codegen contract ---'
rg -n -B12 -A24 'Expr::ArrayUnshift|ArrayUnshift' crates/perry-codegen/src crates/perry-runtime/src
printf '%s\n' '--- top-level function/class registration relevant to first-class references ---'
rg -n -B8 -A18 'register_func|register_class|lower_fn_decl|Decl::Fn|Decl::Class' crates/perry-hir/src/lower/lower_module_fn.rs crates/perry-hir/src/lower_decl crates/perry-hir/src/lowerRepository: PerryTS/perry Length of output: 50370 🏁 Script executed: printf '%s\n' '--- files containing the ArrayUnshift codegen arm ---'
rg -l 'ArrayUnshift' crates/perry-codegen/src crates/perry-runtime/src
printf '%s\n' '--- focused ArrayUnshift implementation ---'
for f in $(rg -l 'ArrayUnshift' crates/perry-codegen/src crates/perry-runtime/src); do
echo "### $f"
rg -n -B8 -A18 'ArrayUnshift' "$f"
doneRepository: PerryTS/perry Length of output: 18635 Invalidate Array inference for named functions and classes.
Add 📍 Affects 2 files
🤖 Prompt for AI Agents |
||
|
|
||
| fn lower_assignment_target( | ||
| ctx: &mut LoweringContext, | ||
| target: &ast::AssignTarget, | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Infer the flattened element type for
flat.flatremoves one array nesting level. ForArray<Array<number>>, this branch infersArray<Array<number>>, but the runtime returnsArray<number>. Useflattened_array_element_type(array_element_type_from_expr(receiver, env)).🤖 Prompt for AI Agents