Skip to content

[soundness] Loop back-edge check (check_loop_backedge) fails to propagate moved alias state across iterations, allowing double-move data races #313

Open

Description

@ajithnair1808-max

The smallest .hy program that demonstrates it

// hyb version b6878f8 (latest main)
package main

import "fmt"

fn worker(m map[string]int, done chan bool) {
m["k"] = 1
done <- true
}

fn main() {
m := map[string]int{"k": 0}
done := make(chan bool, 2)

for i in 0..2 {
    task worker(move m, done)
}

<-done
<-done

}

What the checker should say

error[HYB-E3001]: use of moved value: 'm' — value was moved in a previous loop iteration (O2.2)

What it actually said

0 diagnostics (the checker accepts the loop, allowing move m on iteration 0 without invalidating m for iteration 1, resulting in concurrent map write data races under go run -race).

Claimed severity

P0 — data race reachable in the checked subset

Anything else

/claim #

Root Cause Analysis:
In compiler/crates/hy-check/src/freeze.rs, check_loop_backedge validates local loan consistency within a single loop body but fails to propagate moved/invalidated state across loop back-edges into subsequent iterations. Consequently, a variable moved inside a loop body can be reused or re-moved in subsequent iterations without triggering HYB-E3001.

Activity

  1. added
    soundness
    on Oct 16, 2026
  2. gelismarvel commented on Oct 17, 2026

    @gelismarvel
    Contributor

    /claim #313

    Submitting a fix PR for #313 that ensures check_loop_backedge and FnState::scope_pop properly propagate moved alias and may_share state across loop iterations, covered by 4 regression tests (cargo test --manifest-path compiler/Cargo.toml -p hy-check: 121/121 unit + 86/86 integration tests passing).

  3. dancerdan15 commented on Oct 22, 2026

    @dancerdan15

    /attempt #313

  4. added a commit that references this issue on Oct 23, 2026
    7a9b538
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

    soundness

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions