Repository navigation
Array literals given to optional parameters are released; own string literals given to calls; own rest-array fields; nested iterable patterns - #1039
Merged
Conversation
…literals given to calls; own rest-array fields; nested iterable patterns - rc and own: a new array given to an optional parameter (`new Set([a, b])` of DefaultLib's `constructor(values?: V[])`) reaches the call as `ts.OptionalValue` of it, and nothing gave it back: every call leaked the literal (2M rounds: 220 MB). arrayMadeFor follows the optional, and the array inside it is held (rc) or owned (own). - own: a literal of strings alone given to a call (`g(["a" + i])`) was owned by nothing and given back by nothing since #1006 (143 MB over 2M calls; 5 MB in pre-alpha134). The text a literal holds a copy of counts as its own again, unless it also holds a value it would take over. - own: a field of a record returned by a call passed straight to a rest parameter (`console.log(mk().value)`, `const v = mk().value; console.log(v)`, `next().value`, a Set pattern) was refused ("a value takes a second reference"): the borrowing rest array is a read of the field. - every model: a nested array pattern of an iterable (`const [[k, v]] = map`) was refused; the element read out of an iterable is `T | undefined`, and the inner pattern now reads T's value. Tests: 00own_rest_argument_field.ts, 00nested_iterable_array_pattern.ts, optional-array-argument (IR read under rc and own; fails on main). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd Node, compare the output The tsc sweep only checks that a test compiles. This runs each passing single-file sweep test (or a corpus folder) under tslang and under Node (transpiled by `tsc --noCheck`), and groups the results: match, stdout differs, tslang throws, crashes, times out, refuses the file. 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.
Fixes
new Set([...])leaked its array literal (rc and own). DefaultLib'sconstructor(values?: V[])takes the literal asts.OptionalValueof it, andarrayMadeForonly followed casts, so the array was neither held (rc) nor owned (own). 2M rounds ofnew Set<string>(["a" + i]): 220 MB → 5 MB.arrayMadeFornow follows the optional, and the array inside it is held/owned (OwnedReturnConsumptionPass.cpp).-mm=own: a literal of strings alone given to a call leaked (regression since #1006).holdsWhatItIsGivenskipped text elements without counting them, sog(["a" + i])was owned by nothing: 143 MB over 2M calls, against 5 MB in pre-alpha134. Text the literal holds a copy of counts as its own again, unless the literal also holds a value something else had (which it would take over).-mm=own: a field of a call's record passed straight to a rest parameter was refused (console.log(mk().value),const v = mk().value; console.log(v)in a function,it.next().value,const [a] = set; console.log(a): "a value takes a second reference"). Pre-existing at d152212.fieldOnlyReadnow counts the borrowing rest array (and rc's retain for it, infieldBorrowRetains) as a read of the field (OwnershipInferenceMoves.cpp).Every model:
const [[k, v]] = mapwas refused. An element read out of an iterable isT | undefined; the inner array pattern now reads T's value withts.Value, as element access does (MLIRGenVariables.cpp).Tests
00own_rest_argument_field.ts,00nested_iterable_array_pattern.ts(gc/rc/own, JIT and compile)optional-array-argument.cmake: reads the IR under rc and own (each array inreadsreleased once; rc also retained once). Fails on main, passes here. Plus compile/JIT runs in all four models.tests/collection_literal_arguments.ts, Set/Map/console.log); merge after this one.ctest Release, Windows: 9855/9855 passed. Leak probes (2M rounds, peak working set) flat at ~5 MB under own and rc for: Set of strings/numbers, string/number arrays to optional and plain parameters, rest-array field reads, Map under rc, nested patterns.
Not in this PR
-mm=own: an array of tuple literals given to a call still leaks (new Map([["a" + i, 1]]): 173 MB; plaing([["a" + i, 1]]): 51 MB). Same in pre-alpha134, so not a regression.const [e1, ...rest] = m.entries()(rest element over an iterator) is still refused.Also adds
scripts/tsc_differential.py: runs the passing single-file tsc sweep tests (or a corpus folder) under tslang JIT and under Node (tsc --noCheck), and groups match / stdout differs / tslang throws / crash / timeout.🤖 Generated with Claude Code