Phase 6A: .aji layer 7 (task scopes, spawn/join, channels)

- scope s { … }: task.scope.begin, task.scope.end at every normal exit
  (scope ends generalized: borrow.end or task.scope.end, innermost first)
- task.spawn(s, f, args): call-like; named linear values moved (E7003);
  lent borrows are bound first (inline borrow E7006); scope operand E7005
- task.join/cancel/cancelled; task<T>, sender<T>, receiver<T>, scope types
- channels: make<T>, dup, send, recv, close_sender, close_receiver; send,
  recv and close_receiver are outcome matches; endpoints by name, borrowed
  for the operation and ended on every edge (written `mut tx`: E7006)
- outcome rebinding: a value coming back under the name of a variable of
  its type becomes the variable's value (pending(r))
- joins carry live variables only (pruned SSA): a linear value consumed
  before a join does not travel to it; ordered after-walk over the
  enclosing statement or tail, sibling arms not counted
- parser: a keyword after `.` is a member name (task.cancelled)
- conformance equivalence ignores schedule.choices (quantum counts AIR
  instructions)
- tests: 10 run tests with AIR equivalence (Phase 3 programs), 12 rejects
  (E4301, E4101 x2, E4002, E2001, E3101, E3002, E7006 x2, E7003, E0006,
  E7005); Quick Reference tasks/channels programs now pass
- spec 15 §4/§6/§7, grammar, quick reference, bundle notes, plan
This commit is contained in:
dev committed 2026-10-05 17:55:30 +03:00
1 parent c2c238d9b1
commit 179dee3c3a
32 files changed
+1315 -41

No files matched your search

+7 -5
View File
@@ -106,6 +106,8 @@ Statements end with `;`. Block constructs (`if`, `while`, `for`, `loop`, `match`
`if` and `match` are expressions when every branch yields a value of the same type through a tail expression (an expression without `;` at the end of a block) or diverges (`return`, `break`, `continue`, `trap`).
**Joins carry live variables only.** A variable is passed to a join (the block after an `if` or `match`, a loop header, a loop exit) only if it may be read after that join: on a later path, or, for a loop header, anywhere in the loop. A variable that is not read again is not passed on. This is ordinary pruned SSA construction, not tracking of moves. A linear value consumed before a join (`channel.close_receiver(move r)` before `break`) does not travel to it. A linear value that is read after it was consumed is still the verifier's `E2001`. The analysis is conservative: any read on a later path counts, and only a whole-variable assignment in straight-line code ends a variable's life.
**Type inference is deliberately small.** It works within one function, it is monomorphic, and it does no overload resolution or search among several admissible types. An expression's type comes from:
- its own form: a literal suffix, a name, a call's declared return type, a cast, a struct or enum constructor;
@@ -227,7 +229,7 @@ match io.stdin_read(input, mut buf) {
- **Match kinds.** The parser decides the kind of a `match` from its arms: `Enum::Variant` arms make an enum match, integer literals and `_` an integer match, and bare outcome names (`ok`, `err`, `closed`, `cancelled`, `pending`) an outcome match. Outcome names are not enum patterns. In an outcome match the scrutinee MUST be a fallible operation (`E7006` otherwise). Each outcome is matched exactly once: a repeated one is `E7006`, an unknown one `E7002`, a wrong number of bound names `E7005`. A fallible operation outside an outcome match or `or trap` is `E7006`.
- **Outcome values.** `err(e)` binds the real error value (`alloc_error`, `cap_error`, `io_error`). These built-in enums are matched like declared ones: `alloc_error::out_of_memory`, exhaustive, no `_`. A borrow bound by an outcome (the `ok(item)` of `region.new`) ends at the end of its arm. A borrow bound by `let item = region.new(arena, v) or trap;` ends at the end of the enclosing block.
- **Rebinding.** A value that comes back on an edge is rebound by the name in its arm: `closed(v)`, `pending(rx)`, `cancelled(t)`.
- **Rebinding.** A value that comes back on an edge is rebound by the name in its arm: `closed(v)`, `pending(rx)`, `cancelled(t)`. If that name is a variable (`var`) of the value's type, the value becomes the variable's new value. A receiver kept in `var r` is closed with `match channel.close_receiver(move r) { ok => …, pending(r) => … }` and received from again.
- **`or trap`.** `op(args) or trap` is the expression of the `ok` value, or of `void`. Every other outcome traps (`T0001`). It is the only shorthand.
- **Enums.** A `match` over a value of an enum type has exactly one arm per variant, each written `Enum::Variant(names…)` (`Enum::Variant` without payload). It must be exhaustive (`E7004` lists the missing variants), and `_` is not allowed (`E7006`), so a new variant cannot slip through silently. Payload names are bound only inside their arm (they are the arm block's parameters in AIR). It lowers to `enum.switch`.
- **Integers.** A `match` over an integer has literal arms and exactly one `_` arm, which is required (`E7004`). It lowers to `switch`.
@@ -246,8 +248,8 @@ scope s {
**`scope s { … }`** is `task.scope.begin` and `task.scope.end`, at every normal exit of the block. Inside it:
- `task.spawn(s, f, args)` spawns; borrow arguments are lent until the join (spec 04 §34);
- `task.join(move t)` joins;
- `task.spawn(s, f, args)` spawns `f` (a function of the module) into the scope `s`. Arguments are passed like call arguments: a named linear value is `move`d (`E7003`). A borrow argument is lent until the join (spec 04 §34), so it is a borrow binding passed by name (`mut part = buf;` … `task.spawn(s, f, part)`). A borrow or byte string written inline is `E7006`, because a temporary would have to end right after the spawn. The first operand must be the scope (`E7005`);
- `task.join(move t)` joins; its value is the task's result (`task<T>` gives `T`);
- a task that is not joined at an exit is `E4301`.
**Task operations elsewhere:**
@@ -261,9 +263,9 @@ scope s {
**Channels:**
- `channel.make<T>(n, mem)`: a match, §6;
- `channel.dup(tx)`;
- `channel.dup(tx)`: `channel.sender.dup` on a shared borrow of `tx`, made for the operation;
- `channel.send(tx, v)` (`move v` for a linear `v`);
- `channel.recv(rx)`;
- `channel.recv(rx)`; for `send` and `recv` the endpoint is borrowed `mut` for the operation and the borrow ends on every edge;
- `channel.close_sender(move tx)`;
- `channel.close_receiver(move rx)`.