Repository navigation
Description
Summary
GUARANTEES.md row 11 explicitly specifies:
sync/atomic(atomic.Pointer[T], ...):[TBD]... Until then: unproven → rejected.
However, in compiler/crates/hy-check/src/foreign.rs, foreign_named_type matches if name.starts_with("atomic.") { return Some(TypeShape::Atomic); } for all atomic.* types — including atomic.pointer[T] and atomic.value — and method_result returns TypeShape::Primitive for every atomic.* method call (p.load(), p.swap(...), etc.).
As a result, sharing &p (where p is atomic.pointer[holder] pointing to a struct containing a mutable map[string]int) or &v (atomic.value) across spawned tasks is accepted by hyb check with 0 diagnostics (OK), allowing two goroutines to load the same *holder and concurrently mutate h.data["k"] without synchronization (fatal error: concurrent map writes).
- Tested commit (
main):8aaa231e947d87e163cb5836e798ee6a69b58fd0 - Violated guarantees:
GUARANTEES.mdRow 1 (No value reaches a spawned task or channel send through an unproven path) & Row 11 (sync/atomic(atomic.Pointer[T], ...) — Until then: unproven → rejected)SPEC.md§O4.9 (Fail-closed concurrency boundary (HYB-E3005))
Minimal Reproducer (f5_atomic_pointer.hy)
import "sync/atomic"
struct holder {
data map[string]int
}
fn worker(p *atomic.pointer[holder], done chan<- bool) {
h := p.load()
for i in 0..10000 {
h.data["k"] = i
}
done <- true
}
fn main() {
var p atomic.pointer[holder]
shared := holder{data: map[string]int{"k": 0}}
p.store(&shared)
done := make(chan bool, 1)
task worker(&p, done)
for i in 0..10000 {
shared.data["k"] = i
}
<-done
}Variant 2 — atomic.value (f5b_atomic_value.hy)
import "sync/atomic"
fn worker(v *atomic.value, done chan<- bool) {
done <- true
}
fn main() {
var v atomic.value
done := make(chan bool, 1)
task worker(&v, done)
<-done
}Actual vs. Expected Behavior
Actual (main)
$ hyb check f5_atomic_pointer.hy
OK (0 diagnostics)
Running the emitted Go code on Go 1.27.0 immediately crashes:
fatal error: concurrent map writes
Expected (and behavior with the accompanying fix PR)
$ hyb check f5_atomic_pointer.hy
error[HYB-E3005]: cannot prove `&p` (`*atomic.pointer[holder]`) is safe to send at the spawn `task worker(...)` (fail-closed, O4.9)
--> f5_atomic_pointer.hy:20:17
|
20 | task worker(&p, done)
| ^^ sendability is not proven here
= note: why: `atomic.pointer[holder]` can smuggle arbitrary non-sendable references across task boundaries; GUARANTEES.md row 11 marks `atomic.Pointer[T]` and `atomic.Value` as unproven -> rejected until T-sendability + linear store/swap discipline is specified
Root Cause
compiler/crates/hy-check/src/foreign.rs:foreign_named_typechecksname.starts_with("atomic.")and unconditionally returnsSome(TypeShape::Atomic)(Class 2 sendable) instead of restricting Class 2TypeShape::Atomicto scalar atomic types (atomic.int32,atomic.int64,atomic.uint32,atomic.uint64,atomic.uintptr,atomic.bool).compiler/crates/hy-check/src/foreign.rs:method_resultreturnsSome(TypeShape::Primitive)wheneverrecv_type.starts_with("atomic."), treatingp.load()on anatomic.pointer[T]as a primitive copy.
Activity
Merge pr-52 (ocakciomursel-pixel, fixes limitlessprojects#51): atomic…
test(checker-corpus): add #51 shadow-predeclared-struct-reject (fixes #…