Skip to content

Sema: reads of a place are refused while a closure mutating it is alive (§12.4, #1691) - #1694

Merged
ehartford merged 1 commit into
mainfrom
sema-capture-read-exclusivity
Sep 26, 2026
Merged

ehartford merged 1 commit into
mainfrom
sema-capture-read-exclusivity

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1691. A let-bound non-move closure whose body writes a captured place now registers an exclusive view of it (from its capture summary); reading the place before the closure's last use is refused with a diagnostic naming both, mutations keep their existing refusal, and a dead view (last use behind the read) is removed as before. Fixtures: two compile-error, one behavior (read after last use; move || snapshot). Probes: the four D62 shapes give the expected verdicts; all closure fixtures in both lanes unchanged. Draft until the pinned-seed battery is green.

…ew of it — reads are refused while it is alive (§12.4, D62, #1691)

`let g = () => n += 1; g(); let seen = n; g()` was accepted: the binding's
borrow of `n` was registered SHARED whatever the closure's body did, so
only mutations of `n` were refused. The binding's entry now takes its kind
from the closure's capture summary (EXCLUSIVE when the body writes the
place), the mutation check consults named exclusive entries, and a new
read check refuses a read of the place while the closure is alive — a view
whose last use is behind the read is dead and removed, exactly as for
mutations. `move ||` snapshots are untouched. WITH_DEBUG_BORROWS=1 dumps
the borrow table at binding registration and at every read check.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery verdict — green. Pinned seed nightly-20260925-local-1-607a52f543e7, cold c_import epoch, on 20a8b7e (base 1e83944): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (1291 behavior incl. the new fixture, 1131 compile-error incl. the two new refusals, 17 codegen, spec/phase/internals lanes), :test-green ok, :last-green ok (published), :user-programs-safe ok. Logs: ~/.local/with-staging/capture-read-1691/out/logs/. Sema view/exclusivity change; ready for merge on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant