atomics A.0a: lib + IR ops + recognizer, emit bails (lock commit)

Stream A (atomics) foundation. Net-new atomic load/store codegen path, wired
end-to-end except LLVM emission, which deliberately bails loudly so the example
locks to a clean diagnostic (A.0b turns it green — cadence: no commit both adds a
test and makes it pass).

- library/modules/std/atomic.sx: Ordering enum, Atomic($T) transparent wrapper
  (init/load/store, seq_cst-only for now), atomic_load/atomic_store #builtin
  intrinsics. Opt-in import, NOT in the universal std facade (Ordering in the
  prelude grows every program's type table + churns 37 .ir snapshots).
- IR: atomic_load/atomic_store ops + AtomicOrdering (all 5) + structs (inst.zig);
  print arms; comptime_vm arms reuse load/store (single-thread correct);
  recognizer tryLowerAtomicIntrinsic (const-ordering + scalar-size guards, both
  loud); emit dispatch -> emitAtomicLoad/Store bail via comptime_failed.
- examples/1700-atomics-load-store.sx locked to the bail diagnostic.

Full ordering surface (a.load(.acquire)) blocked on comptime-constant ordering
propagation (comptime enum value params) — A.0.5, migrated not legacy.
This commit is contained in:
agra
2026-06-20 08:47:07 +03:00
parent ad1687c692
commit 22af40413d
14 changed files with 473 additions and 0 deletions

View File

@@ -670,6 +670,20 @@ pub const Vm = struct {
try self.writeField(table, frame.get(s.ptr.index()), vty, frame.get(s.val.index()));
return .{ .value = 0 }; // store has a void result but still occupies a Ref slot
},
// Comptime is single-threaded, so seq_cst is trivially satisfied —
// atomic load/store are ordinary load/store here (the ordering is
// a no-op at comptime). Mirrors the design (§3): the interp needs no
// atomics machinery.
.atomic_load => |a| {
const table = try self.requireTable();
return .{ .value = try self.readField(table, frame.get(a.ptr.index()), ins.ty) };
},
.atomic_store => |a| {
const table = try self.requireTable();
const vty = if (a.val_ty != .void) a.val_ty else (try self.refTy(ref_types, a.val));
try self.writeField(table, frame.get(a.ptr.index()), vty, frame.get(a.val.index()));
return .{ .value = 0 };
},
.struct_init => |agg| {
const table = try self.requireTable();
const sty = ins.ty;