Repository navigation
fix(wasm): object patterns bind from their source (#14733) - #14741
Conversation
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Overlap note: #14664 (ours) carries the same This PR is the standalone fix for #14733 and doesn't depend on #14664. Whichever lands first, I'll drop the duplicate hunk from the other when I rebase it. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
55380a9 to
d97da07
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
d97da07 to
ba572a0
Compare
Every object pattern opens with the HIR intrinsic
`__perry_runtime.requireObjectCoercible(source, offset)`. The wasm
backend had no arm for it, so it fell through to the generic native-call
path, which drops the arguments and yields `undefined`: `const { k } = v`
and `for (const { k } of arr)` on `--target web` read `k` from
`undefined` and threw `Cannot read properties of undefined (reading 'k')`.
The wasm backend now emits the check as the `rt_requireObjectCoercible`
bridge, which returns the source or throws the TypeError native throws
for a nullish one.
Fixes PerryTS#14733
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
ba572a0 to
5ee4028
Compare
Summary
On
--target web, every object pattern read its properties fromundefined:const { k } = vandfor (const { k } of arr)threwCannot read properties of undefined (reading 'k'). The HIR opens each object pattern with the__perry_runtime.requireObjectCoercible(source, offset)intrinsic; the wasm backend had no arm for it, so it fell through to the generic native-call path, which skips the arguments and yieldsundefined. This adds the missing arm.Changes
crates/perry-codegen-wasm/src/emit/expr/iterator_records.rs:requireObjectCoercibleemits the newrt_requireObjectCoerciblebridge with the source only (the second operand is a byte offset for native--debug-symbols).crates/perry-codegen-wasm/src/wasm_runtime.js:rt_requireObjectCoerciblereturns its value, or throwsTypeError: Cannot convert undefined or null to object(native's message) fornull/undefined.crates/perry-codegen-wasm/src/emit/tests.rs:object_patterns_bind_from_their_source_and_reject_nullishcovers the for-of head, a nested declaration pattern, a source evaluated once, and a catchable TypeError fornull/undefined.Related issue
Fixes #14733
Test plan
Cause, verified before the fix (
main64257c3, the wasm harnessrun_web_source):--target webfor (const x of arr) console.log("k", x.k)(no pattern)k 1/k 2for (const [a, b] of arr)(array pattern)const { k } = v(declaration, no for-of)TypeError ... (reading 'k')for (const { k } of arr)TypeError ... (reading 'k')So the failure follows the object pattern, not
for...of; the HIR of the failing programs carriesrequireObjectCoercible, which no wasm emit arm matches.cargo test -p perry-codegen-wasm --lib object_patterns_bind: passes; with only the two source files reverted (test kept) it fails withTypeError: Cannot read properties of undefined (reading 'k').cargo test --lib --bins -p perry-codegen-wasmandcargo test --bins -p perry(what./scripts/test_affected_crates.sh --base upstream/main --dry-runlists):perry-codegen-wasm77 passed (the new test plus 76 existing).perry --binsfails 4 tests (static_require_transform,generated_native_namespaces,library_search,macos_bundle), the same 4 by name as on a pristinemaincheckout.cargo build-perry --release && scripts/gc_call_effects/sidecars.sh target/release,npm ci,scripts/build_instr_runtime.sh, then A/B against a pristinemainbuild:python3 scripts/parity.py run <subject> --mode webforlanguage/array,language/destructuring,language/function,language/iterator: 0 cases pass onmainand fail here. Newly passing:language/destructuring/test_edge_destructuring,test_issue_554_nested_destructure_for_of,test_issue_express_value_not_fn(destructuring web: 7 failing on main, 4 here). Twolanguage/arraycases (test_array_reps_loop_base_gc,test_gap_array_fill_3m_objects) also flipped, but they were run-timeouts (exit 124) on the loadedmainarm, so I don't count them.bash tests/integration/wasm/run_wasm_tests.sh: 30 passed, 3 failed on both sides (04_functions,10_higher_order,19_ffi_imports, the same three as onmain).rustfmt --checkclean on the touched files;cargo clippy -p perry-codegen-wasm --all-targets: 282 warnings on both sides, none on a touched line.BASE_SHA=upstream/main scripts/run_lint_gates.sh: the FAIL set (24 gates) is identical to a pristinemaincheckout's. The changelog fragment is added with the PR number.Checklist
feat:/fix:/docs:/chore:prefix convention used in the log🤖 Generated with Claude Code
https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
Summary by CodeRabbit
TypeErrorfornullorundefined.