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

+59
View File
@@ -0,0 +1,59 @@
# Concurrency Litmus Tests
These are semantic tests for the interpreter, verifier and native backend. Syntax is illustrative.
## MP — message publication
Writer:
```aji
atomic.store(ref value, 42, relaxed);
atomic.store(ref ready, true, release);
```
Reader:
```aji
if atomic.load(ref ready, acquire) {
let v = atomic.load(ref value, relaxed);
assert v == 42;
}
```
If the reader observes the release publication, observing the prior value store must be consistent with the happens-before relation.
## SB — store buffering
Initially `x = 0`, `y = 0`, both atomic.
Task A:
```text
store x=1 relaxed
r1 = load y relaxed
```
Task B:
```text
store y=1 relaxed
r2 = load x relaxed
```
Outcome `r1=0, r2=0` is permitted under relaxed ordering. The interpreter's weak-memory test mode must not incorrectly forbid it.
## Mutex handoff
Writes performed while holding a mutex before unlock must be visible to a later holder after successful lock acquisition.
## Channel handoff
Writes sequenced before successful `channel.send` are visible after the matching receive. Ownership of the moved message belongs only to the receiver after transfer.
## Spawn/join
Parent operations sequenced before spawn happen-before child start. Child operations happen-before successful join return.
## Invalid ordinary race
Two tasks writing the same ordinary `u64` through overlapping unsynchronized aliases must be rejected before execution.
+41
View File
@@ -0,0 +1,41 @@
# Design Decisions
This file records short decisions whose rationale does not yet justify a standalone RFC.
## DD-001 — Checked arithmetic by default
Normal integer arithmetic traps on overflow. Wrapping/saturating arithmetic is explicit.
Reason: release/debug behavior must not diverge, and arithmetic assumptions should remain visible to agents/verifier.
## DD-002 — No exceptions
Errors are values. No stack unwinding.
Reason: explicit CFG and resource cleanup are easier to verify and replay.
## DD-003 — No hidden destructors
Cleanup constructs lower to explicit AIR edges.
Reason: hidden control flow harms auditability and agent repair.
## DD-004 — Bounded channels by default
Unbounded queues require explicit library choice.
Reason: memory growth must not be implicit.
## DD-005 — No default atomic ordering
Every atomic operation states its order.
Reason: the compiler must not hide one of the most consequential concurrency choices.
## DD-006 — No arbitrary safe atomic pointer type initially
Reason: reclamation cannot be separated from safe publication.
## DD-007 — Interpreter before optimizer/backend
Reason: executable semantics and verifier behavior must stabilize before native-code complexity is introduced.
+61
View File
@@ -0,0 +1,61 @@
# Error Code Registry
Draft registry. Codes are stable once released in a tagged compiler version.
## E1xxx — Types and values
| Code | Kind | Meaning |
|---|---|---|
| E1001 | type.mismatch | Operand/result type mismatch |
| E1002 | type.invalid_cast | Cast not permitted by safe semantics |
| E1010 | init.read_uninitialized | Read from uninitialized storage |
## E2xxx — Memory and ownership
| Code | Kind | Meaning |
|---|---|---|
| E2001 | ownership.use_after_move | Value used after ownership transfer |
| E2002 | ownership.double_consume | Linear value consumed twice |
| E2101 | borrow.mutable_alias | Overlapping exclusive/shared borrow violation |
| E2102 | borrow.outlives_owner | Borrow may outlive backing storage |
| E2103 | memory.out_of_bounds | Access not proven in bounds |
| E2104 | memory.region_generation | Reference belongs to invalidated region generation |
| E2110 | island.escape | Island-internal reference escapes island |
| E2111 | island.foreign_mutable_edge | Island graph points to forbidden foreign mutable storage |
## E3xxx — Resources/capabilities/effects
| Code | Kind | Meaning |
|---|---|---|
| E3001 | resource.use_after_consume | Closed/joined/released resource reused |
| E3002 | resource.leak | Linear resource has no terminal consumption path |
| E3101 | effect.undeclared | Callee effect absent from caller contract |
| E3201 | capability.missing | Required authority unavailable |
| E3202 | capability.widen | Attempt to widen delegated authority |
## E4xxx — Concurrency
| Code | Kind | Meaning |
|---|---|---|
| E4001 | concurrency.not_send | Non-Send value moved to migratable task/thread |
| E4002 | concurrency.not_share | Non-Share value concurrently shared |
| E4101 | concurrency.possible_data_race | Conflicting ordinary access not ordered/synchronized |
| E4201 | atomic.invalid_order | Memory ordering invalid for atomic operation |
| E4301 | task.live_child_escape | Scope exits with live child task |
| E4302 | task.borrow_escape | Child task borrow can outlive parent storage |
| E4303 | io.buffer_in_flight | Buffer accessed while async operation owns/borrows it |
## E5xxx — AIR/verifier
| Code | Kind | Meaning |
|---|---|---|
| E5001 | air.invalid_ssa | SSA definition/dominance failure |
| E5002 | air.invalid_cfg | Invalid block/terminator structure |
| E5101 | verifier.resource_limit | Deterministic verifier resource limit exceeded |
## E6xxx — Unsafe/ABI
| Code | Kind | Meaning |
|---|---|---|
| E6001 | unsafe.required | Operation requires explicit unsafe boundary |
| E6101 | abi.unaligned_reference | Normal reference requested from insufficiently aligned storage |
+23
View File
@@ -0,0 +1,23 @@
# Glossary
**AIR** — Aji Intermediate Representation, the canonical semantic representation.
**Borrow** — temporary access to storage without ownership transfer.
**Capability** — unforgeable authority required to perform selected external operations.
**Effect** — declared category of externally observable or privileged behavior.
**Frozen graph** — deeply immutable graph produced by irreversible freeze.
**Island** — uniquely owned closed graph of mutable memory that can be transferred as one ownership unit.
**Linear resource** — value that must be consumed exactly once.
**Provenance** — logical origin/bounds/lifetime identity attached to a safe reference.
**Region** — owner of many allocations sharing a collective reset/destroy lifetime.
**Structured concurrency** — model in which child execution is bounded by an explicit parent scope.
**Undefined Aji Behavior** — behavior resulting only from violation of documented unsafe preconditions.
+51
View File
@@ -0,0 +1,51 @@
(* Aji draft grammar sketch. This is intentionally incomplete until syntax stabilizes. *)
program = { module_decl | import_decl | type_decl | function_decl } ;
module_decl = "module" qualified_name ";" ;
import_decl = "use" qualified_name [ "as" identifier ] ";" ;
function_decl = [ "pub" ] [ "unsafe" ] "fn" identifier
[ generic_params ]
"(" [ parameter_list ] ")"
[ "->" type ]
effect_decl
[ contract_block ]
block ;
effect_decl = "effects" "[" [ effect_list ] "]" ;
parameter_list = parameter { "," parameter } ;
parameter = identifier ":" param_type ;
param_type = [ "move" ] type
| "ref" "<" type ">"
| "mut" "<" type ">" ;
type = primitive_type
| qualified_name
| "Option" "<" type ">"
| "Result" "<" type "," type ">"
| "Own" "<" type ">"
| "Island" "<" type ">"
| "Frozen" "<" type ">"
| "Arc" "<" type ">"
| "slice" "<" type ">"
| "slice_mut" "<" type ">"
| "ref" "<" type ">"
| "mut" "<" type ">"
| "[" type ";" integer_literal "]" ;
primitive_type = "bool" | "byte" | "void" | "never"
| "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize"
| "f32" | "f64" ;
block = "{" { statement } "}" ;
statement = let_stmt | var_stmt | return_stmt | expr_stmt | block ;
let_stmt = "let" identifier [ ":" type ] "=" expression ";" ;
var_stmt = "var" identifier [ ":" type ] "=" expression ";" ;
return_stmt = "return" [ expression ] ";" ;
expr_stmt = expression ";" ;
qualified_name = identifier { "." identifier } ;
identifier = letter { letter | digit | "_" } ;
+93
View File
@@ -0,0 +1,93 @@
# Intrinsic Registry (Draft)
Intrinsics are verifier-known platform/runtime operations. Each intrinsic requires a formal signature, effects, capabilities, ownership behavior and failure model.
## Filesystem
```text
fs.open_read
fs.open_write
fs.read
fs.write
fs.write_all
fs.sync
fs.close
```
## Console / generic I/O
```text
io.stdout_write
io.stderr_write
```
## Network
```text
net.socket
net.bind
net.listen
net.accept
net.connect
net.recv
net.send
net.close
```
## Time/random
```text
clock.monotonic
clock.wall
random.fill
```
## Task/thread
```text
task.spawn
task.join
task.cancel
thread.spawn
thread.join
```
## Synchronization
```text
mutex.create
mutex.lock
mutex.unlock
rwlock.create
rwlock.read
rwlock.write
channel.create
channel.send
channel.recv
```
## Atomics
```text
atomic.load
atomic.store
atomic.exchange
atomic.fetch_add
atomic.fetch_sub
atomic.compare_exchange
atomic.fence
```
## Memory
```text
heap.alloc
heap.free
region.create
region.alloc
region.reset
region.destroy
island.create
island.alloc
island.freeze
```
+37
View File
@@ -0,0 +1,37 @@
# Type Properties
Aji 0.1 uses compiler-known structural properties rather than a user-defined trait system.
## Copy
A `Copy` value may be duplicated without changing ownership semantics.
Typical examples: integers, booleans, small aggregates containing only `Copy` fields.
Not `Copy`: `Own<T>`, `Region`, `Island<T>`, `File`, `Socket`, task/thread handles.
## Send
A `Send` value may move to another concurrent execution context.
A type becomes non-`Send` if it contains thread-affine/local state.
## Share
A `Share` value may be observed concurrently through immutable access.
Deeply immutable values are normally `Share`.
Interior-mutability wrappers must establish their own synchronization semantics to qualify.
## Freeze
A `Freeze` type may participate in deep immutable conversion.
External resources that remain operational/mutable may prevent `Freeze`.
## Local
A `Local` value is tied to its current execution context and prevents migration/transfer.
Examples may include thread-local handles, event-loop-local registrations or platform UI objects.