fix(array): honor fromIndex/start/end/depth in indexOf/fill/flat/copyWithin - #3452
Merged
Merged
Conversation
…Within #2804: thread the optional fromIndex through Array/TypedArray indexOf and includes (runtime helpers + static codegen + dynamic dispatch). #2801: honor start/end in dynamic Array.prototype.fill dispatch. #2800: honor depth in dynamic Array.prototype.flat dispatch. #2802: add dynamic Array.prototype.copyWithin dispatch. Also fixes a pre-existing duplicate stable-hash tag (12045) shared by RegExpEscape and ReflectIsExtensible that broke cargo test -p perry-hir.
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.
Closes #2804
Closes #2801
Closes #2800
Closes #2802
Implementation
All four issues were optional-argument gaps where the runtime/dynamic-dispatch
path ignored a trailing argument the static codegen path already understood.
#2804 — indexOf / includes
fromIndex(Array + TypedArray).js_array_indexOf_jsvalueandjs_array_includes_jsvaluenow take(value, from_index, has_from)and apply ECMA-262 ToIntegerOrInfinity +clamping (new shared
forward_start_indexhelper): omitted → 0, positive →that index, negative →
max(len + n, 0),NaN→ 0,+Infinity→ not-found.Works for both Array and TypedArray receivers. The optional
from_indexwasthreaded through the existing
Expr::ArrayIndexOf/Expr::ArrayIncludesHIRvariants by adding a field (mirroring the existing
Expr::ArrayLastIndexOf) — no new HIR variant was added, so stable-hashtags 254/255 are unchanged. Static codegen (
lower_array_method,misc_methods,instance_misc1), all HIR lowering construction sites, and the dynamicnative_call_methoddispatch arms now pass the fromIndex.#2801 — fill(value, start, end) dynamic dispatch. The
"fill"arm innative_call_methodnow routes 2+ args tojs_array_fill_range(defaultend = +Infinity→ clamps to length, matching the static path) instead ofalways whole-array
js_array_fill.#2800 — flat(depth) dynamic dispatch. The
"flat"arm now routes asupplied depth to
js_array_flat_depth(NaN/≤0 → 0, +Infinity → fully flat),falling back to legacy
js_array_flatonly when depth is omitted.#2802 — copyWithin dynamic dispatch. Added a
"copyWithin"arm mirroringthe static path: require
target, defaultstartto 0, passhas_end = 0when
endis omitted, mutate and return the receiver viajs_array_copy_within.Drive-by: fixed a pre-existing duplicate stable-hash tag
12045shared byRegExpEscapeandReflectIsExtensible(introduced by parallel-merged PRs onmain) that was failing
cargo test -p perry-hir(
expr_variant_stable_hash_tags_are_unique). ReassignedReflectIsExtensibleto the next free tag12048.Validation
Gap test
test-files/test_gap_array_optargs_2804_2801_2800_2802.tsexerciseseach method via both direct calls and dynamic dispatch (computed method
name /
as anyreceiver), covering positive/negative/NaN/Infinity fromIndex,negative fill ranges, flat depth incl. Infinity, and copyWithin overlap.
Under the DEFAULT auto-optimize compile the output is byte-identical to
node --experimental-strip-types:./scripts/check_file_size.sh→ OK (no file over 2000 lines)cargo fmt --all -- --check→ cleancargo test --release -p perry-runtime array→ 101 passedcargo test --release -p perry-hir→ all pass (incl. stable-hash uniqueness)cargo build --release(cold) → green