Repository navigation
-mm=own phase 5a: a closure that does not escape borrows what it captures - #436
Merged
Merged
Conversation
…ures The frame keeps its cells, the box frees itself only (__own_borrows_captures), and nothing that may run the closure comes after anything it borrows is given back. A captured parameter's cell borrows its value (__own_cell_borrows) and cannot be assigned, in the frame or in a closure body (__own_assigns_captures, from the signature pass). An assignment to a captured variable is a drop, and a call given a closure may run it. A closure over a variable that escapes is still an error (5b). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ree would hit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…release too Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 2, 2026
Merged
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.
Phase 5a of
-mm=own(spec §2.5, §4.2 step 6; plandocs/superpowers/plans/2026-10-02-own-phase-5.md; results in spec §16).Before this, every closure that captured a variable was the error "closures that capture a variable are not supported by -mm=own yet". Now a closure that does not escape borrows what it captures:
ts.RetainCelland the box'sts.Retainof each copy go. The closure is marked__own_borrows_captures, and its box's routine frees the box and nothing it holds (tsfrecb_).ts.ReleaseCell, or a copy owner's releases and takers. A copy of a container read is bounded by the read's own check, which now sees the closure's uses.this. Their cell borrows the caller's value. Itsts.ReleaseCellis marked__own_cell_borrowsand frees the cell only. Assigning the variable is an error, in the frame or in a closure body. The signature pass computes the closure-body side (__own_assigns_captures), following nested closures over the same cell.a closure that captures a variable and escapes here is not supported by -mm=own yet. That is 5b. A closure over copies only keeps phase 4's behaviour: its box owns them.Found on the way, also fixed: a closure held by a local that owns nothing (
let f: () => number; f = () => ...) lost its only release. rc's birthRetainread as the store's acquisition, so the box leaked. The closure now keeps its release, and calls through the alias must come before it.MLIRGen does not change. gc/rc/none output does not change: the lowering changes are all under
MemoryModelOwn.Verification
test-compile-gc-defaultlib-collector: LNK2005 onError..sizeetc. against the installed default library atI:\tslang(built 2026-09-28, before DefaultLib [Question] Speed difference #20, which needs a rebuild). It is a gc-only test, and this branch touches no gc code path.owntests pass.-mm=own --no-default-lib: 310 → 319 of 591, none lost. The 9 new ones pass undertest-runner -mm=own, AOT and JIT. Their JIT output matches gc.measure.ps1onown_closure_borrow: gc 6.1, rc 4.3, none 1879.7, own 4.3 MB.own_closure_borrowcrashes under AOT (0xC0000005). With__own_cell_borrowsignored, it crashes too (0xC0000374). Each new negative compiles with its rule switched off.Tests
own_closure_borrow(13 shapes), JIT, AOT and no-counting.own_err_closure(now: escapes),own_err_closure_outlives_cell,own_err_closure_copy_moved,own_err_closure_param_assigned,own_err_closure_assigns_param,own_err_cell_assigned_in_frame,own_err_cell_assigned_in_closure,own_err_closure_assigns_captured_field.🤖 Generated with Claude Code