fix(codegen): invalidate Array.isArray folds on reassignment - #7855
Conversation
📝 WalkthroughWalkthrough
ChangesArray.isArray reassignment handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
crates/perry-codegen/src/expr/array_methods.rs (1)
97-99: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winMake the static-type analysis lazy.
bool::then_someevaluates its argument before the method runs. Therefore,crate::type_analysis::static_type_of(ctx, o)still runs for reassigned locals. Replace it withthen(|| ...)so reassigned locals skip this analysis.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/perry-codegen/src/expr/array_methods.rs` around lines 97 - 99, Update the conditional static-type lookup around static_type_is_still_valid to use lazy evaluation, replacing then_some with then so crate::type_analysis::static_type_of(ctx, o) runs only when the validity flag is true and is skipped for reassigned locals.Source: Coding guidelines
test-files/test_gap_7844_array_isarray_reassigned_local.ts (1)
1-2: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a loop reassignment regression case.
The test covers only straight-line assignments. Add one loop case to verify that
reassigned_localsinvalidates theArray.isArraystatic fold for loop writes. Run./scripts/run_gap_tests.shwith Node 26.5.1 from.node-version.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test-files/test_gap_7844_array_isarray_reassigned_local.ts` around lines 1 - 2, Extend the regression test around numberToArray with a loop that reassigns the local, verifying reassigned_locals prevents Array.isArray static folding for loop writes. Keep the existing straight-line assignment case, and run ./scripts/run_gap_tests.sh using the Node version specified in .node-version.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/perry-codegen/src/expr/array_methods.rs`:
- Around line 97-99: Update the conditional static-type lookup around
static_type_is_still_valid to use lazy evaluation, replacing then_some with then
so crate::type_analysis::static_type_of(ctx, o) runs only when the validity flag
is true and is skipped for reassigned locals.
In `@test-files/test_gap_7844_array_isarray_reassigned_local.ts`:
- Around line 1-2: Extend the regression test around numberToArray with a loop
that reassigns the local, verifying reassigned_locals prevents Array.isArray
static folding for loop writes. Keep the existing straight-line assignment case,
and run ./scripts/run_gap_tests.sh using the Node version specified in
.node-version.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 63d339df-704e-4ae7-bfa9-910811af4cf8
📒 Files selected for processing (4)
changelog.d/7855-array-isarray-reassignment.mdcrates/perry-codegen/src/expr/array_methods.rscrates/perry-codegen/tests/native_proof_regressions.rstest-files/test_gap_7844_array_isarray_reassigned_local.ts
Summary
Array.isArrayfrom folding a reassigned local from its initializer-refined typejs_array_is_array, so the predicate checks the current runtime valueCloses #7844
Reproduction
On
origin/main(079e646dd), the same six-case program produced stale answers in both directions:The second boolean is
instanceof Array, showing that the runtime value itself was correct. Node and the fixed compiler both produce:The A/B used two compilers against the same prebuilt runtime.
Validation
cargo test -p perry-codegen --lib: 877 passedjs_array_is_arraycalls for the two reassigned locals, while the unchanged-array control remains foldednative_proof_regressions: 262 passed with onlytyped_f64_receiver_method_clone_raw_loads_after_composed_guardsskipped (the current-main typed_f64_receiver_method_clone_raw_loads_after_composed_guards: the guard-failure edge no longer calls $generic — miscompile or intentional collapse? #7506 failure, fixed separately in fix(codegen): coerce declared-only addition results #7851)python3 scripts/check_test_registration.py: passedcargo fmt --all -- --check,git diff --check, andbash scripts/check_file_size.sh: passedSummary by CodeRabbit
Array.isArrayto correctly evaluate local values at runtime after reassignment.instanceof Array,null, primitives, and unchanged arrays.