Removes SSA, block parameters, CFG, borrow ends, frame-storage placement and the features header; keeps move, borrows, allocation, resources, capabilities, effects, tasks, channels, locking, cancellation and every fallible outcome explicit. Lowers to the same AIR and verifier. Decisions D1-D7 requested (lock block, lexical borrows, explicit move, frontend frame storage, explicit effects, familiar surface, E7xxx).
17 KiB
RFC 0013: The .aji Source Language, Phase 6A
Status: Proposed
Scope: source language .aji 0.1 for the semantics of AIR format 0 features of Phases 0–3; no change to AIR, the verifier or the runtime
Language version: 0.1
Supersedes: the grammar sketch in reference/grammar.ebnf
Decision context: the native smoke (docs/evaluation/results/2026-10-05-native-smoke.md) found that agents writing Aji pay mostly for representation, not semantics:
- SSA and CFG diagnostics outnumbered safety diagnostics about 3:1 for the weaker agent;
- strong agents produced no safety diagnostics at all;
- AIR solutions were about 3× the size of Rust;
- the 33k-token reference was read in full.
The owner brought Phase 6 forward as Phase 6A.
Motivation
AIR is the normative, machine-facing format: SSA values, block parameters, explicit terminators, explicit borrow.end, a features header. Each of these is mechanical bookkeeping that a compiler does better than a model. None of them carries a safety decision. Writing them by hand costs agents tokens, repair cycles and output length, and it hides whether Aji's semantics help.
Phase 6A gives agents a source language whose only job is to remove that mechanical work:
.ajiremoves mechanical work but never hides a semantically significant action.
The frontend lowers .aji to AIR, and the existing verifier checks that AIR. The safety guarantees are therefore exactly those of AIR format 0. The frontend is outside the trusted computing base (spec 01 §8, spec 00).
Invariants
- Same semantics. Every
.ajiprogram means exactly the AIR it lowers to. There is no source-only runtime behavior, no source-only type rule that admits a program the verifier would reject, and no feature beyond the published AIR features of Phases 0–3. - Visible significant actions. These stay written in the source at the point where they happen:
- move of a linear value;
- shared and exclusive borrow;
- heap and region allocation;
- resource consumption (close, free, take);
- capability use;
- the effect list;
- task spawn and join;
- channel send and receive;
- locking;
- cancellation points and shields;
- every fallible outcome.
- Invisible mechanics. The frontend generates the rest:
- SSA values, block parameters and the CFG;
- the end of a borrow at the end of its lexical scope;
- frame storage for variables that are borrowed;
- the
features [...]header (the closure of what is used); - array and byte literals;
- intermediate values.
- Determinism. Lowering is a pure function: the same source gives byte-identical canonical AIR.
- Traceability. Every AIR instruction carries the source span it came from. Every verifier diagnostic on lowered AIR is reported at a source span, with the same code.
1. Lexical structure and items
The surface deliberately follows Rust and Zig where their meaning matches Aji. Agents bring strong priors for that syntax, and the source reference stays small. Where the meaning differs, Aji uses a keyword rather than a familiar symbol with an unfamiliar meaning.
module echo
type Pair = struct { a: u8, b: u8 }
type Shape = enum { Empty, Square(u64), Rect(u64, u64) }
fn main(input: cap<io.read>, out: cap<io.write>) -> void
effects [io.read, io.write]
{
...
}
- One module per file,
module <path>. There are no imports in 6A. - Line comments start with
//. - Types use the AIR spellings:
u8…i128,usize,isize,bool,void,never,ref<T>,mut<T>,slice<T>,slice_mut<T>,own<T>,own_array<T>,region,cap<K>,file<read>and so on,task<T>,sender<T>,receiver<T>,mutex<T>, built-in enums. Two exceptions:- arrays are written
[T; N]; - a function-bound type (
scope,shield,guard<T>) is never written; it exists only through the block forms of §5.
- arrays are written
effects [...]is written exactly as in AIR (decision D5).
2. Values, variables and control flow
let n = a + b // immutable binding: an SSA value
var i: usize = 0 // a variable: SSA with block parameters, or frame storage if borrowed (§3)
i = i + 1
if i < n { ... } else { ... }
while i < n { ... }
loop { ... break ... continue ... }
match shape { Empty => ..., Square(s) => ..., Rect(w, h) => ... } // enum.switch, exhaustive
match code { 0 => ..., 1 => ..., _ => ... } // switch.<int>
return x
trap
assert(c)
Lowering: if, while, loop and match become blocks, cbr, br, enum.switch and switch. A var that is assigned on several paths becomes a block parameter at the join. The agent never writes SSA, a block or a terminator.
Arithmetic keeps AIR's explicit modes:
| Source | AIR |
|---|---|
a + b, a - b, a * b, a / b, a % b |
.checked (traps T0003/T0004) |
a +% b, a -% b, a *% b |
.wrap |
&, |, ^, <<, >>, ==, !=, <, <=, >, >=, and, or, not |
bit, shift, compare and boolean operations |
x as T |
cast.widen (accepted only where widen is lossless) |
x as! T |
cast.checked (traps T0006) |
x as% T |
cast.wrap |
Structs and enums:
Pair { a: 1, b: 2 },Shape.Square(4);p.aon a value isstruct.get.
Integer literals take their type from context, or from a suffix (1u8).
3. Borrows and frame storage
var buf: [u8; 64] = zero // frame storage (local.alloc + local.zero)
let s = mut buf // exclusive borrow: borrow.mut, slice.make where a slice is needed
let r = ref buf // shared borrow
let x = *r // load
*s = v // store (through mut<T>)
let e = mut s[i] // borrow.index (checked, traps T0008), or .proven under a dominating `if i < s.len`
let (l, r) = s.split_at(k) // slice.split
let part = s[a..b] // slice.sub
copy(dst, src) // slice.copy
s.len // slice.len
let f = mut p.field // borrow.field
- Borrows are created explicitly with
refandmut, the same keywords as the borrow types. - A borrow ends at the end of the lexical block that binds it, on every path out of the block: fall-through,
break,continue,return. A temporary borrow inside an expression ends at the end of its statement. The frontend emitsborrow.endin reverse order of creation. A borrow that must end earlier is put in an inner block{ … }(decision D2). - Frame storage is chosen by the frontend. A
varwhose address is taken byreformutbecomeslocal<T>storage in the entry block; all other variables are SSA (decision D4). - Returning a borrow keeps the AIR rule:
fn first(s: slice<u8>) -> ref<u8> from s { … }.
The verifier still checks every borrow. The frontend only removes the bookkeeping: an agent who writes a conflicting borrow gets E2101 at the source span of the second borrow.
4. Ownership, resources, allocation and fallible operations
Moves are explicit. A linear value is consumed only by writing move x (decision D3):
close(move f)
let v = take(move o)
spawn(s, worker, move job)
Using a linear value without move is a source diagnostic. Using it after a move is E2001, after it was consumed E3001, a second consumption E2002, and never consuming it E3002. These are the AIR codes, reported at source spans.
Fallible operations are match expressions over their AIR outcomes. The arm names are the AIR edge roles, and the match must be exhaustive:
match io.stdin_read(input, mut buf) {
ok(n) => { ... }
err(e) => { trap }
}
let o = match own.new(heap, Pair { a: 1, b: 2 }) {
ok(o) => o,
err(e) => return Status.OutOfMemory,
}
let n = io.stdin_read(input, mut buf) or trap // shorthand: any non-ok outcome traps
or trap is the only shorthand, and it is explicit. 6A has no ?: AIR format 0 has no Result type to propagate (open question O1).
Intrinsics and allocation keep their AIR names and operand order: fs.open_read(c, path), net.accept(mut l), own.new(heap, v), region.create(heap), region.new(ref r, v), cap.narrow.prefix(c, path).
Byte literals. b"127.0.0.1:7" is a [u8; 11] value. Used where a slice<u8> is expected, the frontend materializes it in frame storage. This removes byte-by-byte construction (the AIR TCP echo spends about 60 lines on an address).
5. Tasks, cancellation, channels, select and mutex
Block forms make the function-bound values of RFC 0011 and RFC 0012 lexical. Their structure is visible in the source, and the frontend emits the begin and end instructions:
scope s { // task.scope.begin … task.scope.end
let a = spawn(s, square, mut left) // task.spawn; lends `left` until the join
let b = spawn(s, square, mut right)
let x = join(move a) // task.join
let y = join(move b)
} // a task not joined here is E4301
shield { ... } // task.shield.begin … task.shield.end (nesting by construction)
match check_cancel() { ok => ..., cancelled => ... }
match join_cancel(move t) { ok(v) => ..., cancelled(t) => { cancel(t); let v = join(move t) } }
match channel.make<u64>(2, heap) { ok(tx, rx) => ..., err(e) => ... }
let tx2 = dup(ref tx)
match send(mut tx, move v) { ok => ..., closed(v) => ..., cancelled(v) => ... }
match recv(mut rx) { ok(v) => ..., closed => ..., cancelled => ... }
close_sender(move tx)
match close_receiver(move rx) { ok => ..., pending(rx) => ... }
select {
recv(mut a) { ok(x) => ..., closed => ... }
send(mut b, move job) { ok => ..., closed(job) => ... }
cancelled(job) => ...
}
let m = mutex(0u64) // mutex.make
lock ref m as counter { // mutex.lock; `counter: mut<u64>` (mutex.borrow)
*counter = *counter + 1
} cancelled { ... } // the lock's cancelled edge
let v = take_mutex(move m) // mutex.take
- Values coming back on an edge are bound by name, as in AIR, where they are block parameters.
closed(v)rebinds the returnedv. Inselect, the arms bind the send values that were not sent, in the order of their first appearance. lock … as x { … }unlocks at the end of the block on every path out of it (decision D1). The critical-section rule (E4304) is unchanged: a waiting operation inside the block is rejected at its source span.scopeandshieldblocks end their scope or shield at the end of the block. A task that is not joined is stillE4301.
6. The features header and effects
The frontend computes the features [...] header: the dependency closure of the constructs a module uses. It always declares effects, so effect lists are checked. E0006 therefore cannot arise from .aji source.
Effects stay declared by the programmer (decision D5). A missing effect is E3101 at the source span of the operation. Its fields name the effect and the canonical effect list the function needs.
7. Diagnostics
| Diagnostic | Source |
|---|---|
verifier diagnostics (E1xxx–E6xxx) |
the lowered AIR, reported with the same code at the source span of the instruction, with an air field pointing at the AIR location |
| trap records | function, block and instruction plus the source span |
Source-only problems get codes in a new range, E7xxx (decision D7):
| Code | Kind | Meaning |
|---|---|---|
| E7001 | source.syntax | malformed .aji source |
| E7002 | source.unknown_name | undefined variable, function, type, field or variant |
| E7003 | source.missing_move | linear value used without move |
| E7004 | source.not_exhaustive | match over an outcome or enum misses an arm |
| E7005 | source.type_mismatch | an expression has the wrong type in source position (reported before lowering) |
8. Tooling
| Command | Does |
|---|---|
aji check file.aji |
parse, lower, verify; diagnostics at source spans |
aji run file.aji |
the same, then run, exactly like aji run file.air |
aji lower file.aji |
print the canonical AIR, for inspection and as the bridge to every AIR tool |
9. Agent Reference Bundle
The two conditions get separate bundles:
Aji/sourcegets a source bundle: the.ajireference (this RFC's §1–§8 as normative text), the semantic rules agents must reason about (borrows, linearity, resources, effects and capabilities, tasks, channels, mutex, cancellation) stated in source terms, and the diagnostics table. It contains no AIR syntax.Aji/AIRkeeps the current bundle.
Both start from a quick reference of 5–8k tokens with an index into the full material.
Valid example
The echo program of the dev task, 13 lines against about 35 lines of AIR:
module echo
fn main(input: cap<io.read>, out: cap<io.write>) -> void
effects [io.read, io.write]
{
var buf: [u8; 64] = zero
loop {
let n = io.stdin_read(input, mut buf) or trap
if n == 0 { return }
io.stdout_write(out, ref buf[0..n]) or trap
}
}
Rejected examples
let f = fs.open_read(c, b"log") or trap
read_all(f) // E7003: `f: file<read>` is linear; write `move f` or borrow it with `mut f`
lock ref m as v {
match recv(mut rx) { ... } // E4304 at this span: waiting while the lock is held
}
let r = mut buf
let s = ref buf // E2101 at this span: `buf` is exclusively borrowed by `r` (line …)
Agent complexity impact
- New concepts: none in semantics. The source spellings of existing operations, lexical borrow scopes, block forms, outcome
match, andmove. - New verifier state: none. The frontend has its own state: names, types, liveness, scopes.
- Repairability:
- SSA, CFG, block-arity and header diagnostics disappear;
- borrow-end bookkeeping (
E2105,E2106) largely disappears; - the remaining diagnostics are the semantic ones, at source spans.
- Bundle: a separate source bundle for the condition
Aji/source. Target: about half of the AIR bundle, with a 5–8k quick reference. - Targets, measured on dev tasks:
| Quantity | Target |
|---|---|
| source size | ≤ 1.5× Rust |
| output tokens | ≤ 2× Rust |
| hand-written SSA/CFG diagnostics | ≈ 0 |
E0006 |
0 |
Compatibility
There is no change to AIR format 0, the verifier, the runtime or any published feature. .aji 0.1 is new. Spec 00 allows source syntax to change between 0.x releases.
Spec integration (on acceptance)
- a new spec file
15-source-language.md(normative for.aji0.1); reference/grammar.ebnfreplaced by the 6A grammar;reference/error-codes.mdgainsE7001–E7005;- spec 01 §3–§5 examples updated to 6A syntax;
docs/agent/gains the source bundle and the quick reference.
Implementation (after acceptance)
The frontend lives in src/frontend/: lex, parse, resolve, check, lower, spans. Conformance gains a .aji twin for every Phase 0–3 run and reject test. A twin must give the same outcome or code, and the twins together are the exit criterion. Reference programs and examples are ported to .aji. Dev tasks M and C serve as the Aji/AIR vs Aji/source regression.
Alternatives considered
- Smarter AIR tooling, e.g. auto-inserted
borrow.endor SSA repair: keeps the agent in a compiler IR. The measured cost is the IR form itself. - Inferring moves and borrows Rust-style: less text, but the significant actions become invisible, which invariant 2 forbids. Explicit
move,refandmutcost a few tokens and are where the reasoning is. - Inferring effects: violates "effects are part of the public contract" (AGENTS.md).
- A new surface unlike any known language: wastes the agents' priors and makes the bundle bigger.
Decisions requested
- D1 — lock as a block (
lock ref m as x { … } cancelled { … }, unlock at block exit). The alternative is explicitunlock(move g)with guard values. Proposal: the block. It makes the guard lexical, which matches the critical-section rule, and removes a leak class. - D2 — lexical borrow scopes. A borrow ends at the end of its block; earlier ends use an inner block. The alternative is an explicit
end(r). Proposal: lexical, with no explicit end in 6A. - D3 —
moverequired for every consumption of a linear value. Proposal: yes. Ownership transfer is the reasoning Aji externalizes. - D4 — frame storage chosen by the frontend for borrowed variables. Proposal: yes. Frame storage is static and not an allocation in the sense of spec 01 §2.
- D5 — effects stay explicit. Proposal: yes, with
E3101naming the full list the function needs. - D6 — Rust/Zig-like surface to use model priors, with keywords where the meaning differs (
ref,mut,move,or trap,as!,as%,+%). Proposal: yes. - D7 — the
E7xxxrange for source-only diagnostics, and the AIR codes for everything the verifier decides. Proposal: yes.
Open questions
- O1.
?-style propagation needs a result type in AIR (a later feature). 6A offersmatchandor traponly. - O2. Methods and generics, for example
s.lenandchannel.make<u64>, are spelled as fixed built-in forms in 6A; user-defined generics belong to the full Phase 6.