The arrays of a tuple literal built at run time can be changed (#486) - #491
Merged
Merged
Conversation
Two shapes failed to compile: - A constant array in a tuple that has a run-time value (`let t = [x, [1]]`) kept its constant-array type, so `t[1].push(2)` was "Can't resolve property 'push'". createTupleFromArrayLiteral now makes it an array of its own, a heap copy, as it already did for a constant tuple holding an array (#484). - A `const` of a tuple built at run time (`const nt = [x, [2, [3, 4]]]`) was folded into the CreateTuple value, so `nt[1][1].push(5)` had no reference to change the array through ("Can't get reference of the array"), and nothing counted the arrays in it. Such a const now has storage when the tuple owns a block, as a `let` has and as a record literal's const has since #485. Under own, `const r = [i, [i, i]]; r[1].push(5)` now gives the error the `let` form already gave ("'this value' takes a second reference") instead of "Can't get reference of the array". Closes #486 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.
Two shapes of a tuple literal built at run time did not compile:
let t = [x, [1]]; t[1].push(2)): the element kept its constant-array type, sopushdid not resolve.createTupleFromArrayLiteralnow makes it an array of its own (a heap copy), as Arrays in an inferred tuple or record literal are heap copies (#479) #484 already did for a constant tuple holding an array.constof it (const nt = [x, [2, [3, 4]]]; nt[1][1].push(5)): the const was folded into theCreateTuplevalue, so there was no reference to change the array through ("Can't get reference of the array"), and under rc nothing counted the arrays in it. Such a const now has storage when the tuple owns a block, as alethas and as a record literal's const has since rc/own: a record literal with a run-time field leaks the array in its fields #485.Under own,
const r = [i, [i, i]]; r[1].push(5)now gives the error theletform already gave ("'this value' takes a second reference") instead of "Can't get reference of the array".New test
00tuple_runtime_arrays.ts(does not compile onmain):let+ push,const+ pop, nestedconst+ push, string-and-array tuple, a tuple passed to a[number, number[]]parameter, and a fresh array per loop pass.weakref_basicis gc-only, as onmain)--opt, same asmain)let,const, nested, run-time values: flat at 4.4 MBCloses #486
🤖 Generated with Claude Code