Skip to content

[soundness] Moving a may-share peer of a parameter escapes the O5.1 non-owned check (h2 := h; task worker(move h2) - OK accepted, fatal error: concurrent map writes) #75

Closed

Description

@milkingndb-oss

Revision (git rev-parse HEAD)

8fb92385a54f3934959c1ff059cb13f2ffe2e78d (origin/main, 2026-10-14 19:51 UTC). Also reproduced on the heads of open PRs #32 (8d9c9ba) and #34 (36e93f6) - not covered by either. Related but distinct from the fix for this file in PR #74 (call-result sharing, issue #73): that PR edges call results; this gap is about moving a share peer and exists for the LEXICAL form too.

Summary (Bounty Track #5 - Soundness P0)

check_non_owned_move (freeze.rs) derives non_owned_origin from the binding's own origin or its aliases-chain root only. The may-share graph (#27/#35 - undirected, covering shallow struct/array copies, projections, composite captures) is not consulted, and record_alias's define-time origin inheritance only fires for reference-alias shapes (Map/Slice/Pointer). So for a struct/array/unknown-shaped peer of a parameter:

  • m2 := m (map param) ? correctly rejected HYB-E3004 "cannot move m2 . not parameter m" (alias + inherited origin).
  • h2 := h (struct param carrying a map) ? h2 gets a may-share edge but no origin, so task worker(move h2, done) inside outer passes with OK (0 diagnostics) while the caller keeps a live binding to the same storage - a real race.

The checker's own O5.1 rationale (the E3004 note text: "the caller retains the argument across intra-task calls") applies identically when the moved local is a share peer of the param: the storage is not exclusively owned by the sending frame, so the freeze cannot reach the caller's binding.

Minimal repro

// param-struct3.hy (main @ 8fb9238)
struct holder {
    m map[string]int
}

fn worker(h holder, done chan<- bool) {
    for i in 0..10000 {
        h.m["k"] = i
    }
    done <- true
}

fn outer(h holder, done chan<- bool) {
    h2 := h                 // shallow struct copy: may-share peer of param h
    task worker(move h2, done)  // ACCEPTED - should be HYB-E3004 like the map twin
}

fn main() {
    h := holder{m: map[string]int{"k": 0}}
    done := make(chan bool, 1)
    outer(h, done)
    for i in 0..10000 {
        h.m["k"] = i        // caller writes the same map worker is writing
    }
    <-done
}

hyb check param-struct3.hy ? OK (0 diagnostics).
hyb build --emit-go emits outer: h2 := h; go worker(h2, done) while main loops h.m["k"] = i.
go run on the emitted file: fatal error: concurrent map writes (reproduced).

Negative control (same main, same shapes, map instead of struct)

fn outer(m map[string]int, done chan<- bool) {
    m2 := m
    task worker(move m2, done)
}

? HYB-E3004 cannot move m2 (map[string]int) - move requires an exclusively owned local binding, not parameter m . (O5.1 / O5.4).

The struct/array form must behave identically - the storage-identity argument is the same; only the recorder differs (alias+origin vs share-edge-only).

Expected

Reject the repro with HYB-E3004 (O5.1: move requires an exclusively owned local binding) - the same diagnostic the map twin emits.

Actual

OK (0 diagnostics)

(emitted Go then fatals at runtime)

Claimed severity

P0 - data race reachable in the checked subset

Anything else

Activity

  1. rickymulya commented on Oct 14, 2026

    @rickymulya
    Contributor

    Opened fix PR #80:
    Traverses st.share_group(name) in check_non_owned_move to detect non-owned origins across shallow struct/array copies and projections. Rejects with HYB-E3004 (O5.1 / O5.4).
    Includes regression tests for struct/array parameter peers and positive control for pure locals.

  2. added 2 commits that reference this issue on Oct 15, 2026
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