Skip to content

D172: mut parameters, access at call activation, D144 for elements - #2834

Merged
ehartford merged 1 commit into
mainfrom
d172-mut-params-a
Oct 30, 2026
Merged

ehartford merged 1 commit into
mainfrom
d172-mut-params-a

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

The language half of D172 (ruled, #2833), landing before the compiler's own migration: the pinned seed parses no mut parameter, so src/ uses one only after a seed carrying this is cut (then PR B: the compiler's fn -> mut fn / &T -> mut migration and D172 (1)'s receiver-hole enforcement).

See the commit message for the full account. Also: lib/std/string.w ByteIter.next returns b for Some(b) — under D144 the element is the u8 value, so the census now (rightly) sees the wrap as ceremony. One census allowance: clone-call src 556 557 for self.ast.clone() (an AstPool holder count) passed to a mut method on self until per-field footprints.

Gate green. Batteries to follow.

The language half of D172 (ruled), landing before the compiler's own
migration: the pinned seed parses no `mut` parameter, so `src/` can use
one only after a seed carrying this is cut. Nothing here restricts the
compiler source beyond what it meets.

- §3.8a: any parameter may be `mut` — the receiver's `mut self` mode at
  any position (one flag, FN_PARAM_FLAG_MUT_SELF). The ABI is the
  receiver's: the caller's place, IndirectPlace (fn_param_uses_value_ref_
  abi). Sema reads the mode from the declaration (sig_param_is_mut). The
  argument must be a mutable place — not a `let` binding, a temporary or
  a place reached through `&T` — and is written, never moved or copied:
  check_call and propagate_method_call_param_effects (both call forms)
  take neither the consuming path nor a contextual copy for it. MIR passes
  the place, made unique first (D120). A non-Copy `mut` parameter cannot
  be returned, stored or moved (it is the caller's place); a value type
  (`List` under D120) returns a copy.
- §3.8: `mut x` at a call site is a spelling of intent, valid only where
  the parameter is `mut` (AstPool.mark_mut_arg; Sema holds it against the
  signature).
- §3.2/§3.2a: one activation check (check_call_activation) for `mut`
  arguments: an argument may mutate the place while it runs, but may not
  retain access to it when the call begins (judged on paths: disjoint
  fields are not the same place; a contextually copied view holds
  nothing); the same place may not reach a second parameter; a place read
  through an index projection is resolved before the arguments, so an
  argument that mutates its container is an error naming both. For
  receivers this replaces §5.4's blanket refusal of nested mutating calls
  (`pool.add_node(pool.make_node(k))` is legal) and §15.5's refusal of
  any access through the same indexed base (only a mutation of the
  container is an error now). That was live on main:
  `pools[0].bump(pools.push_new())` wrote into the freed buffer and lost
  the increment (printed 7 for 8).
- MIR: a `mut` receiver without an index projection is resolved after the
  arguments (lower_call_with_arg_nodes_recv's deferred receiver), so
  `s.boxed.update(s.reset())` updates the box that exists then; it
  updated the freed one (printed 200 for 201).
- D144 for elements: `let k = self.starts[i]` of plain bits takes the
  value, as `let k = self.idx` already did; it stayed a view of the
  element and refused a later write of `self`.
- Diagnostics in D172's words for a `mut` method through a read-only
  place: the `&T` parameter is named with its `mut p: T` fix.
- Analysis: a parameter fact carries its declared type's span and
  whether it is written `&T` (the D172 migration's input).

Compiler source: 12 views of the intern pool passed to a `mut` method on
the owner they view are copied out first (`self.fail(node,
with_str_clone_ref(self.pool.resolve(s)))`) — the pool may grow under the
view; Zcu.sync_frontend_pool / capture_last_link_lib_names read their own
fields; three `if` joins spell their widening now that the element is the
i32; SemaCheck's borrow-path offset is one accessor (borrow_path_mark)
instead of 13 casts.

Not here (the receiver-hole enforcement and the compiler's `fn` -> `mut
fn` / `&T` -> `mut` migration need this in the seed first): D172 (1)'s
check that a `fn` receiver is read-only for std container writes.

Evidence: 12 fixtures (behav_d172_mut_params, behav_d144_element_binding_
takes_value, 9 err_d172_*, da_d172_view_read_before_grow) each failed on
the installed compiler and pass on stage1; stage1 checks src/main.w with
0 errors.

Tests that pinned what the rulings change (spec supersedes a test):
- D144 (a plain-bits binding from a place takes the value, every binding):
  err_2099_view_used_after_store_is_live, err_d27_copy_elem_view_reassign
  and behav_d27_element_view_liveness pinned a plain-bits ELEMENT binding
  as a view; they are behavior tests of the value now
  (behav_2099_copy_element_binding_takes_value, behav_d27_copy_elem_var_
  takes_value, behav_d27_element_view_liveness: `cur` is 0xAB after
  `v[0] = 0x11`, printing 171). A user IndexGet (`d[1]` on a Deque,
  #2560) is a call returning a view, not a place: it stays a view.
- D172 (§3.8a): err_mut_nonself_param pinned "`mut` is not a parameter
  modifier"; its body (a temporary into a `mut` parameter) is
  err_d172_temporary_to_mut_param. Removed.
- D172 (§3.2a): test/mut_nested_mutating.w (in no target) pinned §5.4's
  refusal of `xs.push(xs.pop().unwrap())`; it is legal now
  (behav_d172_nested_mutating_call). The three err_mut_recv_arg_* tests
  expect D172's wording; an explicit `&a` argument beside a `mut`
  receiver `a` is refused again (the activation check missed it: the
  reference node carried no recorded type).
@ehartford

Copy link
Copy Markdown
Contributor Author

Seed-driven battery GREEN on 617d0cd (with run tools/battery.w, darwin-aarch64): tools/verdict.w out/battery/battery.log → rc=0 green. Windows (win10) battery on the same commit running.

@ehartford

Copy link
Copy Markdown
Contributor Author

Windows (win10, windows-x86_64) battery on 617d0cd: tools/verdict.w out/battery/battery.log → rc=0 green. Both platforms green.

@ehartford
ehartford marked this pull request as ready for review October 30, 2026 04:42
@ehartford
ehartford merged commit e86624a into main Oct 30, 2026
@ehartford
ehartford deleted the d172-mut-params-a branch October 30, 2026 04:42
ehartford added a commit that referenced this pull request Oct 30, 2026
…#2837)

The four gating platforms cut from main 6a97f6c, each to a stage2 ==
stage3 fixpoint with :release-checks green: darwin on the laptop,
linux-x86_64 on eric-5090, windows-x86_64 on win10 (published from the
laptop), linux-aarch64 in tools/docker/linux-aarch64. The first seeds
that parse `mut` on any parameter (D172, #2834), which the compiler's
own migration needs (PR B). Workflow pins rewritten by
tools/bump_seed_pins.w.

Co-authored-by: Eric Hartford <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant