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
Implement D12: mut fn on scalar primitive owners lowers via share-place (IndirectPlace) #677
mut fn mutates the caller's place on every owner type. This issue implements the scalar primitive shape: mut fn receivers on i8–i64, u8–u64, usize/isize, f32/f64, bool, char, and distinct/newtypes over them, lower via D5 share-place (PassMode::IndirectPlace), so x.bump() on a var x mutates x.
Governing principle (D12): the receiver mode decides share-place, not the owner's Copy-ness. f(x) copies; x.bump() borrows. move self stays consuming.
Root cause (single gate)
src/SemaDecl.w:1086 fn_param_uses_value_ref_abi restricts IndirectPlace to STRUCT/GENERIC_INST/ENUM owners (line ~1093); scalar owners fall through to by-value, so self += 1 mutates a callee copy. After D7 enforcement this surfaces as a misleading cannot assign to immutable variable.
Approach
Extend fn_param_uses_value_ref_abi so a non-moveself receiver on a scalar primitive (or distinct-over-scalar) owner returns share-place. Compose with compute_fn_abi/PassMode (D6) — one ABI classifier, read by both declare_function prologue and push_call_arg; do NOT add a per-path decision.
Confirm caller marshalling (CodegenDispatch IndirectPlace path) and callee prologue both honor the new classification via --dump-abi.
move self on a scalar stays OWNED (consumed); plain fn/&self on a Copy scalar may remain by-value (read-only).
Acceptance
extend i32: mut fn bump(): self += 1 — x.bump() mutates a var; let receiver is a clean "cannot mutate immutable binding" error.
Distinct-type domain verbs: distinct type Health = i32; extend Health: mut fn damage(n: i32) mutates in place.
--dump-abi shows SHARE-PLACE for the mut self scalar receiver, OWNED for move self.
/drop-audit matrix clean (value shape × control flow × ownership op × receiver mode) — new cells for scalar share-place receivers; run before and after.
Behavior + spec fixtures pinning mutate-in-place, the let-rejection, and move/mut distinction.
Full battery: build, :fixpoint, analyze audit:all, :test.
D12-SCALAR IMPLEMENTED (566bc58, full battery GATES EXIT: 0 — fixpoint byte-identical, audit violations=0, all 9 targets green with the new fixtures; reseeded on both seed paths + release asset).
Every acceptance item verified:
extend i32: mut fn bump(): self += 1 — x.bump() mutates a var (straight-line, branch, and loop shapes pinned in behav_d12_scalar_mut_receiver.w, including f64/bool owners); let receiver gets the spec's clean cannot mutate immutable binding \y` (test/compile_errors/d12_scalar_let_receiver.w`).
Distinct domain verbs mutate in place via the canonical §9.5 form: mut fn damage(n: i32): self = Health(self.value - n) (distinct types are TY_STRUCT wrappers, so they already rode the D5 IndirectPlace ABI — the missing piece was bare-self assignability).
--dump-abi: SHARE-PLACE for the mut-self scalar receiver, OWNED for move-self — the verdict order is now D12-aware (mode outranks Copy-ness).
Single-classifier discipline held: the only ABI change is in fn_param_uses_value_ref_abi (scalar owner kinds added); prologue and call sites read it through the existing arg_pass_mode/PassMode path. No per-path decisions.
Copy-semantics boundary pinned: f(x) still copies; callee-local mutation of a copy never reaches the caller.
Drop discipline (the reason for the scoping): the mandated drop-audit ran as a --debug-alloc matrix (the drop-audit skill was lost in the machine switch — flagged in #689). Scalar and distinct-over-scalar cells are allocator-clean. Enabling bare-self assignment on HEAP-bearing owners exposed that place reassignment never drops the old contents — even plain v = w on a local leaks on the shipped compiler (filed as #689 with MIR-level analysis). Heap owners therefore keep the status quo behind d12_mut_self_binding_allowed until #689's drop elaboration lands; the parked acceptance matrix is in that issue.
Also filed:#690 — parameter rebinding is rejected today despite mutability.md declaring parameters implicitly rebindable (found when a fixture leaned on it).
Remaining D12 work: #678 (str/fat-pointer receivers — delicate, own cycle, interacts with #689 and §22 view-origin rules) and the #689-gated heap-owner bare-self surface. Closing this scalar issue.
Activity
Docs: canonize D12 — mut fn mutates in place on every owner type (#644)
Sema: mut fn on scalar owners lowers via share-place (D12, #677)
ehartford commentedon Jul 19, 2026
D12-SCALAR IMPLEMENTED (566bc58, full battery
GATES EXIT: 0— fixpoint byte-identical, audit violations=0, all 9 targets green with the new fixtures; reseeded on both seed paths + release asset).Every acceptance item verified:
extend i32: mut fn bump(): self += 1—x.bump()mutates avar(straight-line, branch, and loop shapes pinned inbehav_d12_scalar_mut_receiver.w, including f64/bool owners);letreceiver gets the spec's cleancannot mutate immutable binding \y`(test/compile_errors/d12_scalar_let_receiver.w`).mut fn damage(n: i32): self = Health(self.value - n)(distinct types are TY_STRUCT wrappers, so they already rode the D5 IndirectPlace ABI — the missing piece was bare-self assignability).--dump-abi:SHARE-PLACEfor the mut-self scalar receiver,OWNEDfor move-self — the verdict order is now D12-aware (mode outranks Copy-ness).fn_param_uses_value_ref_abi(scalar owner kinds added); prologue and call sites read it through the existingarg_pass_mode/PassModepath. No per-path decisions.f(x)still copies; callee-local mutation of a copy never reaches the caller.Drop discipline (the reason for the scoping): the mandated drop-audit ran as a
--debug-allocmatrix (the drop-audit skill was lost in the machine switch — flagged in #689). Scalar and distinct-over-scalar cells are allocator-clean. Enabling bare-self assignment on HEAP-bearing owners exposed that place reassignment never drops the old contents — even plainv = won a local leaks on the shipped compiler (filed as #689 with MIR-level analysis). Heap owners therefore keep the status quo behindd12_mut_self_binding_alloweduntil #689's drop elaboration lands; the parked acceptance matrix is in that issue.Also filed: #690 — parameter rebinding is rejected today despite mutability.md declaring parameters implicitly rebindable (found when a fixture leaned on it).
Remaining D12 work: #678 (str/fat-pointer receivers — delicate, own cycle, interacts with #689 and §22 view-origin rules) and the #689-gated heap-owner bare-self surface. Closing this scalar issue.