Skip to content

Array literals given to optional parameters are released; own string literals given to calls; own rest-array fields; nested iterable patterns - #1039

Merged
ASDAlexander77 merged 2 commits into
mainfrom
own-gaps-1126
Nov 26, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
own-gaps-1126

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Fixes

new Set([...]) leaked its array literal (rc and own). DefaultLib's constructor(values?: V[]) takes the literal as ts.OptionalValue of it, and arrayMadeFor only followed casts, so the array was neither held (rc) nor owned (own). 2M rounds of new Set<string>(["a" + i]): 220 MB → 5 MB. arrayMadeFor now 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). holdsWhatItIsGiven skipped text elements without counting them, so g(["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. fieldOnlyRead now counts the borrowing rest array (and rc's retain for it, in fieldBorrowRetains) as a read of the field (OwnershipInferenceMoves.cpp).

Every model: const [[k, v]] = map was refused. An element read out of an iterable is T | undefined; the inner array pattern now reads T's value with ts.Value, as element access does (MLIRGenVariables.cpp).

Tests

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; plain g([["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

ASDAlexander77 and others added 2 commits November 26, 2026 17:08
…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>
@ASDAlexander77
ASDAlexander77 merged commit 4923d3a into main Nov 26, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-gaps-1126 branch November 26, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant