fix(codegen): coerce declared-only addition results - #7851
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe compiler extends declared-only numeric proof tracking to numeric locals and compound expressions. Residual coercion now preserves JavaScript semantics in typed-receiver fallbacks. Regression tests verify coercion and fallback ordering. ChangesDeclared-only numeric coercion
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant NumericLocal
participant operand_needs_residual_coerce
participant js_number_coerce
participant ReceiverFallback
NumericLocal->>operand_needs_residual_coerce: provide declared-only numeric expression
operand_needs_residual_coerce->>js_number_coerce: coerce residual numeric value
ReceiverFallback->>js_number_coerce: coerce dynamic addition result
js_number_coerce-->>ReceiverFallback: return numeric value for multiplication
Possibly related PRs
Suggested labels: 🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@crates/perry-codegen/tests/native_proof_regressions.rs`:
- Around line 11746-11751: Update the regression assertions around the cond_br
consuming js_typed_feedback_class_field_get_guard so the typed clone is required
only in the guard-success successor and explicitly rejected in the failure
successor. Replace the unconditional call-pattern check that currently accepts
any i64 receiver with successor-specific validation, ensuring $typed_f64_recv
cannot appear on the failed field-guard path while preserving the existing
coercion checks there.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 343d855e-de06-466e-91ec-4242610d1557
📒 Files selected for processing (6)
crates/perry-codegen/src/expr/binary.rscrates/perry-codegen/src/expr/mod.rscrates/perry-codegen/src/stmt/let_stmt.rscrates/perry-codegen/src/type_analysis/pod.rscrates/perry-codegen/tests/native_proof_regressions.rstest-files/test_gap_7506_pshape_add_result_coercion.ts
Summary
Fix the raw-f64 guard-failure path for typed receiver methods when a declared-number
+result feeds another arithmetic operator.After the field guard falls back to a
$pshapeclone,this.x + this.ycan correctly produce a boxed string when a runtime field violates its declared numeric type. Two paths then lost that fact:const sum = this.x + this.ywas not marked declared-only because the tracker only coveredAny -> Numberrefinements;(this.x + this.y) * scalewas excluded because residual coercion only consulted declared-only proof forLocalGet.This change propagates declared-only proof into every numeric local whose initializer carries it, and consults the same proof for every arithmetic operand. Proven raw-f64 tiers still answer false and remain coercion-free.
The existing clone-composition test now asserts the semantic order
dynamic + -> ToNumber -> multiplyand that the typed raw-f64 clone retains no dynamic add or number coercion. A parsed TypeScript parity regression covers both intermediate-local and direct-expression forms through the actual$pshapefallback.Reproduction
Both compiler arms linked generated programs against the same runtime:
Validation
cargo test -p perry-codegen --test native_proof_regressions -- --test-threads=1— 262 passedtyped_f64_receiver_method_clone_raw_loads_after_composed_guards— passedpython3 scripts/check_test_registration.py— passedcargo fmt --all -- --check— passedbash scripts/check_file_size.sh— passedcargo test -p perry-codegen— 877 library tests passed, then stopped at the documented pre-existinglarge_local_array_push_inbounds_store_emits_precise_slot_barrierfailureCloses #7506.
Summary by CodeRabbit
Bug Fixes
Tests