Phase 6A: .aji layer 2 (structs, enums, exhaustive match)

Owner rules: struct/enum declarations in Rust form; one construction
form each (named struct literal, Enum::Variant); struct fields lowered
in declaration order, so field order in the source does not change the
AIR (golden test with two orders, one AIR); match over enums exhaustive
with no '_' (E7004 lists missing variants, E7006 for '_'), integer
match needs '_'; payload names scoped to their arm (enum.switch block
parameters); match as an expression with a merge block; arm-level
source map; no destructuring, guards or nested patterns. Type inference
limits written into spec 15 (one function, monomorphic, no search,
E7007). aji lower --stats: source/AIR size and expansion ratio.

Tests: 4 run (one shared golden), 7 rejects incl. verifier-caught E1003.
This commit is contained in:
dev committed 2026-10-05 11:31:56 +03:00
1 parent ba3e9b3719
commit 0fdd04179b
22 files changed
+702 -121

No files matched your search

+8 -3
View File
@@ -31,8 +31,8 @@ effects [io.read, io.write]
|---|---|
| `u8 … u128`, `usize`, `i8 … i128`, `isize`, `bool` | no implicit conversion |
| `[T; N]` | array; `[e; N]` repeats `e` |
| `type P = struct { a: u8, b: u8 }` | `P { a: 1, b: 2 }`, `p.a` |
| `type E = enum { A, B(u64), C(u8, u8) }` | `E.B(4)`; `match` arms `A`, `B(x)`, `C(x, y)`, `_` |
| `struct P { a: u8, b: u8 }` | `P { a: 1, b: 2 }` (every field, any order), `p.a` |
| `enum E { A, B(u64), C(u8, u8) }` | `E::A`, `E::B(4)`; `match` with one arm per variant: `E::A => …`, `E::B(x) => …`, `E::C(x, y) => …` (no `_`) |
| `ref<T>`, `mut<T>`, `slice<T>`, `slice_mut<T>` | borrows (§4) |
| `own<T>`, `own_array<T>`, `region` | heap and regions (§6) |
| `cap<K>` | authority; kinds below |
@@ -54,6 +54,11 @@ for i in 0..n { … } // 0 ≤ i < n
loop { … break; … continue; … }
return v; trap; assert(c);
let y = if c { 1 } else { 2 }; // value-producing if/match: tail expression without `;`
let w: u64 = match m { // enum match: exhaustive, one arm per variant
Message::Stop => 0,
Message::Value(x) => x, // x exists only in this arm
};
match d { 0 => { … } 1 => { … } _ => { … } } // integer match: `_` required
```
| Operation | Meaning |
@@ -197,7 +202,7 @@ scope s { // every task spawned in s must
| E7001 | syntax | check `;`, braces, `=>` in `match` |
| E7002 | unknown name | spelling; declare the variable or function |
| E7003 | linear value consumed without `move` | write `move x` (or borrow it with `ref`/`mut` if it must stay) |
| E7004 | `match` not exhaustive | add the missing outcome/variant arm or `_` |
| E7004 | `match` not exhaustive | add the arms listed in `missing` (integers: add `_`) |
| E7005, E1001 | type mismatch | convert with `as`, `as!`, `as%`; check borrow vs value |
| E7007 | ambiguous literal | add a suffix (`0u64`) or a type annotation |
| E2101 | conflicting borrows | end the first borrow earlier with an inner `{ }` block |