Initial import: Aji 0.1 draft spec and Zig scaffolding

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.
This commit is contained in:
dev committed 2026-10-04 11:59:13 +03:00
commit 17a55a7fef
67 files changed
+4197

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
# RFC NNNN: Title
Status: Draft
Target: Aji 0.x
Supersedes: —
<!-- Status values: Draft → Proposed → Accepted → Implemented, or Rejected. See README.md. -->
## Motivation
Which of the mission goals (AGENTS.md) does this improve, and what fails today without it?
## Precise invariant
The property preserved or established, stated so that a verifier could check it.
## Normative rule changes
Exact MUST/SHOULD/MAY text to add to or replace in `docs/spec/`, with file and section.
## Verifier implications
New abstract state, transfer functions, and complexity bound.
## Interpreter / runtime implications
Runtime rule, if any. Deterministic interpreter behavior.
## AIR changes
For each new or changed instruction: operand types, result types, ownership effects, memory effects, concurrency effects, capability/effect requirements, trap behavior, verifier transfer function. Explain why it is not syntax sugar.
## Valid example
```text
```
## Rejected example
```text
```
Expected diagnostic:
```json
```
## Diagnostics impact
New or changed codes in `docs/reference/error-codes.md`.
## Compatibility and migration
## Alternatives considered
## Unresolved questions
@@ -0,0 +1,110 @@
# RFC 0001: Regions, Islands and Frozen Graphs
Status: Proposed
Target: Aji 0.1
## Summary
Aji uses four complementary ownership mechanisms:
```text
Own<T> single object ownership
Region bulk lifetime
Island<T> closed uniquely owned mutable graph
Frozen<T> deeply immutable shared graph
```
The intent is to avoid forcing all systems programming into one ownership abstraction.
## Motivation
Traditional per-object ownership works well for trees and many local structures, but becomes awkward for:
- cyclic graphs;
- object arenas;
- parsers with many related nodes;
- message graphs transferred between tasks;
- storage-engine request contexts;
- actor-like state.
A tracing GC solves graph lifetime at runtime but introduces runtime tracing and weakens explicit lifetime control.
Regions solve bulk lifetime but by themselves do not solve safe concurrent transfer of arbitrary mutable graphs.
`Island<T>` combines region-owned storage with unique graph ownership.
## Invariant
For a live island `I`:
```text
outside mutable aliases into I = 0
mutable references from I into ordinary foreign mutable memory = 0
```
Internal `iref<T>` edges may be cyclic but are scoped to the island.
## Transfer
Ownership of `Island<T>` may move between tasks, channels and threads if the contained external resources satisfy transfer requirements.
Transfer invalidates sender ownership.
No deep copy is required.
## Freeze
`island.freeze` consumes the mutable island and produces `Frozen<T>`.
The conversion is irreversible in safe Aji.
This allows a large graph to move from:
```text
single-writer mutable state
```
into:
```text
concurrently shared immutable state
```
without copying.
## Rejected alternatives
### Everything is Own<T>
Rejected because cyclic/arena-style graphs become unnecessarily complex.
### Garbage collection
Rejected as a core requirement because Aji targets kernels, runtimes and storage systems where deterministic lifetime and bounded runtime behavior are important.
### Implicit reference counting
Rejected because hidden atomic increments/decrements are poor fits for transparent cost and agent reasoning.
### Shared mutable regions
Rejected as a default model because it makes the verifier's alias and race problem substantially harder.
## Verifier rules
The verifier must track:
- island owner;
- internal allocation membership;
- escaping references;
- `iref` island identity;
- mutable borrow exclusivity;
- freeze transition;
- transfer transition.
## Open questions
- whether islands may contain multiple physical regions;
- exact representation of `iref<T>`;
- whether sub-islands can be detached in O(1);
- interaction with memory-mapped files.
+65
View File
@@ -0,0 +1,65 @@
# RFC 0002: Structured Concurrency
Status: Proposed
Target: Aji 0.1
## Summary
Aji makes structured task scopes the default concurrency primitive.
A child task cannot silently outlive the scope that created it.
## Motivation
Unstructured task spawning complicates:
- lifetime reasoning;
- cancellation;
- resource cleanup;
- borrowed data;
- error propagation;
- deterministic replay.
A language designed for machine verification should make the lifetime tree explicit.
## Rule
Every normal task belongs to a task scope.
```aji
task.scope s {
let a = task.spawn(s, worker_a, move input_a)?;
let b = task.spawn(s, worker_b, move input_b)?;
let ra = task.join(move a)?;
let rb = task.join(move b)?;
}
```
Leaving the scope with live children is a verifier error.
## Borrowing
Because child lifetime is bounded by the scope, scoped tasks may borrow parent storage when the verifier proves the storage outlives all child uses.
This enables zero-copy parallel algorithms.
## Cancellation
Cancellation propagates downward through the task tree but is observed only at explicit cancellation points.
Aji intentionally rejects arbitrary asynchronous interruption because it can break invariants between instructions.
## Detached tasks
Detached tasks require an explicit capability and fully owned `Send` state.
Long-lived services should normally be expressed using supervisors rather than detached background work.
## Failure policy
The language does not hard-code fail-fast semantics. Libraries may implement supervision policies.
## Determinism
Structured task topology gives the deterministic runtime a bounded set of live tasks and parent/child relationships, simplifying replay and schedule exploration.
+61
View File
@@ -0,0 +1,61 @@
# RFC 0003: Concurrency Memory Model
Status: Proposed
Target: Aji 0.1
## Summary
Aji adopts a data-race-free model for ordinary memory and explicit C/C++/Rust-style atomic ordering for low-level synchronization.
The intended user-level guarantee is DRF-SC:
> If a safe program has no data race, ordinary memory behaves as though operations occurred in some sequentially consistent interleaving consistent with happens-before.
## Relations
The model defines:
- sequenced-before;
- synchronizes-with;
- happens-before;
- atomic modification order.
## Synchronization examples
- operations before task spawn happen-before child start;
- child completion happens-before successful join return;
- channel send synchronizes with the matching receive;
- mutex unlock synchronizes with a later successful lock acquisition;
- release atomic operation synchronizes with an acquire operation that observes the release according to atomic semantics.
## Ordinary memory
Safe Aji rejects possible unsynchronized conflicting ordinary accesses.
The compiler may therefore optimize ordinary memory under the assumption that safe programs are race-free.
## Atomics
Orders:
```text
relaxed
acquire
release
acq_rel
seq_cst
```
No default order and no `consume`.
## Why no safe Atomic<ref<T>> initially
Publishing an address atomically does not solve reclamation. A verifier would need to reason about when pointed-to storage can be freed.
Therefore lock-free pointer structures should first exist behind audited library abstractions using epoch/hazard/RCU mechanisms.
## Weak-memory audit marker
Use of relaxed atomics should be visible in the effect/audit system as `atomic.weak`.
This has no runtime meaning; it is an auditability requirement.
+90
View File
@@ -0,0 +1,90 @@
# 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
```text
const copy move
integer arithmetic
bitwise operations
comparisons
casts with explicit failure/semantics
```
### Control
```text
br cbr switch ret trap guard assert
```
### Memory
```text
borrow.ref borrow.mut borrow.end
load store
slice.make slice.sub
mem.copy mem.zero
```
### Ownership
```text
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
```text
call call.indirect intrinsic.call
resource.consume
```
### 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
```
## Required metadata
Each opcode definition must declare:
```text
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.
+23
View File
@@ -0,0 +1,23 @@
# RFC Process
RFC status values:
```text
Draft → Proposed → Accepted → Implemented
↘ Rejected
```
An RFC that changes memory safety, concurrency, effects/capabilities, AIR or unsafe semantics must include:
- motivation;
- precise invariant;
- normative rule changes;
- verifier implications;
- interpreter/runtime implications;
- valid example;
- rejected example;
- diagnostics impact;
- migration/compatibility notes;
- alternatives considered.
Until an RFC is marked Accepted, the normative files under `docs/spec/` remain authoritative.