Skip to content

-mm=own: an object literal capturing a let or a parameter borrows it (spec 69) - #740

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-literal-let-param-captures
Oct 29, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-literal-let-param-captures

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Fixes the two -mm=own gaps left after spec 68. Both are now spec 69.

let d = new Item(4);
apply({ w: (x) => x + d.n }); // was: 'this value' is captured by a closure that escapes
d.n;

function viaParam(item: Item) {
    return applyO({ w: (x) => x + item.n }); // was: ... its value is the caller's
}

Changes

  • followClosure: a typed literal's arrow is a closure stored into an unboxed record (spec 36). That record owns nothing, so storing into its field no longer counts as an escape. The closure's uses are now:
    • the record's reads, and the reads of that field (in place, or ts.ExtractProperty);
    • the calls the record is given.
  • Literal .captured boxes vs. generator state: classifyStateBoxes treated every literal's .captured box as a generator's state, which owns its cells and copies. A box that classifyLiteralCaptures decides borrows (specs 67/68) is now skipped there. It borrows a cell of this frame's let the way a closure that does not escape does:
    • rc's RetainCell for the cell is erased, and so is the box's own;
    • decideClosures reports an error if anything uses the literal after the cell is released or moved away.
  • The spec 68 interface path (capturedBoxBorrows) accepts the same cells.

Test

New test own_literal_let_captures, run under own, rc, gc and none, with churn between steps. It captures lets in three ways and reassigns them afterwards:

  • inline in a call;
  • in a const literal that is both called and passed on;
  • given to an interface.

It also captures parameters in literals given to object-type and interface parameters.

Results

  • ctest: 6360/6360.
  • DefaultLib release jit:
    • gc 182/182
    • rc 181/182 (1 skip)
    • none 181/182 (1 skip)
    • own 171/182 (11 skips, all by design)

🤖 Generated with Claude Code

…r borrows it (spec 69)

`let d = ...; apply({ w: (x) => x + d.n }); d.n` was "captured by a closure that escapes", and
`return applyO({ w: (x) => x + item.n })` was "its value is the caller's".

- followClosure: a store into an unboxed record's field (spec 36) is no escape; the record's
  reads, that field's reads and the calls given the record are the closure's uses.
- A literal's `.captured` box that classifyLiteralCaptures decides borrows is no generator
  state's (classifyStateBoxes skips it). It borrows a cell of this frame's `let` too: rc's
  RetainCell for it and the box's own go, and decideClosures checks that no use of the literal
  comes after the cell is released or moved away.
- The spec 68 record path takes the same cells.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 66d377a into main Oct 29, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-literal-let-param-captures branch October 29, 2026 17:31
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