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
mut-self on primitive/str owners passes self by value — in-place mutation cannot reach the caller #644
declare_function_at (src/Codegen.w:3847-3866) lowers struct/enum self params as pointers, but primitive and str owners pass self BY VALUE — so a mut self method on a primitive/str extension mutates a callee copy and the caller never sees it. Found during the #641a receiver-lowering design pass (out of scope there: the fix is an ABI change for primitive receivers).
Spec
§9.5: mut self: Self "mutates x in place" (requirements 9.5.1.4) — currently untrue for primitive/str owners.
Fix direction
Either lower flagged mut-self primitive receivers by pointer too, or reject mut self on by-value-ABI owners at check time with a clear message. Needs a small ruling on which.
Re-triaged during the v0.16.0 release-blocker sweep — no longer a silent-wrongness blocker
The silent bug this issue reported (a mut self primitive/str method mutates a callee copy and the caller never sees it) no longer reproduces. The D7 receiver-mode enforcement, which landed after this issue was filed, already converted it to a loud compile error. Every mutation form on a primitive/str receiver is now rejected at check time:
Verified against the current compiler for self = …, self += …, and mutation via a nested mut fn — all loud, none silent. The codebase contains zero mut fn methods on primitive/str owners, so neither resolution direction risks a self-host flip.
Consequence for the release: the stability bar ("never silently wrong") is met, so this is removed from the v0.16.0 blocker set.
What remains (the ruling this issue asked for) — post-release
The premise is still true: in-place mutation of a primitive/str receiver cannot reach the caller — it's just loud now instead of silent. The original fix direction still needs a maintainer ruling:
A. Make it work — lower flagged mut fn primitive/str receivers by pointer (share-place / IndirectPlace), so mut self mutates in place per §9.5. This is an ABI change to the D5 share-place model (fn_param_uses_value_ref_abi, SemaDecl.w:~1086) and should be weighed against docs/completed/mutability.md + decisions.md D5/D6/D7.
B. Keep rejecting — but replace the misleading "cannot assign to immutable variable" with a message that names the real reason (primitive/str receivers use by-value ABI; mutate a caller variable directly instead).
Recommendation: A is the mission-aligned answer (ergonomics-first, §9.5 says mut self mutates in place), but it's an ABI change that wants an explicit D-log entry, so it's out of scope for the packaging-focused release. B's message improvement is a safe, small follow-up regardless of the A/B call.
Ruling: Option A — canonized as D12 (BDFL, 2026-07-17)
mut fn mutates the caller's place on every owner type — primitives and str included. Not deferred: in scope for v0.16.0 ("we do it right, now").
The governing principle (D12): the receiver mode decides share-place, the owner's type does not. i32 is Copy, but mut fn still borrows in place — mode wins over Copy-ness, exactly as it already does for Copy structs. f(x) copies; x.bump() borrows. No new mechanism: it's D5 share-place / PassMode::IndirectPlace (D6), the same ABI aggregates already use. The previous restriction to STRUCT/GENERIC_INST/ENUM owners (SemaDecl.w:1086 fn_param_uses_value_ref_abi, lines ~1089/1093) was an incompleteness, not a design.
Reference filter (verified in .reference/): Swift ships mutating func negate() on Int (Integers.swift:327); Rust ships &mut self make_ascii_uppercase on a primitive (core/num/mod.rs:720). Effectively unanimous that the mutation must reach the caller. Mission: §9.5 already promises "mut self mutates in place" with no primitive carve-out — spec-leads-compiler; the spec is right, the impl was incomplete.
Idiom (spec examples lead with this): domain verbs on distinct/newtypes — distinct type Health = i32; extend Health: mut fn damage(n) → hp.damage(30). Bare i32.bump() is legal but prefer the operator when there's no domain meaning.
Option B rejected: it bent the spec to a current ABI limitation (backwards from spec-leads-compiler) and denied an ergonomic the two closest references ship in their own stdlibs.
Implementation (this issue = umbrella)
Two ABI shapes, split by genuine risk/shape difference:
Both gated on the /drop-audit matrix. This issue closes when both land and §9.5's promise holds for every owner type. The misleading cannot assign to immutable variable diagnostic disappears as a consequence (the feature works; no honest-error half-measure needed).
D12 is COMPLETE across every owner type: scalars/distinct-over-scalar (#677, 566bc58), aggregates (uniform mut-self binding, e101e7e), and str/fat-pointer (#678, e823026). The receiver MODE decides share-place, uniformly — 'extend i32: mut fn bump()' mutates, 'self = Health(...)' mutates, 'self = W{...}' mutates, 'self = self.slice(...)' mutates. Spec §9.5's canonized surface is fully implemented, battery-gated, allocator-lane-verified, and reseeded. With D11 (#630) also live, both canonized-ahead rulings from the 2026-07-17 handoff are now law AND implementation.
Activity
Fix #641a/#641b/#642: mut-self borrows (incl. Drop types); explicit .…
docs: D7 — eliminate `self`; receiver mode becomes a `fn` prefix keyword
ehartford commentedon Jul 15, 2026
Re-triaged during the v0.16.0 release-blocker sweep — no longer a silent-wrongness blocker
The silent bug this issue reported (a
mut selfprimitive/str method mutates a callee copy and the caller never sees it) no longer reproduces. The D7 receiver-mode enforcement, which landed after this issue was filed, already converted it to a loud compile error. Every mutation form on a primitive/str receiver is now rejected at check time:Verified against the current compiler for
self = …,self += …, and mutation via a nestedmut fn— all loud, none silent. The codebase contains zeromut fnmethods on primitive/str owners, so neither resolution direction risks a self-host flip.Consequence for the release: the stability bar ("never silently wrong") is met, so this is removed from the v0.16.0 blocker set.
What remains (the ruling this issue asked for) — post-release
The premise is still true: in-place mutation of a primitive/str receiver cannot reach the caller — it's just loud now instead of silent. The original fix direction still needs a maintainer ruling:
mut fnprimitive/str receivers by pointer (share-place /IndirectPlace), somut selfmutates in place per §9.5. This is an ABI change to the D5 share-place model (fn_param_uses_value_ref_abi, SemaDecl.w:~1086) and should be weighed againstdocs/completed/mutability.md+decisions.mdD5/D6/D7.Recommendation: A is the mission-aligned answer (ergonomics-first, §9.5 says
mut selfmutates in place), but it's an ABI change that wants an explicit D-log entry, so it's out of scope for the packaging-focused release. B's message improvement is a safe, small follow-up regardless of the A/B call.ehartford commentedon Jul 17, 2026
Ruling: Option A — canonized as D12 (BDFL, 2026-07-17)
mut fnmutates the caller's place on every owner type — primitives andstrincluded. Not deferred: in scope for v0.16.0 ("we do it right, now").The governing principle (D12): the receiver mode decides share-place, the owner's type does not.
i32isCopy, butmut fnstill borrows in place — mode wins over Copy-ness, exactly as it already does for Copy structs.f(x)copies;x.bump()borrows. No new mechanism: it's D5 share-place /PassMode::IndirectPlace(D6), the same ABI aggregates already use. The previous restriction to STRUCT/GENERIC_INST/ENUM owners (SemaDecl.w:1086 fn_param_uses_value_ref_abi, lines ~1089/1093) was an incompleteness, not a design.Reference filter (verified in .reference/): Swift ships
mutating func negate()on Int (Integers.swift:327); Rust ships&mut self make_ascii_uppercaseon a primitive (core/num/mod.rs:720). Effectively unanimous that the mutation must reach the caller. Mission: §9.5 already promises "mut self mutates in place" with no primitive carve-out — spec-leads-compiler; the spec is right, the impl was incomplete.Idiom (spec examples lead with this): domain verbs on distinct/newtypes —
distinct type Health = i32; extend Health: mut fn damage(n)→hp.damage(30). Barei32.bump()is legal but prefer the operator when there's no domain meaning.Option B rejected: it bent the spec to a current ABI limitation (backwards from spec-leads-compiler) and denied an ergonomic the two closest references ship in their own stdlibs.
Implementation (this issue = umbrella)
Two ABI shapes, split by genuine risk/shape difference:
i32*-style). The common case; land first.str/fat-pointer owners → IndirectPlace over the{ptr,len}fat pointer. Distinct shape, own drop/ephemeral cell.Both gated on the
/drop-auditmatrix. This issue closes when both land and §9.5's promise holds for every owner type. The misleadingcannot assign to immutable variablediagnostic disappears as a consequence (the feature works; no honest-error half-measure needed).Docs: canonize D12 — mut fn mutates in place on every owner type (#644)
ehartford commentedon Jul 19, 2026
D12 is COMPLETE across every owner type: scalars/distinct-over-scalar (#677, 566bc58), aggregates (uniform mut-self binding, e101e7e), and str/fat-pointer (#678, e823026). The receiver MODE decides share-place, uniformly — 'extend i32: mut fn bump()' mutates, 'self = Health(...)' mutates, 'self = W{...}' mutates, 'self = self.slice(...)' mutates. Spec §9.5's canonized surface is fully implemented, battery-gated, allocator-lane-verified, and reseeded. With D11 (#630) also live, both canonized-ahead rulings from the 2026-07-17 handoff are now law AND implementation.
Sema: mut fn on str owners lowers via share-place over the fat pointe…
Docs: handoff — D12 COMPLETE (#678 done, #644 closed); queue advances…