tests: inventory and verify source rejection twins

This commit is contained in:
dev committed 2026-10-08 18:01:58 +03:00
1 parent 09fbf8a5bc
commit e4aacef48c
28 files changed
+1092 -8

No files matched your search

+12
View File
@@ -42,6 +42,18 @@ A key is a single lowercase word; header lines without a `key:` prefix are free-
`reject` compares the exact multiset of error codes. Listing a code twice means two diagnostics with that code are expected.
## 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. The small declaration/producer lookup fails closed on unsupported forms; it 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. Several raw diagnostics at one source construct use the first-per-code/location projection required by spec 15 §10. Budget headers use the marked source declaration and matching canonical function name, since `--annotate` exposes block/instruction spans. 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. 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.
`--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 |
+313
View File
@@ -0,0 +1,313 @@
{
"version": 1,
"cases": {
"phase0/reject/block_argument_type.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Explicit block arguments are generated mechanics. A wrong generated argument type is a compiler defect, not authorable source."
},
"phase0/reject/branch_arity.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Explicit target argument arity is generated mechanics; malformed lowered targets are compiler defects."
},
"phase0/reject/call_argument_type.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
"rule": "The source type/signature rule rejects before AIR verification, using its prescribed E7xxx code; this does not satisfy the same-code criterion.",
"analogues": [
{
"source": "source/typecheck/call_argument.aji",
"codes": [
"E7005"
],
"fields": {
"expected": "u64",
"found": "bool"
}
}
]
},
"phase0/reject/double_definition.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "SSA definition identity is generated; source shadowing is a different name rule."
},
"phase0/reject/duplicate_feature.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a79",
"rule": "Source does not declare an AIR features header; lowering generates its closure."
},
"phase0/reject/lossy_widen.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
"rule": "The source type/signature rule rejects before AIR verification, using its prescribed E7xxx code; this does not satisfy the same-code criterion.",
"analogues": [
{
"source": "source/typecheck/lossy_widen.aji",
"codes": [
"E7005"
],
"fields": {}
}
]
},
"phase0/reject/missing_dependency.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a79",
"rule": "Source does not declare an AIR features header; lowering generates its closure."
},
"phase0/reject/missing_terminator.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Block terminators are generated, and malformed lowered CFG is a compiler defect."
},
"phase0/reject/operand_type_mismatch.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
"rule": "The source type/signature rule rejects before AIR verification, using its prescribed E7xxx code; this does not satisfy the same-code criterion.",
"analogues": [
{
"source": "source/typecheck/binary_mixed_widths.aji",
"codes": [
"E7005"
],
"fields": {
"expected": "u64",
"found": "u8"
}
}
]
},
"phase0/reject/recursive_type.air": {
"kind": "same_code",
"site": "declaration",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Node contains itself by value; source declaration validation retains E1003 (Q-043/Q-044).",
"lowering": "rejected"
},
"phase0/reject/terminator_mid_block.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Instruction placement after an AIR terminator is generated CFG structure."
},
"phase0/reject/too_many_params.air": {
"kind": "same_code",
"site": "function",
"spec": "docs/spec/08-verifier.md",
"rule": "The same deterministic budget is exceeded, with identical limit/max/found/type facts."
},
"phase0/reject/unknown_block.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Source has no named AIR block targets; generated resolution failure is a compiler defect."
},
"phase0/reject/unknown_feature.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a79",
"rule": "Source does not declare an AIR features header; lowering generates its closure."
},
"phase0/reject/unsupported_version.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Source has no AIR format-version header."
},
"phase0/reject/use_not_dominated.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Source has no explicit SSA dominance edges; malformed generated uses are compiler defects."
},
"phase1/reject/alloc_outside_entry.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "local.alloc placement is chosen by lowering; source has no instruction-placement operation."
},
"phase1/reject/borrow_return_without_from.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a719",
"rule": "The source type/signature rule rejects before AIR verification, using its prescribed E7xxx code; this does not satisfy the same-code criterion.",
"analogues": [
{
"source": "source/borrow_returns/missing_from.aji",
"codes": [
"E7006"
],
"fields": {
"reason": "invalid_borrow_return"
}
}
]
},
"phase1/reject/feature_not_declared.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a79",
"rule": "Source does not declare an AIR features header; lowering generates its closure."
},
"phase1/reject/frame_escape.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/08-verifier.md \u00a711.3",
"rule": "A returned borrow points into local frame storage, despite the declared parameter origin."
},
"phase1/reject/frame_too_large.air": {
"kind": "same_code",
"site": "function",
"spec": "docs/spec/08-verifier.md",
"rule": "The same deterministic budget is exceeded, with identical limit/max/found/type facts."
},
"phase1/reject/le_is_not_a_fact.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a75",
"rule": "A source <= condition uses checked indexing; only the specified strict < bounds form requests proven indexing."
},
"phase1/reject/mut_and_shared.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/08-verifier.md \u00a711.2",
"rule": "A shared whole-place borrow is created while an exclusive whole-place borrow is live."
},
"phase1/reject/read_uninitialized.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a74",
"rule": "Source local declarations require an initializer; there is no uninitialized frame-local declaration."
},
"phase1/reject/size_overflow.air": {
"kind": "same_code",
"site": "function",
"spec": "docs/spec/08-verifier.md",
"rule": "The same deterministic budget is exceeded, with identical limit/max/found/type facts."
},
"phase1/reject/value_too_large.air": {
"kind": "same_code",
"site": "function",
"spec": "docs/spec/08-verifier.md",
"rule": "The same deterministic budget is exceeded, with identical limit/max/found/type facts."
},
"phase2/reject/own_free_while_borrowed.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/03-memory-model.md",
"rule": "The same owning-resource consumption or whole-place borrow conflicts with a live borrow."
},
"phase2/reject/own_use_after_free.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/03-memory-model.md",
"rule": "A closed/freed resource is borrowed again."
},
"phase2/reject/region_destroy_with_live_reference.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/03-memory-model.md",
"rule": "The same region operation would invalidate a live allocation reference."
},
"phase2/reject/region_leak.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/06-resources-and-errors.md \u00a76.3",
"rule": "An owned region reaches return without region.destroy."
},
"phase2/reject/region_reset_with_live_reference.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/03-memory-model.md",
"rule": "The same region operation would invalidate a live allocation reference."
},
"phase2/reject/resource_close_twice_after_error.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/06-resources-and-errors.md",
"rule": "The same resource is consumed twice."
},
"phase2/reject/resource_close_while_borrowed.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/06-resources-and-errors.md",
"rule": "The same owning-resource consumption or whole-place borrow conflicts with a live borrow."
},
"phase2/reject/resource_join_mismatch.air": {
"kind": "same_code",
"site": "block",
"spec": "docs/spec/08-verifier.md \u00a711.4",
"rule": "The same file is closed on one incoming edge and still live on another."
},
"phase2/reject/resource_use_after_close.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/06-resources-and-errors.md",
"rule": "A closed/freed resource is borrowed again."
},
"phase3/reject/cancel_join_keeps_loans.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md",
"rule": "The lent borrow is ended while its task remains unjoined; the creating spawn is retained.",
"required_ops": {
"task.join.cancel": 1
}
},
"phase3/reject/cancel_join_twice_keeps_spawn.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md",
"rule": "The lent borrow is ended while its task remains unjoined; the creating spawn is retained.",
"required_ops": {
"task.join.cancel": 2
}
},
"phase3/reject/tasks_end_lent_borrow.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md",
"rule": "The lent borrow is ended while its task remains unjoined; the creating spawn is retained."
},
"phase4/reject/arc_release_twice.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/03-memory-model.md",
"rule": "The same resource is consumed twice."
},
"phase4/reject/frozen_leak.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/03-memory-model.md \u00a723",
"rule": "An owned frozen graph reaches return without frozen.release."
},
"phase4/reject/island_use_after_freeze.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/03-memory-model.md",
"rule": "An island is borrowed after freezing transferred its ownership."
},
"phase5/reject/cmpxchg_failure_release.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md",
"rule": "The same atomic operation rejects the same ordering and allowed set."
},
"phase5/reject/fence_relaxed.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md",
"rule": "The same atomic operation rejects the same ordering and allowed set."
},
"phase5/reject/load_release.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md",
"rule": "The same atomic operation rejects the same ordering and allowed set."
},
"phase5/reject/store_acquire.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md",
"rule": "The same atomic operation rejects the same ordering and allowed set."
},
"phase5/reject/take_while_borrowed.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md",
"rule": "The same owning-resource consumption or whole-place borrow conflicts with a live borrow."
}
}
}
@@ -1,6 +1,7 @@
// expect: reject E2108
// phase: 6
// spec: docs/spec/15-source-language.md §19
// AIR twin: phase1/reject/frame_escape.air
module test.returned_views
fn bad(p: ref<u64>) -> ref<u64> from p effects [] { let n = 1u64; ref r = n; return r; }
fn bad(p: ref<u64>) -> ref<u64> from p effects [] { let n = 1u64; ref r = n; return r; } // diagnostic here: return
fn main() -> u64 effects [] { return 0u64; }
@@ -2,5 +2,5 @@
// phase: 6
// spec: docs/spec/15-source-language.md §19
module test.returned_views
fn bad(p: ref<u64>) -> ref<u64> effects [] { return p; }
fn bad(p: ref<u64>) -> ref<u64> effects [] { return p; } // diagnostic here: fn bad
fn main() -> u64 effects [] { return 0u64; }
@@ -1,10 +1,11 @@
// The verifier, not the frontend, rejects a struct that contains itself by value (E1003).
// A by-value cycle retains E1003 in source declaration validation.
// expect: reject E1003
// phase: 6
// spec: docs/spec/15-source-language.md
// AIR twin: phase0/reject/recursive_type.air
module demo.recursive
struct Node {
struct Node { // diagnostic here
value: u64,
next: Node,
}
@@ -2,6 +2,7 @@
// expect: reject E2101
// phase: 6
// spec: docs/spec/15-source-language.md
// AIR twin: phase1/reject/mut_and_shared.air
module demo.conflict
fn main() -> u64
@@ -9,6 +10,6 @@ effects []
{
var buf: [u64; 2] = zero;
mut a = buf;
ref b = buf;
ref b = buf; // diagnostic here: ref
return 0;
}
@@ -0,0 +1,13 @@
// expect: reject E2002
// phase: 6
// spec: docs/spec/03-memory-model.md §24
// AIR twin: phase4/reject/arc_release_twice.air
module test.twins.arc_release_twice
fn main(heap: cap<mem.alloc>) -> void effects [mem.alloc] {
let i = island.create(1u64, heap) or trap;
let f = island.freeze(move i);
let a = arc.from_frozen(move f);
arc.release(move a);
arc.release(move a); // diagnostic here: arc.release
}
@@ -0,0 +1,12 @@
// expect: reject E4201
// phase: 6
// spec: docs/spec/04-concurrency-and-atomics.md
// AIR twin: phase5/reject/cmpxchg_failure_release.air
// The historical AIR filename says release; its rejected failure order is acq_rel.
module test.twins.cmpxchg_failure_acq_rel
fn main() -> void effects [atomic, atomic.weak] {
let c = atomic.new(1u64);
let (old, changed) = atomic.compare_exchange(ref c, 1u64, 2u64, acq_rel, acq_rel); // diagnostic here: let
let n = atomic.take(move c);
}
@@ -0,0 +1,9 @@
// expect: reject E4201
// phase: 6
// spec: docs/spec/04-concurrency-and-atomics.md
// AIR twin: phase5/reject/fence_relaxed.air
module test.twins.fence_relaxed
fn main() -> void effects [atomic, atomic.weak] {
atomic.fence(relaxed); // diagnostic here: atomic.fence
}
@@ -0,0 +1,16 @@
// expect: reject E5101
// phase: 6
// spec: docs/spec/08-verifier.md §3
// AIR twin: phase1/reject/frame_too_large.air
module test.twins.frame_too_large
fn unused() -> void effects [] { // diagnostic here: fn unused
var a: [u8; 409600] = zero;
var b: [u8; 409600] = zero;
var c: [u8; 409600] = zero;
ref av = a;
ref bv = b;
ref cv = c;
}
fn main() -> void effects [] {}
@@ -0,0 +1,11 @@
// expect: reject E3002
// phase: 6
// spec: docs/spec/03-memory-model.md §23
// AIR twin: phase4/reject/frozen_leak.air
module test.twins.frozen_leak
fn main(heap: cap<mem.alloc>) -> void effects [mem.alloc] {
let i = island.create(1u64, heap) or trap;
let f = island.freeze(move i);
return; // diagnostic here: return
}
@@ -0,0 +1,14 @@
// expect: reject E2001
// phase: 6
// spec: docs/spec/03-memory-model.md §23
// AIR twin: phase4/reject/island_use_after_freeze.air
module test.twins.island_use_after_freeze
fn main(heap: cap<mem.alloc>) -> void effects [mem.alloc] {
let i = island.create(1u64, heap) or trap;
let f = island.freeze(move i);
{
ref view = i; // diagnostic here: ref
}
frozen.release(move f);
}
@@ -0,0 +1,11 @@
// expect: reject E4201
// phase: 6
// spec: docs/spec/04-concurrency-and-atomics.md
// AIR twin: phase5/reject/load_release.air
module test.twins.load_release
fn main() -> void effects [atomic, atomic.weak] {
let c = atomic.new(1u64);
atomic.load(ref c, release); // diagnostic here: atomic.load
let n = atomic.take(move c);
}
@@ -0,0 +1,10 @@
// expect: reject E3002
// phase: 6
// spec: docs/spec/03-memory-model.md §8
// AIR twin: phase2/reject/region_leak.air
module test.twins.region_leak
fn main(heap: cap<mem.alloc>) -> void effects [mem.alloc] {
let r = region.create(heap) or trap;
return; // diagnostic here: return
}
@@ -0,0 +1,9 @@
// expect: reject E5101
// phase: 6
// spec: docs/spec/08-verifier.md §3
// AIR twin: phase1/reject/size_overflow.air
module test.twins.size_overflow
fn unused(data: [[u64; 4294967296]; 4294967296]) -> void effects [] {} // diagnostic here: fn unused
fn main() -> void effects [] {}
@@ -0,0 +1,11 @@
// expect: reject E4201
// phase: 6
// spec: docs/spec/04-concurrency-and-atomics.md
// AIR twin: phase5/reject/store_acquire.air
module test.twins.store_acquire
fn main() -> void effects [atomic, atomic.weak] {
let c = atomic.new(1u64);
atomic.store(ref c, 2u64, acquire); // diagnostic here: atomic.store
let n = atomic.take(move c);
}
@@ -0,0 +1,11 @@
// expect: reject E2101
// phase: 6
// spec: docs/spec/04-concurrency-and-atomics.md
// AIR twin: phase5/reject/take_while_borrowed.air
module test.twins.take_while_borrowed
fn main() -> void effects [atomic] {
let c = atomic.new(1u64);
ref view = c;
let n = atomic.take(move c); // diagnostic here: atomic.take
}
@@ -0,0 +1,9 @@
// expect: reject E5101
// phase: 6
// spec: docs/spec/08-verifier.md §3
// AIR twin: phase0/reject/too_many_params.air
module test.twins.too_many_params
fn unused(x0: u64, x1: u64, x2: u64, x3: u64, x4: u64, x5: u64, x6: u64, x7: u64, x8: u64, x9: u64, x10: u64, x11: u64, x12: u64, x13: u64, x14: u64, x15: u64, x16: u64, x17: u64, x18: u64, x19: u64, x20: u64, x21: u64, x22: u64, x23: u64, x24: u64, x25: u64, x26: u64, x27: u64, x28: u64, x29: u64, x30: u64, x31: u64, x32: u64, x33: u64, x34: u64, x35: u64, x36: u64, x37: u64, x38: u64, x39: u64, x40: u64, x41: u64, x42: u64, x43: u64, x44: u64, x45: u64, x46: u64, x47: u64, x48: u64, x49: u64, x50: u64, x51: u64, x52: u64, x53: u64, x54: u64, x55: u64, x56: u64, x57: u64, x58: u64, x59: u64, x60: u64, x61: u64, x62: u64, x63: u64, x64: u64) -> void effects [] {} // diagnostic here: fn unused
fn main() -> void effects [] {}
@@ -0,0 +1,9 @@
// expect: reject E5101
// phase: 6
// spec: docs/spec/08-verifier.md §3
// AIR twin: phase1/reject/value_too_large.air
module test.twins.value_too_large
fn unused(data: [u8; 1048577]) -> void effects [] {} // diagnostic here: fn unused
fn main() -> void effects [] {}
@@ -9,5 +9,5 @@ effects []
{
let a = 1u8;
let b = 2u64;
b + a
b + a // diagnostic here: a
}
@@ -13,5 +13,5 @@ effects []
fn main() -> u64
effects []
{
f(true)
f(true) // diagnostic here: true)
}
@@ -8,5 +8,5 @@ fn main() -> u8
effects []
{
let big: u64 = 1;
return big as u8;
return big as u8; // diagnostic here: big as u8
}