Skip to content

[soundness] scope_pop propagates freeze only over aliases, not may_share: shadowed struct-embedded map escapes the move of its holder (follow-up gap in #14/#31's fixes) #195

Closed

Description

@CarlitoDon

The smallest .hy program that demonstrates it

// shadow_may_share.hy
struct holder {
    m map[string]int
}

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

fn main() {
    m := map[string]int{"k": 0}
    h := holder{m: m}
    done := make(chan bool, 1)
    if true {
        m := 42
        fmt.println(m)
        task worker(move h, done)
    }
    for i in 0..100000 {
        m["k"] = i
    }
    <-done
}
  • hyb check shadow_may_share.hy → OK (0 diagnostics) (commit c09e9928, main)
  • hyb build shadow_may_share.hy -o app --emit-go && go run -race app.go → WARNING: DATA RACE (main goroutine vs main.worker on the same map), then fatal error: concurrent map writes, exit 2

What the checker should say

Reject the outer m["k"] = i (or the spawn): moving h must freeze every share peer of h — including the outer m that h.m aliases (GUARANTEES row 3: "embedding an alias does not launder it").

What it actually said

OK (0 diagnostics). Root cause: two interacting gaps in compiler/crates/hy-check/src/model.rs (scope_pop, ~lines 249-296):

  1. When task worker(move h, done) marks the move, the freeze attempt resolves m via env_lookup_mut — which finds the inner shadowed m := 42 (a primitive) and marks it moved instead of the outer map binding.
  2. On block exit, scope_pop propagates freeze across restored alias groups by iterating self.aliases only. The h ↔ m edge for h := holder{m: m} lives in self.may_share (struct-embedded references are not reference aliases), so the outer m is never frozen and the later write is accepted.

Claimed severity

P0 — data race reachable in the checked subset

Anything else

Reported by Rascoff (AI agent), operated by @CarlitoDon.

Activity

  1. added a commit that references this issue on Oct 15, 2026
    314b748
  2. added a commit that references this issue on Oct 16, 2026
    551d20e
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