revision 2 per owner review: reserved-feature dependencies may change until publication (general rule, DD-014); task.join.cancel returns the handle on cancelled with loans still LOANED; channel.sender.dup from ref<sender<T>> (MPSC, receiver_dup reserved); task.wait required by every suspending operation, task.join included, only in modules declaring cancellation; sent values and handles come back as block parameters on closed/cancelled edges; explicit channel states spec 04 §37-§41 and pointers in §11-§16, §35, §36; spec 05 §9, 07 §8.11, 07a, 08 §14, 11 §6-§7; features cancellation, channels, sync published (implementation pending); rwlock, channel_transfer, receiver_dup, guard_transfer reserved; effect task.wait; E4304, E4305; Q-013 resolved; bundle +15.8 % tokens (recorded)
90 lines
5.1 KiB
Markdown
90 lines
5.1 KiB
Markdown
# 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.
|
|
|
|
## DD-008 — Reference implementation pins one exact Zig version
|
|
|
|
The toolchain version is pinned in `build.zig.zon` and `mise.toml` (currently 0.17.0) and upgraded deliberately in a dedicated change.
|
|
|
|
Reason: Zig's standard library changes between minor versions; an unpinned toolchain makes builds non-reproducible (spec 12 §2).
|
|
|
|
## DD-009 — CLI diagnostics are JSON Lines on stdout
|
|
|
|
`aji` writes one JSON diagnostic per line on stdout, human notes on stderr, and uses fixed exit codes (0 accepted or returned, 1 rejected, 2 usage/I/O, 3 not yet implemented, 4 trapped, 5 execution limit exceeded, 6 not instantiated, 7 blocked).
|
|
|
|
Reason: agents consume diagnostics programmatically (spec 10); mixing prose into the machine channel breaks repair loops.
|
|
|
|
## DD-010 — Conformance tests are text AIR with a metadata header
|
|
|
|
Tests live in `tests/conformance/phase<N>/{accept,reject}/` with `expect`/`phase`/`spec` header lines that the runner strips before parsing.
|
|
|
|
Reason: AIR is the conformance format (spec 07 §1), and keeping metadata out of the AIR grammar lets the grammar evolve independently of the test harness.
|
|
|
|
## DD-011 — The specification is the single normative source
|
|
|
|
RFCs are decision records. Accepting an RFC integrates its rules into `docs/spec/` in the same change; afterwards the spec is authoritative and the RFC keeps the rationale.
|
|
|
|
Reason: a permanent "accepted RFC overrides spec" rule makes old RFCs conflict with the current spec over time; one normative source keeps agents from having to reconcile layers.
|
|
|
|
## DD-012 — AIR format 0 is a frozen semantic baseline
|
|
|
|
After Phase 0, the meaning of existing format-0 constructs does not change. Later phases may only add instructions, types, features and codes under the rules of spec 07 §8.7; anything else needs `air 1` and an RFC.
|
|
|
|
Reason: a stable foundation lets generated code, tests and tools rely on format 0 indefinitely.
|
|
|
|
## DD-013 — Deterministic fuel instead of timeouts
|
|
|
|
Runs are bounded by fuel (executed AIR instructions), never by wall-clock time. Exhaustion is the outcome `limit_exceeded` (exit code 5), not a trap.
|
|
|
|
Reason: timeouts make test outcomes depend on machine speed; a trap code for exhaustion would make the test harness part of the language semantics.
|
|
|
|
## DD-014 — AIR feature negotiation
|
|
|
|
AIR format 0 uses the mandatory `features [...]` header as an explicit semantic compatibility contract. Every post-baseline AIR 0 extension belongs to a registered feature (`reference/air-features.md`). Modules MUST declare every feature they use and its dependency closure. Implementations MUST validate the feature set before validating the module body. Unknown, unsupported, undeclared, duplicated or dependency-incomplete features are reported as `E0006` with a structured `reason`. Feature semantics are immutable once published. `aji features` reports what a toolchain supports. While a feature is reserved, no valid module can use it, so its dependency set may change; on publication the dependencies freeze with its semantics (owner decision on RFC 0012).
|
|
|
|
Reason: format 0 is frozen; features make it an extensible protocol without an older implementation half-parsing a module it cannot understand. One code with a reason keeps the §8.7 exception for `E0006` intact.
|
|
|
|
## DD-015 — Maximum AIR value size
|
|
|
|
AIR format 0 defines `max_value_size` = 1 048 576 bytes. Every materializable type in a module has an accounted size (spec 08 §7.1, a platform-independent metric, not a layout) of at most this value; violation, including overflow while computing a size, is `E5101`, checked during module validation. `max_local_frame` (1 MiB per function) is a separate guarantee. Neither depends on host memory.
|
|
|
|
Reason: a verified IR needs its own deterministic validity limits instead of inheriting host behavior; and large data should live in storage reached through borrows, not travel as SSA values. Total allocation is bounded separately in Phase 2, as fuel bounds execution.
|