fix(hir): #871 part 2 — Uint8Array.of(...) > 16 args (uuid sha1.js)#913
Merged
Conversation
Add an `"of"` arm to the `Uint8Array` static-method lowering at `crates/perry-hir/src/lower/expr_call.rs:1108-1120` that rewrites `Uint8Array.of(a, b, c, ...)` to `Expr::Uint8ArrayFrom(Expr::Array(args))`, exactly mirroring the existing `Array.of` arm at :1618-1621. Pre-fix the codegen bailed with `Call callee shape not supported (PropertyGet) with 20 args` for uuid's `sha1.js` (`Uint8Array.of(H[0]>>24, ..., H[4])` returning the 160-bit SHA-1 output) because the static dispatch tower didn't recognize `Uint8Array.of`, the generic method-dispatch path at `lower_call.rs:~3055` skipped the `Expr::GlobalGet(_)` receiver, and the closure-call fallback at `~3167` was gated by `args.len() <= 16` (no `js_closure_call17..20` exists). Even for ≤ 16 args the closure-call fallback threw `value is not a function` at runtime because the `Uint8Array.of` PropertyGet lowers to `0.0`. Both the > 16 codegen bail and the silent ≤ 16 TypeError-at-runtime are closed by the HIR rewrite — no codegen or runtime changes needed. Adds regression test `test-files/test_issue_871_propertyget_callee_20_args.ts` (`Uint8Array.of(1..20)` → `len: 20 first: 1 last: 20`, byte-identical to `node --experimental-strip-types`). Closes #871 (part 1 was closed by #890; part 2 closes here).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
"of"arm to theUint8Arraystatic-method lowering atcrates/perry-hir/src/lower/expr_call.rs:1108-1120that rewritesUint8Array.of(a, b, c, ...)→Expr::Uint8ArrayFrom(Expr::Array(args)), mirroring the existingArray.ofarm at :1618-1621.Call callee shape not supported (PropertyGet) with 20 argscodegen bail atcrates/perry-codegen/src/lower_call.rs::~3226that uuid'ssha1.jshit when returning its 160-bit SHA-1 output viaUint8Array.of(H[0]>>24, ..., H[4]). Also closes a silentvalue is not a functionruntime TypeError that was present forUint8Array.ofcalls with <= 16 args (the PropertyGet receiver lowers to0.0, so the closure-call fallback threw at runtime even when it did not bail at codegen).args.len() <= 16) and thejs_closure_call0..16family stay untouched;Uint8Array.of(...)now produces the same HIR shape thatUint8Array.from([...args])has produced since the originalUint8ArrayFromlowering landed.Part 1 of #871 (the HIR named-default-function gap) was closed by #890. This PR closes part 2 (the codegen gap that the v0.5.925 changelog entry called out as the remaining v4 runtime blocker).
Test plan
test-files/test_issue_871_propertyget_callee_20_args.ts(Uint8Array.of(1, 2, ..., 20)→ expectslen: 20 first: 1 last: 20). Byte-identical tonode --experimental-strip-types.Uint8Array.of(1, 2, 3)) — pre-fix runtime-TypeError-d; post-fix works./tmp/perry-uuidreproducer from the v0.5.925 entry):node_modules/uuid/dist/sha1.jsnow emits a full object file (no failed-modules stub fallback).Uint8Array.from([1,2,3])+Array.of(1,2,3)still work (no regression in adjacent static-method arms).cargo fmtclean.cargo build --release -p perryclean.Closes #871.