rfc: 0015 scalar atomics and the Aji memory model accepted (revision 2) and integrated into the spec
The Aji RC11 profile (RC11 with NO-THIN-AIR; stronger than ISO C11/C++20) as normative axioms in spec 04 §20; DRF-SC; linear atomic<T> for AtomicScalar with atomic.new/atomic.take; ref<atomic<T>> operands; ordering tables incl. cmpxchg failure table and two results; effects [atomic] / [atomic, atomic.weak]; target atomic_widths and E4203; E4202; enumerator as oracle (observed ⊆ allowed, exact equality on the normative litmus corpus). Feature atomics stays reserved until P5-2a. Q-015 resolved; record/replay and Q-017 moved to Phase 8. RFC 0003 superseded. AIR bundle +1.9 %.
This commit is contained in:
1 parent
702d69b2c1
commit
2bbbd2135c
24 files changed
+927
-142
No files matched your search
@@ -177,7 +177,7 @@ Lowering: structured control flow becomes blocks and terminators. A variable ass
|
||||
| `s[i]` | element value (borrow, load, end) |
|
||||
| `s.len` | `slice.len`, or the static length of an array |
|
||||
| `s[a..b]` | a sub-slice (`slice.sub` with start `a`, length `b - a`); a borrow, so it is bound or passed, never a value |
|
||||
| `let (left, right) = s.split_at(k);` | `slice.split`: two disjoint borrows of `s`; the only multi-result binding. There is no general tuple destructuring. |
|
||||
| `let (left, right) = s.split_at(k);` | `slice.split`: two disjoint borrows of `s`. Besides `atomic.compare_exchange` (§12), the only multi-result binding. There is no general tuple destructuring. |
|
||||
| `slice.copy(mut dst, ref src)` | `slice.copy`, the only copy form |
|
||||
|
||||
**Writes.**
|
||||
@@ -432,3 +432,37 @@ Lowering is deterministic: the same source and compiler give byte-identical AIR,
|
||||
- Sizes count code only: non-empty lines that are not comments (`//` in source, `;` in AIR), each with its newline.
|
||||
- `mechanical_air_eliminated_raw` = 1 − `source_bytes` / `air_bytes`: how much of the AIR text the author did not write. This is the main engineering metric.
|
||||
- `mechanical_air_eliminated_normalized` = 1 − `source_bytes` / `air_bytes_normalized`: the same against AIR in which every byte-string materialization counts as one logical constant operation. Such a materialization is the instructions from the string's `local.zero` to its final `borrow.end`, a store per non-zero byte, because format 0 has no byte-array constant. It is replaced by the single notional line ` const.bytes %<storage>, <literal>`, where `<literal>` is the canonical spelling: printable ASCII as is, otherwise the escapes `\n \r \t \0 \\ \" \xNN`. The storage's `local.alloc` is real frame storage and stays. No other instruction is normalized. The rule is the same for every program, and `byte_string_constants` reports how many were replaced.
|
||||
|
||||
## 12. Atomics
|
||||
|
||||
Spec 04 §20–§30, §42; layer 10, RFC 0015. This layer is specified now and implemented in Phase 5, together with the publication of feature `atomics`. Until then the frontend rejects it as an unknown construct. The section enters the Source Reference Bundle with the implementation (P5-9a).
|
||||
|
||||
| Source | AIR |
|
||||
|---|---|
|
||||
| `atomic<T>` (`T` AtomicScalar) | `atomic<T>`; linear, borrowed in place like a mutex |
|
||||
| `let a = atomic.new(v);` | `atomic.new` |
|
||||
| `let v = atomic.take(move a);` | `atomic.take`; needs no live borrow of `a` |
|
||||
| `atomic.load(c, o)` | `atomic.load.<o>` |
|
||||
| `atomic.store(c, v, o);` | `atomic.store.<o>` |
|
||||
| `atomic.swap(c, v, o)` | `atomic.xchg.<o>` |
|
||||
| `atomic.add.wrap(c, v, o)`, `atomic.sub.wrap(c, v, o)` | `atomic.add.wrap.<o>`, `atomic.sub.wrap.<o>` |
|
||||
| `atomic.and(c, v, o)`, `atomic.or(c, v, o)`, `atomic.xor(c, v, o)` | `atomic.and.<o>`, `atomic.or.<o>`, `atomic.xor.<o>` |
|
||||
| `let (old, exchanged) = atomic.compare_exchange(c, expected, desired, s, f);` | `atomic.cmpxchg.<s>.<f>`, the second multi-result binding |
|
||||
| `atomic.fence(o);` | `atomic.fence.<o>` |
|
||||
|
||||
The cell operand `c`:
|
||||
|
||||
- `c` is a `ref<atomic<T>>` binding or parameter, or a temporary `ref a` of an `atomic<T>` written as the argument.
|
||||
- Passing the atomic itself, without `ref`, is `E7005`. So is writing `mut`.
|
||||
- To share a cell with tasks, bind `ref c = a;` and pass `c`.
|
||||
|
||||
The orderings:
|
||||
|
||||
- They are the bare words `relaxed`, `acquire`, `release`, `acq_rel`, `seq_cst`, written last.
|
||||
- They are not values: they cannot be bound, passed or computed (`E7006`).
|
||||
- A word outside the operation's row is the verifier's `E4201`, reported at the ordering.
|
||||
|
||||
Other rules:
|
||||
|
||||
- `*c` and any other ordinary read of a cell is `E4202`.
|
||||
- Effects are declared by the programmer (spec 05 §13).
|
||||
Reference in new issue
Block a user