Repository navigation
Description
The idea, in a paragraph
Directly answering Active Solicitation Prompt 4 in MOONSHOT.md ("'Impossible' guarantees... pick a guarantee GUARANTEES.md explicitly does not make and argue it is reachable") and resolving the open [TBD] gap recorded in GUARANTEES.md Row 11:
Introduce atomic.Box[T] as a first-class Sendable Class 2 type that elevates hardware atomic operations into compile-time ownership transfer boundaries. In PR #52 (issue #51), atomic.Pointer[T] and atomic.Value were demoted from Sendable Class 2 to unproven HYB-E3005 fail-closed because "the atomic makes the pointer swap race-free, NOT the pointee." Today, lock-free concurrency (Treiber stacks, Michael-Scott queues, RCU epoch updates, and atomic buffer swaps) is 100% impossible in Go-Hybrid without taking the managed("...", "atomic") permit, which strips all soundness guarantees (Row 8). atomic.Box[T] solves this by enforcing Exchange Linearity: box.swap(move new_val) consumes the caller's ownership of new_val and returns old_val with exclusive, unaliased ownership transferred to the caller; box.compare_and_swap(expected, move new_val) transfers ownership strictly on success. Hardware LOCK CMPXCHG becomes the ownership handoff mechanism, allowing lock-free data structures to run at hardware speed (~10 ns vs 80 ns for channels) with zero data races on the underlying pointee.
Which assumption it breaks
- Breaks the assumption in
GUARANTEES.mdRow 11: That non-scalar atomic pointers cannot guarantee pointee race-freedom and must remain unproven (HYB-E3005fail-closed) indefinitely. - Breaks the assumption in
SPEC-LANGUAGE.md §8.4 C8andcompiler/crates/hy-check/src/sendability.rs: That concurrent communication between tasks must strictly occur via channel value copies or permanent freeze-on-send.atomic.Box[T]allows a shared concurrent cell across tasks while guaranteeing that at any single point in time, exactly ONE task holds an alias to the underlying pointee. - Breaks the dichotomy between "Channels only" and "Unsound
managedblocks": Eliminates the performance cliff where developers must either pay the channel scheduler overhead (goroutine parking, channel locks, buffer allocations) or abandon all compiler soundness checks viamanaged("...", "atomic").
Why this is a breakthrough, not an increment
A standard feature bounty cannot solve this: PR #52 demonstrated that simply treating atomic.Pointer[T] as sendable causes silent data races under go run -race because multiple goroutines can call .Load() on the atomic pointer and concurrently mutate the returned *T. That is why the maintainer kicked it out.
The breakthrough is recognizing that atomic swap instructions are the exact hardware equivalent of linear ownership transfers:
- In standard Go
sync/atomic.Pointer[T],.Load()permits unbounded fan-out of shared mutable pointers. - In
atomic.Box[T],.load()is statically forbidden on mutable types (or restricted strictly to deeply immutable/frozen types, Class 1/4). - For mutable types (
map,slice, pointer to struct), access is permitted strictly via atomic exchange:// Thread A transfers exclusive ownership of task_data into the atomic box: old := box.swap(move task_data) // Thread A's task_data is marked moved_at (HYB-E3003 prevents local reuse). // Thread A now exclusively owns 'old' (transferred from the box).
Because swap atomically writes the new pointer while extracting the old pointer, no two tasks can ever observe or dereference the same pointee simultaneously. The hardware memory bus guarantees mutual exclusion, and Tier-0's lexical move checker guarantees single-ownership handoff.
This unlocks lock-free algorithms in Go-Hybrid:
- Lock-free queues & stacks: Nodes are popped via atomic swap/CAS; the popping task receives exclusive ownership to process and mutate the node with zero lock contention and zero data races.
- Double-buffering & RCU: Workers atomically swap active render/write buffers in 10 ns without channels or mutexes.
How we would know it works (or doesn't)
We pre-register two falsifiable milestones and concrete kill criteria:
Milestone 1 (Feasibility Spike — Zero-Race Lock-Free Proof, no compiler rewrite required):
- Implement
atomic.Box[T]in pure Go (runtime/go/hyatomic/box.go) using Go'ssync/atomic.Pointerwith runtime exchange checks:Swap(new_val *T) (old_val *T)CompareAndSwap(expected *T, new_val *T) (swapped bool, acquired *T)
- Build an adversarial lock-free test suite:
- Case A (Treiber Stack): 64 concurrent tasks pushing and popping 1,000,000 dynamically allocated mutable structs (
type Node struct { Payload map[string]int; Next *Node }). Each popping task mutatesPayload["count"]++immediately after pop. - Case B (Buffer Swapper): 16 producer tasks and 16 consumer tasks swapping mutable byte buffers.
- Case A (Treiber Stack): 64 concurrent tasks pushing and popping 1,000,000 dynamically allocated mutable structs (
- Run under
go test -race -count=1000 -cpu=8,16,32. - Falsification Gate for M1:
- G1 (Race Freedom): If
go test -racereports a SINGLE data race on any pointee field across 1,000,000 operations, the linear exchange hypothesis is invalid → proposal dies, publish failure log to MOONSHOT.md. - G2 (Performance Budget): Single-thread uncontended swap latency must be < 15 ns (vs ~85 ns for an unbuffered channel ping-pong). If hardware atomic exchange overhead exceeds 30 ns, the performance justification fails → proposal dies.
- G1 (Race Freedom): If
Milestone 2 (Checker Typing & Corpus Flipping):
- Register
atomic.Box[T]inhy-checkas Sendable Class 2 (inherently sendable acrosstaskandchanwithoutmove). - Add exchange-legality checks in
compiler/crates/hy-check/src/loans.rsandsendability.rs:box.swap(v)requiresmove v(rejectsHYB-E3001ifvis not moved).box.load()on a mutableTrejects withHYB-E3007(cannot load shared mutable pointer without exchange).box.compare_and_swap(exp, v)requiresmove v.
- Add 4 regression tests to the test suite:
atomic_box_swap_accepts_and_moves(ACCEPT)atomic_box_swap_without_move_rejects_e3001(REJECT)atomic_box_load_on_mutable_rejects_e3007(REJECT)atomic_box_treiber_stack_e2e_race_clean(ACCEPT +go run -race)
- Deliverable: Publish the learning report to
MOONSHOT.mdand flip GUARANTEES.md Row 11 from[TBD]/ "No claim yet" to "Guaranteed: Race-free lock-free ownership exchange via atomic.Box[T]".
Cost honesty (optional but powerful)
- What gets added:
runtime/go/hyatomic/(~150 LOC of pure Go wrappingsync/atomic.Pointer[T]).- Sendable Class 2 classification for
atomic.Box[T]incompiler/crates/hy-check/src/sendability.rs(~40 LOC). - Method shape validation in
compiler/crates/hy-check/src/shape.rsforswapandcompare_and_swap(~60 LOC).
- What gets deleted / avoided:
- Deletes the need for
managed("...", "atomic")in lock-free code. - Eliminates the
[TBD]footnote inGUARANTEES.mdRow 11.
- Deletes the need for
- What does NOT break:
- Zero breaking changes to existing programs.
atomic.Int64,atomic.Boolremain Class 2 scalars. - Standard Go
sync/atomic.Pointerremains unproven (HYB-E3005), preserving the safety fence established in PR fix(hy-check): treat atomic.pointer[T] and atomic.value as unproven per GUARANTEES row 11 (HYB-E3005) #52.
- Zero breaking changes to existing programs.
Bounty Payout Wallet Address (if accepted for M1 / M2)
- USDT (TRC-20 / Tron):
TJtkXjcJT5MuCcSxUCU8tkJqQYJAfHVq1d
Track terms
- I understand no prototype is required and failure-with-knowledge is a valid, paid outcome
- I understand all outcomes (including declines and failures) are published in MOONSHOT.md
Activity
dancerdan15 commentedon Oct 23, 2026
/attempt #833