12 KiB
Conformance suite
Run with zig build conformance (add -- --json for JSON Lines, -- --filter <substring> to narrow).
Layout
tests/conformance/
phase<N>/accept/*.air modules a conforming verifier MUST accept
phase<N>/reject/*.air modules a conforming verifier MUST reject
phase<N>/run/*.air modules that MUST verify and produce a given run record
phase<N> is the implementation phase (docs/plan/README.md) that first requires the test to pass.
Test header
Every test starts with a block of ; lines. Keys:
| Key | Required | Value |
|---|---|---|
expect |
yes | accept; reject followed by one or more codes from docs/reference/error-codes.md; or run |
result |
with run |
expected value of the run record as canonical JSON, e.g. 42 or {"x":1} |
trap |
with run |
expected trap code, e.g. T0003 |
not_instantiated |
with run |
expected reason of a not_instantiated record (spec 05 §10.2) |
grant |
no, repeatable | <parameter>=<kind>[:<scope>] binding for a capability parameter of @main |
blocked |
with run |
the run must end with the environment outcome blocked |
stdin |
no | input for io.stdin_read; escapes \n, \t, \\, \xHH |
vfs |
no, repeatable | <path>=<text>: initial file in the deterministic file system (same escapes) |
seed |
no | seed of the deterministic random source |
stdout / stderr |
no | expected captured output (same escapes) |
file |
no, repeatable | <path>=<text>: expected contents of a file written by the run |
fuel |
no | instruction limit for run tests (spec 11 §7.1); default 1 000 000. Running out is a FAIL, never a pass |
equivalent |
no, .aji run tests only |
path, relative to tests/conformance, of a reference AIR program. Both are run with this test's world and grants; their run records must be byte-identical (for a trap, the trap code must match, since the record carries the AIR location; schedule.choices is not compared, since the scheduler's quantum counts AIR instructions and the lowered program may have a different instruction stream). The AIR texts may differ |
module |
no, repeatable, .aji only |
NAME=PATH: explicit source provider; path is relative to tests/conformance. Reachable sources are linked through the ordinary frontend. Use .aji.inc for helper files so they are not standalone tests |
phase |
yes | implementation phase number |
spec |
yes | spec section that justifies the expectation |
A key is a single lowercase word; header lines without a key: prefix are free-form description. The runner blanks the header before handing the module to the pipeline, so line numbers in diagnostics are unchanged and the AIR grammar does not need to know about test metadata.
run executes @main twice and fails if the two run records differ (spec 11); otherwise it compares the record with result or trap. Exactly one of them is required.
reject compares the exact multiset of error codes. Listing a code twice means two diagnostics with that code are expected.
For a source test, optional <file>.aji.advice pins structured repair advice: one compact JSON array of repair_candidates per diagnostic, in diagnostic order, each followed by a newline. A diagnostic without advice writes []; a program without diagnostics writes no lines. The golden compares exact kinds, hints, alternatives and member order using the CLI's serializer. Source positions and CLI/package parity are additionally checked by the hosted tests.
AIR/source rejection twins (P6-7)
python3 tools/source_reject_twins.py checks audited pairs declared by free-form // AIR twin: <path> comments in source tests. These comments are separate from equivalent, which applies only to runs. reject-twins.json records each reviewed rule, governing spec and diagnostic site; a matching code alone does not establish a twin.
The check compares code multisets, diagnostic kinds, offending AIR operations, identity-field roles, root resource families and stable rule facts (including atomic orderings and budget limits). Resource families distinguish region/frozen/own/file modes; content types and ref/mut/slice forms do not distinguish these generic ownership/loan rules. For E3101, callee names resolve to their explicit flat effect sets; parameter/result types do not decide this effect rule. For E4001/E4002 argument errors, worker/SSA names are identities, while the complete rejected parameter type remains a fact. The worker must resolve to a declaration; its body/result does not decide the argument rule. Result-only E4001 retains the worker result contract and a distinct role. Unsupported identity rules fail closed. Guard-derived mutex.borrow results retain the borrow class; guard identities and the offending opcode remain distinct. For an E3002 borrow identity produced by value.swap, only a unique direct enum.make replacement with a named enum declaration is supported. Its nominal family remains distinct from other enum, owner or resource families; unsupported replacement producers fail closed. E4202 operand is an SSA identity. Its supported ordinary-load form must identify the exact operand on the reported load line and resolve to a borrow; found and use remain exact facts. Source/raw operand names still match exactly. The small declaration/producer lookup is not a second type checker. Source diagnostics and E7xxx analogues must hit independent // diagnostic here markers. Lowered pairs also agree with canonical AIR and its annotations, including related positions. Source/raw identity fields and related values must agree exactly before original/source spellings are normalized. Several raw diagnostics at one source construct use the first-per-code/location projection required by spec 15 §10. Function/type budget headers use the marked source declaration and exact canonical name, since --annotate exposes block/instruction spans; generic/imported headers without a matching declaration fail closed. A by-value cycle rejected before lowering uses an explicit declaration mode; it does not claim generated AIR.
Case-specific required_ops optionally checks minimum operation counts in the diagnostic's function in both original and generated AIR. Cancelled-join regressions require their cancellation operations, so a plain task-loan error cannot replace them. exact_ops: true instead requires the full opcode count table of that function to match required_ops. The shared-view push case uses it to reject ended decoy views and additional plain borrows; it preserves the reviewed straight-line shape without computing lifetimes. required_identity_uses additionally requires the reported SSA identity to occur as an operand of the named opcode. The shared-view case links conflicts_with to buffer.view, excluding a view of another buffer. These strict witnesses retain both trap continuations; otherwise valid twins may need a separate audit. match_type_declarations: true additionally compares the complete named type-declaration tables, ignoring only comments/whitespace. The nominal diamond regression uses it so flat arrays of the same byte size cannot replace its shared type graph. AIR witnesses require a lowered same-code pair. These witnesses and diagnostic facts supplement the manual rule audit; they do not prove full dataflow equivalence. An analogue without structured rule fields relies on the reviewed construct and exact code/position; the check does not infer facts from message prose.
For a single E0006 feature_not_declared pair, feature_header_context: true permits different unrelated declared features. Each diagnostic's canonical_header must first equal the sorted union of its module's unique feature header and the verifier-provided closure. The comparison then replaces only that repair header with the missing closure set; feature, reason, construct and all other facts remain exact. Invalid/missing closures, dependency errors and malformed repair headers fail closed. Source/raw payload mapping stays exact, including the repair header. This witness does not infer dependencies or support other E0006 reasons.
For lowered CFG cases whose diagnostic facts omit the handoff shape, audited_context pins three manually reviewed artifacts: the original AIR (air), each source file (sources) and its canonical UTF-8 lowering (lowered). Both maps must name exactly the declared twins; every value is a lowercase SHA-256 digest. Byte changes, including source comments/line endings and harmless lowering renames, require a fresh context review before updating the fingerprints. The regular compiled diagnostics, markers, raw mapping, related positions and lowering determinism remain checked. The linear swap-leak row also compares its named type table and pins the array/unpack plus the specific enum arm that leaks; another arm with the same diagnostic and operation counts cannot replace it. The five task-loan rows record their reviewed br/merge/back-edge/cancelled-handle contexts in rule; a straight-line error cannot replace them. These fingerprints attest unchanged artifacts, not the correctness of the manual audit, and add no provenance or lifetime analysis. Direct cbr/switch task arguments to arm targets are AIR-only under spec 15 §4: source if/match arms have no target arguments; changing variables instead reach joins. Loop-exit cbr arguments forward loop-header variables, a different context.
Early rejection produces no canonical AIR. Its mandatory early_context records SHA-256 fingerprints of both manually audited AIR/source files, alongside the rule audit; compiled code/kind/type and independent source positions still have to match. The fingerprints preserve the reviewed cycle shape, including long nominal chains and recursive arrays. They attest unchanged bytes, not the correctness of the audit. Any edit, including comments or line endings, requires a fresh context review before updating these fingerprints; do not regenerate them just to make a failed check pass.
--inventory emits every current AIR rejection as JSON, including newly added unreviewed tests. Its verification: metadata_only output does not claim compiled verification. Rows are same_code, source_error (an audited E7xxx analogue), air_only (not authorable in the implemented source) or pending. The latter three remain unmet same-code rows. A successful ordinary check verifies the audited pairs against these checks; it does not prove P6-7 complete. --require-complete additionally fails until every AIR rejection has a verified same-code twin. Classification is a documented manual audit, not an automatic proof that a rule is inexpressible in source; the phase's literal exit criterion remains unchanged pending Q-053.
python3 tests/hosted/source_reject_twins.py exercises false-pair detection, independent source markers, raw diagnostic projection, early declarations and automatic discovery of pending cases.
Outcomes
| Outcome | Meaning |
|---|---|
PASS |
result matches expect |
FAIL |
result differs, or the header is malformed; the run exits 1 |
PENDING |
the test's phase is later than aji.implemented_phase and its module declares a feature the toolchain does not support yet |
Rules
- Every verifier rule gets at least one
acceptand onerejecttest (AGENTS.md, testing policy). - Names are permanent and describe the rule (
resource_use_after_move.air,borrow_use_after_end.air). A name is never reused for a different rule; the corpus doubles as an executable specification. - One defect per
rejecttest. A test that triggers several unrelated errors is hard to repair against. - Keep tests minimal: the smallest module that exhibits the rule.
- Tests are written in text AIR format 0 (
docs/reference/air-text.ebnf) and start with the four-line module header.