Draft specification, RFCs, reference registries and examples, plus the reference-implementation skeleton: build.zig, diagnostic envelope with error-code registry synced to docs, aji CLI, conformance runner with seed tests, CI and contributor docs.
185 lines
2.5 KiB
Markdown
185 lines
2.5 KiB
Markdown
# 07. AIR — Aji Intermediate Representation
|
|
|
|
## 1. Role
|
|
|
|
AIR is the canonical semantic representation of Aji.
|
|
|
|
Source syntax is optional tooling. AIR is mandatory for conformance.
|
|
|
|
AIR is:
|
|
|
|
- typed;
|
|
- SSA-oriented;
|
|
- basic-block based;
|
|
- explicit about ownership and borrows;
|
|
- explicit about effects and capabilities;
|
|
- explicit about synchronization;
|
|
- deterministic to parse and verify.
|
|
|
|
## 2. Functions and blocks
|
|
|
|
Illustrative AIR:
|
|
|
|
```text
|
|
fn @sum(%a: u64, %b: u64) -> u64
|
|
effects []
|
|
|
|
entry:
|
|
%0 = add.checked.u64 %a, %b
|
|
ret %0
|
|
```
|
|
|
|
Blocks receive values through block parameters rather than implicit phi nodes:
|
|
|
|
```text
|
|
br @loop(%next)
|
|
|
|
loop(%i: u64):
|
|
...
|
|
```
|
|
|
|
## 3. Core instruction classes
|
|
|
|
### Values and arithmetic
|
|
|
|
```text
|
|
const
|
|
copy
|
|
move
|
|
add.checked
|
|
sub.checked
|
|
mul.checked
|
|
div.checked
|
|
add.wrap
|
|
sub.wrap
|
|
mul.wrap
|
|
and or xor
|
|
shl shr
|
|
eq ne lt le gt ge
|
|
```
|
|
|
|
### Control flow
|
|
|
|
```text
|
|
br
|
|
cbr
|
|
switch
|
|
ret
|
|
trap
|
|
guard
|
|
assert
|
|
```
|
|
|
|
### Borrowing and memory
|
|
|
|
```text
|
|
borrow.ref
|
|
borrow.mut
|
|
borrow.end
|
|
load
|
|
store
|
|
mem.copy
|
|
mem.zero
|
|
slice.make
|
|
slice.sub
|
|
```
|
|
|
|
### Ownership
|
|
|
|
```text
|
|
own.alloc
|
|
own.free
|
|
region.create
|
|
region.alloc
|
|
region.alloc_uninit
|
|
region.reset
|
|
region.destroy
|
|
island.create
|
|
island.alloc
|
|
island.freeze
|
|
arc.clone
|
|
arc.release
|
|
```
|
|
|
|
### Calls
|
|
|
|
```text
|
|
call
|
|
call.indirect
|
|
intrinsic.call
|
|
```
|
|
|
|
### Concurrency
|
|
|
|
```text
|
|
task.scope.begin
|
|
task.scope.end
|
|
task.spawn
|
|
task.join
|
|
task.cancel
|
|
thread.spawn
|
|
thread.join
|
|
channel.send
|
|
channel.recv
|
|
mutex.lock
|
|
mutex.unlock
|
|
rwlock.read
|
|
rwlock.write
|
|
atomic.load
|
|
atomic.store
|
|
atomic.rmw
|
|
atomic.cmpxchg
|
|
atomic.fence
|
|
```
|
|
|
|
## 4. Instruction contract
|
|
|
|
Every AIR instruction definition must specify:
|
|
|
|
- operand types;
|
|
- result types;
|
|
- ownership-state transition;
|
|
- borrow-state transition;
|
|
- memory reads/writes;
|
|
- synchronization effects;
|
|
- effect requirements;
|
|
- capability requirements;
|
|
- trap behavior;
|
|
- verifier transfer function.
|
|
|
|
## 5. No hidden semantics
|
|
|
|
AIR does not contain:
|
|
|
|
- hidden destructors;
|
|
- implicit allocation;
|
|
- implicit exception edges;
|
|
- default memory orderings;
|
|
- implicit task detachment.
|
|
|
|
## 6. Serialization
|
|
|
|
Canonical AIR should have both text and binary forms.
|
|
|
|
Binary AIR conceptually contains:
|
|
|
|
```text
|
|
HEADER
|
|
TYPE_TABLE
|
|
CONSTANT_TABLE
|
|
CAPABILITY_TABLE
|
|
FUNCTION_TABLE
|
|
BLOCK_TABLE
|
|
INSTRUCTION_STREAM
|
|
CONTRACT_TABLE
|
|
DEBUG_TABLE
|
|
```
|
|
|
|
Every binary must encode version and required feature bits.
|
|
|
|
## 7. Verification before execution
|
|
|
|
Native code must not be produced from unverified safe AIR.
|
|
|
|
Unsafe AIR modules are allowed only through explicit trusted/unsafe boundaries and must appear in the unsafe dependency report.
|