atomics A.0.5: full ordering surface (comptime $o: Ordering)
Migrate Atomic methods from seq_cst-only to the explicit ordering surface now that comptime value params work on generic-struct methods (workers3c4305f/d7a6857/d95ba0a): - atomic.sx: load/store take a comptime $o: Ordering (explicit, Rust-style; no default, matching design 4.6). a.load(.acquire) -> 'load atomic .. acquire'. - call.zig: atomicOrderingFromNode resolves a comptime-bound ordering identifier via comptimeIntNamed (+ atomicOrderingFromTag); documents the sx-Ordering <-> IR-AtomicOrdering declaration-order invariant. The per-op validity guard fires through the method path (a.load(.release) is a compile error). - 1700 migrated to explicit orderings (output unchanged 7/42/43). Suite green (715/0).
This commit is contained in:
@@ -23,11 +23,11 @@ Ordering :: enum {
|
||||
atomic_load :: ($T: Type, ptr: *T, o: Ordering) -> T #builtin;
|
||||
atomic_store :: ($T: Type, ptr: *T, v: T, o: Ordering) #builtin;
|
||||
|
||||
// NOTE (A.0): the methods bake a literal `.seq_cst` (strongest, conservative)
|
||||
// rather than taking an `o: Ordering` parameter. A runtime ordering param can't
|
||||
// reach the intrinsic as the compile-time constant LLVM requires, and comptime
|
||||
// enum value params don't exist yet — so explicit orderings (`a.load(.acquire)`)
|
||||
// land in A.0.5 once that capability does. See current/PLAN-ATOMICS.md.
|
||||
// The ordering is a COMPTIME value param (`$o`): it must be known at compile
|
||||
// time because LLVM atomic ordering is an instruction attribute, not a runtime
|
||||
// operand. It is explicit (Rust-style — no default), so the caller always states
|
||||
// the ordering: `a.load(.acquire)`, `a.store(v, .release)`. An invalid
|
||||
// combination (`a.load(.release)`) is a compile error.
|
||||
Atomic :: struct ($T: Type) {
|
||||
value: T;
|
||||
|
||||
@@ -35,11 +35,11 @@ Atomic :: struct ($T: Type) {
|
||||
return .{ value = v };
|
||||
}
|
||||
|
||||
load :: (self: *Atomic(T)) -> T {
|
||||
return atomic_load(T, @self.value, .seq_cst);
|
||||
load :: (self: *Atomic(T), $o: Ordering) -> T {
|
||||
return atomic_load(T, @self.value, o);
|
||||
}
|
||||
|
||||
store :: (self: *Atomic(T), v: T) {
|
||||
atomic_store(T, @self.value, v, .seq_cst);
|
||||
store :: (self: *Atomic(T), v: T, $o: Ordering) {
|
||||
atomic_store(T, @self.value, v, o);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user