Repository navigation
a[i] = v past the end of an array grows it to i + 1, as in JavaScript - #979
Merged
Merged
Conversation
`a[a.length] = v` and `s[i] = ...` in a loop over an empty array left the length as it was and wrote past the end of the block: under gc into whatever lay there, under rc and own a crash (TSLANG 152). The element store, which takes the element's address anew after the right side ran, now grows the array first when the index is at or past the length (mlirGenGrowArrayForWrite: SetLengthOf, which zeroes the slots in between - a hole reads as the element type's default). A negative index grows nothing; an array with no place to update (made for the statement) is left as it was. Test 00array_write_grows.ts (compile, JIT, rc, own). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rown slot as a keep); TSLANG 152 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SetLengthOf lowers to a capacity check, a reallocation and the zeroing of the new slots; made at every element write, the sweep's largeControlFlowGraph (10000 `data[0] = 0`) took 71 s instead of 5 s, all of it lowering to LLVM. The length check stays at the write; the growth is a call of `.array_grow.<type>(array, length)`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…growth not there yet, TSLANG 152) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
a[i] = vwithiat or past the end of an array now grows it toi + 1, as in JavaScript (a[a.length] = vappends). The slots in between read as the element type's default.Before this change, the length stayed the same and the write went past the end of the block. Under gc it landed in whatever memory was there; under rc and own it crashed.
.array_grow.<type>function, which runsSetLengthOf. That function is shared by all writes to arrays of the same type, so the inline code stays small: inlining the growth at every write tooklargeControlFlowGraphfrom 5 s to 71 s.-mm=ownthe ownership passes read the grown slot as a keep, so own keeps the old behaviour for now; this is tracked in TSLANG 152.00array_write_grows.ts(compile, jit, jit rc).Verified: ctest 8788/0 after rebasing onto #977 and #978. Before the rebase: the wasm32 rc and none tester suites were clean, and the full tsc sweep was identical to the baseline (3256 pass).
🤖 Generated with Claude Code