Files
aji/docs/rfcs/0004-air-instruction-set.md
T
dev c7c5e4f521 plan: Phase 0 exit review (P0-13)
- all Phase 0 tasks done; exit criterion met (41 conformance tests,
  run records compared across two runs)
- RFC 0004 Amendment 1 documents format-0 additions; status stays
  Proposed pending owner acceptance
- open question Q-019: non-terminating programs in test tooling
- README/CONTRIBUTING: current state and `aji run`
2026-10-04 12:33:17 +03:00

2.6 KiB

RFC 0004: AIR Instruction Set

Status: Proposed
Target: Aji 0.1

Goal

AIR should be small enough for complete semantic definitions to fit in an agent context while remaining expressive enough for systems software.

Principle

Do not add instructions because they make source syntax convenient. Add an AIR instruction only when it represents a distinct semantic/verifier operation.

Initial instruction families

Pure values

const copy move
integer arithmetic
bitwise operations
comparisons
casts with explicit failure/semantics

Control

br cbr switch ret trap guard assert

Memory

borrow.ref borrow.mut borrow.end
load store
slice.make slice.sub
mem.copy mem.zero

Ownership

own.alloc own.free
region.create region.alloc region.reset region.destroy
island.create island.alloc island.freeze
arc.clone arc.release

Resources and calls

call call.indirect intrinsic.call
resource.consume

Concurrency

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

Required metadata

Each opcode definition must declare:

syntax
operand types
result types
ownership transfer
borrow transfer
memory read/write set
sync relation
required effect
required capability
trap cases
verifier transfer function
interpreter behavior

Binary stability

AIR opcodes should receive stable numeric IDs only after the semantics of v0.1 freeze. Before then, text AIR is the safer canonical interchange for development.

Amendment 1 — format version 0 (Phase 0)

Status: Proposed, implemented in the reference implementation.

Format version 0 (spec 07 §8, spec 07a) realizes the "pure values" and "control" families and adds the following, each a distinct verifier operation rather than syntax sugar:

Addition Why it is a distinct operation
cast.widen / cast.checked / cast.wrap the three cast semantics differ in verifier obligations (static losslessness, runtime trap, none)
struct.make, struct.get nominal aggregate construction and projection need their own typing rules
enum.make, enum.switch tagged unions: exhaustiveness is checked by the CFG pass and payloads bind to block parameters, so no separate "get payload" instruction can observe an inactive variant

Not yet realized: memory, ownership, resources, calls through values (call.indirect) and concurrency families; they arrive with their phases and are specified in spec 07a first.