Skip to content

fix(hy-check): reject boundary move of non-owned parameter, closure capture, and non-channel range bindings (HYB-E3004) - #61

Merged
limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
ocakciomursel-pixel:fix/non-owned-param-and-range-move
Oct 14, 2026
Merged

limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
ocakciomursel-pixel:fix/non-owned-param-and-range-move

Conversation

@ocakciomursel-pixel

Copy link
Copy Markdown
Contributor

Fixes #60
Participation in #5

Problem

Under SPEC-LANGUAGE.md §9.3 O5 (O5.1 / O5.2 / O5.4, rule A1b), move x at a concurrency boundary (task spawn or channel send) transfers exclusive ownership of x so that freezing x and its local aliases prevents any concurrent access in the sending task.

Previously, three classes of non-exclusively-owned bindings in FnState were treated as if they were fresh, uniquely-owned local bindings and passed move x at task/send sites with 0 diagnostics (OK):

  1. Function/closure parameters and method receivers (fn spawn_it(m map[string]int) { task worker(move m, done) }): Intra-task calls do not freeze the caller's argument, so moving a parameter inside the callee leaves the caller's map unfrozen.
  2. Outer bindings captured by a closure (f := fn() { task worker(move m, done) }; f()): closures.rs clones st.env into a temporary cst.env, so moving a captured outer binding inside a closure never freezes the binding in the enclosing function (and the closure can be invoked multiple times).
  3. Range iteration variables over non-channel collections (for k, v in mm { task worker(move v, done) }): Iterating a map/slice/array reads elements out of mm while mm continues to hold and alias the elements (unlike for b in ch over a channel, which transfers ownership per received element).

Fix

  • compiler/crates/hy-check/src/model.rs:
    • Add non_owned_origin: Option<String> to Binding to track when a binding originates from a function/closure parameter, method receiver, closure capture, or non-channel for ... in element.
  • compiler/crates/hy-check/src/lib.rs & closures.rs:
    • Populate non_owned_origin on function receivers, function/closure parameters, outer bindings captured in check_closure, and ForKind::Iterate variables when iterating a non-channel collection (!matches!(ck.shape_of_expr(..., expr), TypeShape::Chan(_))), while also recording st.aliases to the collection root so post-move access to the collection triggers HYB-E3003.
  • compiler/crates/hy-check/src/loans.rs:
    • Propagate non_owned_origin through x := y, x := move y, and x = y rebinds; clear it when a binding is rebound to a fresh value.
  • compiler/crates/hy-check/src/freeze.rs & sendability.rs:
    • Add Checker::check_non_owned_move and invoke it at check_site on un-managed move operands so moving a non-exclusively-owned reference-carrying binding across a concurrency boundary rejects with HYB-E3004 (tier0_rule: "A1b").
  • compiler/crates/hy-check/src/lib.rs (tests):
    • Add non_owned_param_capture_and_range_moves_reject_e3004 covering parameter moves, closure-capture moves, non-channel range-element moves, and the positive control (for b in in_ch { out_ch <- move b }).

Verification

  • cargo test --workspace: all 256 tests pass (0 failures).
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings.
  • python3 tools/corpus_harness.py: 25/25 verdict agreement, tripwire not fired.

Prepared with AI assistance.

…apture, and non-channel range bindings (HYB-E3004)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants