Repository navigation
fix(hy-check): self-shadowing define (m := m) keeps the shadowed binding's non-owned origin (HYB-E3004) - #140
Merged
limitlessprojects merged 1 commit intoOct 15, 2026
Conversation
…on-owned origin (HYB-E3004)
`m := m` in an inner block reads the OUTER binding, but process_local
defined the new binding first and only then recorded alias / may-share
links, which resolved `m` against the new inner binding itself
(record_alias saw `m -> m`, share_edge dropped the self-edge). The outer
parameter / receiver / range variable's non_owned_origin was lost, so
fn spawn(m map[string]int, done chan bool) {
if true {
m := m
task worker(move m, done)
}
}
was accepted with 0 diagnostics while the caller kept writing the same
map (go vet clean, `go run -race`: WARNING: DATA RACE). `move m` of the
parameter itself, or a differently named copy `m2 := m`, already
rejected HYB-E3004.
process_local now reads, before the define, the origin the shadowed
binding would cite (check_non_owned_move's origin computation, factored
into non_owned_origin_of) whenever the initializer hands back that
binding's storage in a form the alias / may-share recorders link (copy,
paren, re-slice, reference-bearing projection, composite literal, call
argument / receiver), and gives it to the new binding.
Tests: hy-check/tests/self_shadow_origin.rs (param, receiver, struct,
slice, call, projection, literal, move-send; scalar / fresh / owned
negative controls). SPEC-LANGUAGE O5.4 note.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New soundness finding plus fix (main track, related to the #5 bounty cycle). Nothing in the tracker reports it: I searched every issue and PR for the self-shadow pattern and found none. It is close to #14 (inner-block shadowing), but #14 was a different hole and it is closed. Here, a self-shadowing define (
m := m,h := h,m := same(m)) in an inner block drops the shadowed binding'snon_owned_origin(PR #61's O5.1 guard). The result:moveof a parameter, method receiver, or struct parameter gets through with 0 diagnostics, while the caller keeps writing the same storage.m := mis the ordinary Go re-declare idiom, and the emitted Go passesgo vet.Repro (main @ f99d6d0,
hybbuilt with the pinned go1.26.9 / rust 1.99.0)Twins that already reject on main:
task worker(move m, done)on the parameter directly, andm2 := m; task worker(move m2, done). Both giveHYB-E3004. Only the spelling of the copy changed.Expected:
error[HYB-E3004]: cannot movem(map[string]int) — move requires an exclusively owned local binding, not parameterm...(tier0_rule: A1b). That is what this PR emits.The same hole shows up with a method receiver (
fn (s state) spawn(...) { if true { s := s; task worker(move s, done) } }) and a struct parameter (h := h). Every one of these is accepted on main with 0 diagnostics, andgo run -racereportsWARNING: DATA RACEon each.Root cause
process_local(loans.rs) callsdefine_bindingfirst and only then records links withrecord_may_share/record_alias. Both look up the RHS ident by name, after the new innermalready shadows the outer one:record_aliasseesm -> mand inherits the inner binding's (empty) originshare_edge(m, m)is a no-opSo the outer binding's origin (parameter / receiver / range variable) never reaches the new binding, and
check_non_owned_movefinds nothing to cite.Fix
freeze.rs: movecheck_non_owned_move's origin computation intonon_owned_origin_of(st, name) -> Option<(String, bool)>, covering both the own/alias-root origin and the [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 may-share peer origin. The diagnostic itself does not change.loans.rs/process_local: before the define, if the initializer hands back the storage of the binding it shadows, read that binding's origin withnon_owned_origin_of. "Hands back" means any form the alias / may-share recorders already link: a copy, paren, re-slice, reference-bearing projection, composite literal, or a non-movecall argument or receiver whose result may share. The new binding inherits that origin if it has none, and only when its shape may share. Scalar shadows (n := n) and copy-outs (m := map[string]int{"k": m["k"]}) are untouched.SPEC-LANGUAGE.mdO5.4: one sentence on the exclusively-owned requirement, including the self-shadow case.Tests
New
compiler/crates/hy-check/tests/self_shadow_origin.rs(4 tests):HYB-E3004/A1band names the shadowed binding:m := m,(m),var m map[string]int = m,s := s[:],m := same(m), structh := h, projectiono := o.h, literalh := holder{m: h.m}, move-sendch <- move m, receivers := sn := n, a scalar copy-out into a fresh map, a fresh value under the same name, a shadow with no boundary move, and a self-shadow of an owned local moved into a taskOn unpatched main, 3 of the 4 tests fail: every reject case is accepted. The control test passes on both.
Local runs, with pinned go1.26.9 / rust 1.99.0:
I also ran
hyb check --jsonon all 55 tracked.hyfiles in the repo with the main binary and the patched binary. Diagnostics are identical on every file: no verdict changes outside the new tests.Scope note: this PR covers the flat pass only. The closure-boundary pass (
closures.rs) has its ownStmt::Localpath, which is #87 (repro 3) / #137 and is addressed by #88. I left it alone so the two changes don't collide.Proposed tier: High (an accepted data race through a common Go idiom; the reach is narrower than a blanket bypass because it needs a non-owned binding plus an inner-block re-declare). Maintainer's call.
Fixes #141