Skip to content

Remove the move x/copy x acknowledgment requirement for consuming arguments #372

Closed

Description

@ehartford

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: when param_eff & (EFF_CONSUME | EFF_ESCAPE_VALUE) != 0 and the arg node is not NK_COPY_ARG/NK_MOVE_ARG and the type is non-Copy, it emits non-Copy argument passed to a function that consumes or escapes it; use 'move x' or 'copy x' (line 8186). Immediately before (line 8181) it calls mark_moved_if_consumed(eff_arg_nd) — that mark, not the error, is what powers use of moved value later (SemaCheck.w:3443-3449, marker Sema.mark_moved_if_consumed at 12909).
  • Effect bits: src/Sema.w:214-219 (EFF_CONSUME=4, EFF_ESCAPE_VALUE=8). Inference sites: explicit move x in a callee body records EFF_CONSUME (SemaCheck.w:3293 via note_param_effect); returning a param records EFF_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 plain consume_store(v) compiles today — a body that consumes via plain let rebinding never records EFF_CONSUME (only NK_MOVE_ARG does, line 3293), so the gate never fires;
    • probe: fn take(r: Resource) -> Resource: return r then take(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.
  • The separate EFF_ESCAPE_VIEW rule (SemaCheck.w:8189-8198, rejecting move/copy on 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-2323 via lower_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

  1. src/SemaCheck.w (check_call, lines 8177-8188): delete the anode_kind != NK_COPY_ARG and != NK_MOVE_ARG → emit_error branch. Keep everything else in the block: mark_moved_if_consumed(eff_arg_nd) (use-after-move), propagate_call_param_effect (transitivity), and the EFF_ESCAPE_VIEW move/copy rejection below it.
  2. 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.MOVED and that binding is a parameter (plain let x = param, plain consuming call of a param, struct-literal field init from a param), call note_param_effect(sym, EFF_CONSUME) exactly as the NK_MOVE_ARG path does at 3292-3293. Without this, consume_store(v); v.len() would silently pass (it does today). Candidate sites: the VarState.MOVED setters at SemaCheck.w:7130, 7757, 10594, 12939 — gate each on "sym is a param of the current fn" (the helper note_param_effect already checks this).
  3. 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 for copy) stay — optional spellings remain legal per spec.
  4. 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 value errors in src/ 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): plain take(r) is legal; take(move r) and dup(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 add let y = p.first — the plain call moves, the subsequent use errors;
    • err_transitive_escape.w: wrap_take(r) (transitive EFF_ESCAPE_VALUE) then use r;
    • err_closure_capture_escape_summary.w: consume_capture(r) then use r.
  • 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 via let x = v (no move anywhere); caller calls plainly then uses the binding. This is the case that compiles silently today.
  • Positive: extend test/spec/spec_ss03_8_auto_referencing.w with a consuming-parameter case showing f(x) + no further use compiles, and that a &T overload of the same shape leaves the binding valid (mode is the signature's choice).
  • Verify copy_move_keyword_calls.w and behav_move*.w still pass unchanged.

Acceptance criteria

  • Plain f(x) compiles for consuming/escaping non-Copy parameters; the binding is invalidated; later use errors use of moved value.
  • move x / copy x remain accepted with unchanged semantics; EFF_ESCAPE_VIEW move/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 :test pass.

Dependencies

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

  1. ehartford commented on Jun 11, 2026

    @ehartford
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions