You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sema: a live closure's mutate capture is not exclusive — the enclosing scope may read/write the captured place between two calls (§12.4, D62 non-compliance) #1691
Spec §12.4 (D62): "A non-move closure holds a view of each captured place while it is alive, under the ordinary exclusivity rules (§5): mutating a place in the enclosing scope while a closure holding a read capture of it is alive is an error." A mutate capture is the symmetric case: while the closure is alive, other access to the captured place is an exclusivity error.
Repro (installed compiler 7456c37b…, main 1e839443) — compiles and runs, prints 1 then 2:
use std.builtins.print_i32
fn main:
var body: Vec[i32] = Vec.new()
let sink = k => body.push(k)
sink(1)
print_i32(body.len() as i32) // read of `body` while `sink` (mutate capture) is alive
sink(2)
Same through an ephemeral holding &sink (type Keeper = ephemeral { f: &fn(i32) -> Unit }; keep.f(1); body.len(); keep.f(2)).
Expected: refused — body is held by a mutate view (sink) that is still alive (used again below). Actual: accepted.
Why it matters now: D66's retained variadic pairs (#1652, #1679) define the retention of a callback's userdata as this same view, held by the resource until reset/destroy/last callback-capable operation (Eric's ruling, 2026-09-25). Refusing a use of the sink inside that window depends on Sema enforcing capture exclusivity at all; today it enforces neither the plain case above nor the retained one.
Not a spec question: §12.4 already states the rule.
Narrowed: mutation against a live closure view is enforced for both capture modes (n = 5 after let g = () => n += 1 → "cannot mutate n while g is a live view into it"; same for a read capture). The gap is reads only: g(); let seen = n; g() with g = () => n += 1 is accepted, and so is sink(1); body.len(); sink(2). Fix: a read check against live EXCLUSIVE views (check_mutation_against_views only consults SHARED ones).
Activity
ehartford commentedon Sep 25, 2026
Narrowed: mutation against a live closure view is enforced for both capture modes (
n = 5afterlet g = () => n += 1→ "cannot mutatenwhilegis a live view into it"; same for a read capture). The gap is reads only:g(); let seen = n; g()withg = () => n += 1is accepted, and so issink(1); body.len(); sink(2). Fix: a read check against live EXCLUSIVE views (check_mutation_against_viewsonly consults SHARED ones).Sema: a live closure that mutates a captured place is an exclusive vi…
Sema: a callable retained as callback userdata stays a live view whil…