Skip to content

-mm=own: tuple literals given to calls are given back; a rest element of an iterable - #1040

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-tuples-1126
Nov 26, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-tuples-1126

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Closes the two items left open by #1039.

-mm=own: tuple literals given to calls leaked (a gap since before pre-alpha134). A tuple literal is built in place: a temporary ts.Variable, filled field by field, then read whole. The inference moved the new string into that local, which nothing releases.

  • h(["a" + i, 1]): a field store of such a literal whose tuple is only read into what borrows it (a call that keeps none of it, an array a call borrows) is now a borrow (isBorrowedTupleLiteralField, OwnershipInferenceMoves.cpp), as a ts.CreateTuple given to such calls already was.
  • g([["a" + i, 1]]), new Map([["a" + i, 1]]), new Map([["a", 1]]): the array literal looked as if it borrowed its tuples and was given back by nothing. A tuple literal whose fields hold new values or string constants is now a new value moved into the array (isInPlaceTupleLiteral, OwnedReturnConsumptionPass.cpp; also the ts.CreateTuple of constants), as a nested array literal is.
  • Object literals (tuples with named fields) are records of their own (classifyRecords) and are left out of both.

2M rounds, peak working set (own):

before after
h(["a" + i, 1]) 47 MB 5 MB
g([["a" + i, 1]]) 51 MB 5 MB
new Map([["a" + i, 1]]) 173 MB 5 MB
new Map([["a", 1]]) 105 MB 5 MB

const [first, ...rest] = it of an iterable (m.entries(), a Set, a generator) was refused in every model ("spread is not implemented for type"). The rest is now an array of what the iterator gives from there on, made as [...iterator] is (MLIRGenVariables.cpp).

Still refused (pre-existing): a tuple literal given to a callee that keeps it (k.keepOne(["a" + i, i])).

Tests: 00own_tuple_literal_arguments.ts, 00array_pattern_rest_of_iterator.ts (jit/compile, none/rc/own). ctest 9865/9865 locally; DefaultLib tests.ps1 -Model own release compile+jit all pass with this compiler.

🤖 Generated with Claude Code

… of an iterable

Tuple literals under -mm=own (a gap since before pre-alpha134):
- `h(["a" + i, 1])`: the new string was moved into the literal's in-place local, which nothing
  releases; each call leaked it (2M calls: 47 MB -> 5 MB). A field of such a literal, read whole
  only into what borrows it (a call that keeps none of it, an array a call borrows), is now a
  borrow (isBorrowedTupleLiteralField), as a ts.CreateTuple given to such calls already was.
- `g([["a" + i, 1]])` and `new Map([["a" + i, 1]])` (the array through ts.OptionalValue): the array
  of tuples looked as if it borrowed them, and was given back by nothing (51 MB / 173 MB -> 5 MB;
  `new Map([["a", 1]])` 105 MB -> 5 MB). A tuple literal whose fields hold new values or string
  constants is now a new value moved into the array (isInPlaceTupleLiteral), as a nested array
  literal is, so the array owns it and goes with it. Object literals (named fields) are records
  of their own and are left out of both.

`const [first, ...rest] = it` of an iterable (`m.entries()`, a Set, a generator) was refused
("spread is not implemented"): the rest is an array of what the iterator gives from there on, made
as `[...iterator]` is.

Still refused: a tuple literal given to a callee that keeps it (`k.keep(["a" + i, 1])`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit c5c4436 into main Nov 26, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-tuples-1126 branch November 26, 2026 18:40
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