Repository navigation
Give a nested array literal's inner arrays heap storage of their own - #356
Merged
Merged
Conversation
`const nested = [[1, 2], [3]]; nested[1].push(4)` crashed in the allocator. The literal is a const_array<array<s32>>, and turning it into an array<array<s32>> copied only the outer data to the heap: the inner arrays kept pointing at the literal's constant data, so push reallocated a global and `nested[0][0] = 9` wrote one. castConstArrayToArray skipped the literal because the element types already matched. It now rebuilds a literal whose elements are arrays element by element even then, so each inner array is cast - and copied to the heap - in turn. 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.
Summary
const nested = [[1, 2], [3]]; nested[1].push(4)crashed inGC_realloc, andnested[0][0] = 9wrote into constant data.The literal is a
const_array<array<s32>>. Turning it into anarray<array<s32>>copied only the outer data to the heap, and the inner arrays kept pointing at the literal's constant globals.castConstArrayToArrayskipped the literal because the element types already matched.It now rebuilds a literal whose elements are arrays element by element even when the types match, so each inner array is cast, and copied to the heap, in turn. Deeper nesting recurses. Found while testing #354.
Verification
00nested_array_literal_mutation.ts(compile, jit, and the rc/none corpus). It covers const, let, three levels deep, a module-level literal, and a fresh literal per loop iteration. Onmainit crashes.🤖 Generated with Claude Code