Repository navigation
Description
Summary
Remove the compile error that forces callers to write move x/copy x when passing a non-Copy value to a parameter the callee consumes or escapes. Spec v7.1 §3.8 rules that the signature states the call mode and no call-site annotation is ever required; the implemented gate makes the most common consuming calls (vec.push(move item), tx.send(move msg)) more ceremonial than the languages With improves on, while stating something the compiler already knows (mission test: ceremony with no caught mistake). move x/copy x remain as optional explicit spellings; use-after-move enforcement is unchanged.
Spec
§3.8 Auto-Referencing (spec v7.1, normative): "The parameter's declared type states the mode. A &T parameter borrows … A plain T parameter consumes: the argument is moved into the callee … No call-site annotation is ever required for either mode — a plain call f(x) is always legal and means whatever the signature says. move x, copy x, and &x remain available as explicit spellings of intent."
take(alice) // signature take(a: User): consumes alice
peek(alice) // signature peek(a: &User): borrows alice
take(move alice) // explicit spelling of the same consume
dup(copy xs) // duplicate via Copy or Clone instead of consuming
Ruling record: docs/completed/spec-feedback.md §A.1 ("Cut the acknowledgment; keep the effect inference" — the implementation is "right, except the move x/copy x acknowledgment gate"). Requirement ID 3.8.1.6 is partial in out/req-campaign with pointer #372.
Current state
Verified at 1c5258007a362fcd8c7a145b3e9c3be4c84ac47d:
- The gate lives in
check_call,src/SemaCheck.w:8177-8188: whenparam_eff & (EFF_CONSUME | EFF_ESCAPE_VALUE) != 0and the arg node is notNK_COPY_ARG/NK_MOVE_ARGand the type is non-Copy, it emitsnon-Copy argument passed to a function that consumes or escapes it; use 'move x' or 'copy x'(line 8186). Immediately before (line 8181) it callsmark_moved_if_consumed(eff_arg_nd)— that mark, not the error, is what powersuse of moved valuelater (SemaCheck.w:3443-3449, markerSema.mark_moved_if_consumedat 12909). - Effect bits:
src/Sema.w:214-219(EFF_CONSUME=4,EFF_ESCAPE_VALUE=8). Inference sites: explicitmove xin a callee body recordsEFF_CONSUME(SemaCheck.w:3293vianote_param_effect); returning a param recordsEFF_ESCAPE_VALUE(SemaCheck.w:866, 4996, 7026); transitive propagation through nested calls (SemaCheck.w:4963-4967) and closure captures (7735-7737). - The enforcement is already inconsistent, demonstrating it prevents nothing:
- probe:
fn consume_store(v: Vec[str]): let x = v; …then plainconsume_store(v)compiles today — a body that consumes via plainletrebinding never recordsEFF_CONSUME(onlyNK_MOVE_ARGdoes, line 3293), so the gate never fires; - probe:
fn take(r: Resource) -> Resource: return rthentake(r)errors (escape-by-return is inferred); - method-call arguments never pass through the gate at all (no equivalent check in the method path around
SemaCheck.w:10340+) —vec.push(item)is already annotation-free.
- probe:
- The separate
EFF_ESCAPE_VIEWrule (SemaCheck.w:8189-8198, rejectingmove/copyon view-escaping args) is unrelated and must stay. - Tests pinning the current error (all
//! expect-check-fail: non-Copy argument passed to a function that consumes or escapes it):test/compile_errors/err_eff_escape_no_move.w,err_noncopy_escape.w,err_transitive_escape.w,err_closure_capture_escape_summary.w. - MirLower already lowers a plain non-Copy arg as
OK_MOVE(src/MirLower.w:2308-2323vialower_call_arg), so no lowering change is needed — but note the caller's scheduled scope-exit drop is not cancelled on by-value moves today (observed double-drop), which is Bug: Drop expression temporaries are never dropped (§2.4) #430's move-handoff fix, not this issue's.
Implementation plan
src/SemaCheck.w(check_call, lines 8177-8188): delete theanode_kind != NK_COPY_ARG and != NK_MOVE_ARG → emit_errorbranch. Keep everything else in the block:mark_moved_if_consumed(eff_arg_nd)(use-after-move),propagate_call_param_effect(transitivity), and theEFF_ESCAPE_VIEWmove/copy rejection below it.- Close the consume-inference gap so use-after-move survives the gate's removal with full coverage: where the callee body marks a binding
VarState.MOVEDand that binding is a parameter (plainlet x = param, plain consuming call of a param, struct-literal field init from a param), callnote_param_effect(sym, EFF_CONSUME)exactly as theNK_MOVE_ARGpath does at 3292-3293. Without this,consume_store(v); v.len()would silently pass (it does today). Candidate sites: theVarState.MOVEDsetters atSemaCheck.w:7130, 7757, 10594, 12939— gate each on "sym is a param of the current fn" (the helpernote_param_effectalready checks this). - Do not touch parsing:
NK_MOVE_ARG/NK_COPY_ARG(src/Parser.w:3172-3216) and their sema (SemaCheck.w:3270-3296, including the Clone-fallback forcopy) stay — optional spellings remain legal per spec. - Update the four pinned tests (see Test plan). No rt/Link/seed changes; sema-only — but the compiler's own sources call consuming functions, so watch for newly-surfaced
use of moved valueerrors insrc/after step 2 (they would be real bugs or real annotations to fix, not check-weakening candidates).
Test plan
- Repurpose
test/compile_errors/err_eff_escape_no_move.w→test/spec/spec_ss03_8_plain_consuming_call.w(//! expect-stdout): plaintake(r)is legal;take(move r)anddup(copy xs)also compile; behavior identical. - Convert the three remaining gate tests into use-after-move tests (
//! expect-check-fail: use of moved value):err_noncopy_escape.w:let _ = identity(p)then addlet y = p.first— the plain call moves, the subsequent use errors;err_transitive_escape.w:wrap_take(r)(transitiveEFF_ESCAPE_VALUE) then user;err_closure_capture_escape_summary.w:consume_capture(r)then user.
- New negative test for step 2's inference fix,
test/compile_errors/err_plain_let_consume_use_after.w(//! expect-check-fail: use of moved value): callee consumes vialet x = v(nomoveanywhere); caller calls plainly then uses the binding. This is the case that compiles silently today. - Positive: extend
test/spec/spec_ss03_8_auto_referencing.wwith a consuming-parameter case showingf(x)+ no further use compiles, and that a&Toverload of the same shape leaves the binding valid (mode is the signature's choice). - Verify
copy_move_keyword_calls.wandbehav_move*.wstill pass unchanged.
Acceptance criteria
- Plain
f(x)compiles for consuming/escaping non-Copy parameters; the binding is invalidated; later use errorsuse of moved value. -
move x/copy xremain accepted with unchanged semantics;EFF_ESCAPE_VIEWmove/copy rejection unchanged. - The plain-
let-rebind consume case (today's silent hole) is caught by use-after-move. - The string
use 'move x' or 'copy x'no longer appears in src/ or test expectations. -
with build && with build :fixpoint && with build :testpass.
Dependencies
- Bug: Drop expression temporaries are never dropped (§2.4) #430 — by-value moves currently double-drop (caller scope-exit drop not cancelled); removing the annotation increases plain-consuming-call traffic, so Bug: Drop expression temporaries are never dropped (§2.4) #430's handoff fix should land close to this. Overlaps test fixtures.
- Directed diagnostic: by-value parameter that is only read (or whose view escapes) should suggest &T #373 — the directed
&Tsuggestion is the constructive replacement for the deleted gate (definition-site, not call-site). - Borrow checker Rule 7: implicit drop is a use (§21.1) #444 (implicit drop is a use) — adjacent move-analysis work.
Traceability
Spec reference: §3.8 Auto-Referencing (parameter modes) — spec v7.0/v7.1. Original context and rationale preserved above (ruling: signature states the mode; annotation is pure ceremony; mission test).
Activity
ehartford commentedon Jun 11, 2026
Implemented in 19f7cb9. Removed the call-site move/copy acknowledgment gate for consuming arguments while keeping use-after-move enforcement, optional move/copy spellings, and escape-view rejection. Also closed the plain-parameter-consume inference gap exposed by the change and added positive/negative coverage. Verification passed: with build, with build :fixpoint, with build :test, and with build :test-green.