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
}
+187
View File
@@ -0,0 +1,187 @@
#!/usr/bin/env python3
"""Independent failure probes for the rejection-twin coverage check."""
import importlib.util
import json
import re
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[2]
spec = importlib.util.spec_from_file_location('source_reject_twins', ROOT / 'tools/source_reject_twins.py')
twins = importlib.util.module_from_spec(spec)
spec.loader.exec_module(twins)
AJI = ROOT / 'zig-out/bin/aji'
REAL_CORPUS = twins.CORPUS
class CoverageFailures(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory(prefix='aji-twin-oracle-')
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.corpus = self.root / 'corpus'
self.corpus.mkdir()
self.manifest = self.corpus / 'reject-twins.json'
def fake_pair(self, source_name='fence_relaxed', air_name='fence_relaxed', source_path=None, air_path=None):
air = REAL_CORPUS / (air_path or f'phase5/reject/{air_name}.air')
source = REAL_CORPUS / (source_path or f'source/reject_twins/{source_name}.aji')
(self.corpus / 'a.air').write_text(air.read_text())
source_text = source.read_text()
source_text = re.sub(r'^// AIR twin: .+$', '// AIR twin: a.air', source_text, flags=re.MULTILINE)
(self.corpus / 's.aji').write_text(source_text)
rule = {'kind': 'same_code', 'site': 'instruction',
'spec': 'docs/spec/04-concurrency-and-atomics.md §24',
'rule': 'Test audit; the executable check must still reject mismatched rules.'}
self.manifest.write_text(json.dumps({'version': 1, 'cases': {'a.air': rule}}))
return {'air': 'a.air', 'sources': ['s.aji'], 'codes': twins.codes(air), **rule}
def verify_fake(self, row):
with patch.object(twins, 'CORPUS', self.corpus):
twins.verify_pair(AJI, self.root, row, 's.aji')
def test_valid_pair_survives_changed_file_and_ssa_identity(self):
self.verify_fake(self.fake_pair())
def test_same_code_different_atomic_operation_is_not_a_twin(self):
row = self.fake_pair(air_name='load_release')
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
def test_same_operation_different_invalid_order_is_not_a_twin(self):
row = self.fake_pair(air_name='load_release', source_name='load_release')
p = self.corpus / 's.aji'
p.write_text(p.read_text().replace('ref c, release', 'ref c, acq_rel'))
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
def test_comment_cannot_spoof_a_leaked_resources_type(self):
row = self.fake_pair(source_path='source/reject_twins/frozen_leak.aji',
air_path='phase2/reject/region_leak.air')
p = self.corpus / 'a.air'
d, = twins.errors(AJI, p)
p.write_text(p.read_text().replace('entry:', 'entry:\n ; ' + d['borrow'] + ': frozen<u64>', 1))
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
def test_changed_related_role_cannot_survive_source_mapping(self):
row = self.fake_pair(source_path='source/layer34/reject/borrow_conflict.aji',
air_path='phase1/reject/mut_and_shared.air')
real_command = twins.command
def changed(aji, *args, status):
result = real_command(aji, *args, status=status)
if args[0] == 'check' and Path(args[1]) == self.corpus / 's.aji':
ds = [json.loads(line) for line in result.splitlines()]
ds[0]['related_locations'][0]['role'] = 'task_spawn'
return '\n'.join(json.dumps(d) for d in ds) + '\n'
return result
with patch.object(twins, 'command', changed):
with self.assertRaisesRegex(ValueError, 'mapping changed related roles'):
self.verify_fake(row)
def test_a_plain_loan_error_cannot_replace_a_cancelled_join_regression(self):
rows = twins.inventory()
row = next(r for r in rows if r['air'] == 'phase3/reject/cancel_join_keeps_loans.air')
with self.assertRaisesRegex(ValueError, 'missing required operation witness'):
twins.verify_pair(AJI, self.root, row, 'source/cfg_provenance/tasks_end_lent_borrow.aji')
def test_changed_analogue_reason_is_detected_independently(self):
rows = twins.inventory()
row = next(r for r in rows if r['air'] == 'phase1/reject/borrow_return_without_from.air')
analogue = {**row['analogues'][0], 'fields': {'reason': 'move_copy'}}
with self.assertRaisesRegex(ValueError, 'analogue rule facts changed'):
twins.verify_analogue(AJI, analogue)
def test_same_ret_and_leak_code_different_resource_family_is_not_a_twin(self):
row = self.fake_pair(source_path='source/reject_twins/frozen_leak.aji',
air_path='phase2/reject/region_leak.air')
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
def test_two_source_locations_cannot_be_dropped_as_one_raw_error(self):
row = self.fake_pair()
p = self.corpus / 's.aji'
text = p.read_text()
line = next(line for line in text.splitlines() if 'atomic.fence(relaxed)' in line)
p.write_text(text.replace(line, line + '\n' + line).replace('reject E4201', 'reject E4201 E4201'))
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
def test_block_site_cannot_pass_an_instruction_twin(self):
row = self.fake_pair()
row['site'] = 'block'
with self.assertRaisesRegex(ValueError, 'expected block label'):
self.verify_fake(row)
def test_ambiguous_marker_is_rejected_instead_of_selecting_first_token(self):
with self.assertRaisesRegex(ValueError, 'unique code fragment'):
twins.positions(' let x = x; // diagnostic here: x')
def test_markers_in_comments_are_not_source_sites(self):
self.assertEqual(twins.positions('// note // diagnostic here: note'), [])
def test_wrong_independent_source_marker_is_rejected(self):
row = self.fake_pair()
p = self.corpus / 's.aji'
p.write_text(p.read_text().replace('here: atomic.fence', 'here: relaxed'))
with self.assertRaisesRegex(ValueError, 'marked source positions'):
self.verify_fake(row)
def test_new_rejection_is_pending_without_any_manual_inventory_update(self):
self.fake_pair()
(self.corpus / 'new.air').write_text((self.corpus / 'a.air').read_text())
with patch.object(twins, 'CORPUS', self.corpus), patch.object(twins, 'MANIFEST', self.manifest):
rows = twins.inventory()
self.assertEqual([(r['air'], r['kind']) for r in rows], [('a.air', 'same_code'), ('new.air', 'pending')])
def test_air_only_cannot_hide_a_declared_source_twin(self):
self.fake_pair()
data = json.loads(self.manifest.read_text())
data['cases']['a.air']['kind'] = 'air_only'
self.manifest.write_text(json.dumps(data))
with patch.object(twins, 'CORPUS', self.corpus), patch.object(twins, 'MANIFEST', self.manifest):
with self.assertRaisesRegex(ValueError, 'lacks a same-code rule audit'):
twins.inventory()
def test_manual_review_cannot_override_discovered_pair_identity(self):
self.fake_pair()
data = json.loads(self.manifest.read_text())
data['cases']['a.air']['sources'] = []
self.manifest.write_text(json.dumps(data))
with patch.object(twins, 'CORPUS', self.corpus), patch.object(twins, 'MANIFEST', self.manifest):
with self.assertRaisesRegex(ValueError, 'reserved review keys'):
twins.inventory()
def test_deleted_air_rejection_is_not_silently_removed(self):
self.fake_pair()
(self.corpus / 'a.air').unlink()
with patch.object(twins, 'CORPUS', self.corpus), patch.object(twins, 'MANIFEST', self.manifest):
with self.assertRaisesRegex(ValueError, 'invalid corpus path'):
twins.inventory()
def test_duplicate_json_fields_do_not_survive_last_key_wins(self):
with self.assertRaisesRegex(ValueError, 'duplicate JSON member'):
twins.load_json('{"code":"E4201","code":"E7005"}')
def test_early_recursive_declaration_is_checked_without_claiming_lowered_air(self):
rows = twins.inventory()
row = next(r for r in rows if r['air'] == 'phase0/reject/recursive_type.air')
self.assertEqual(row['lowering'], 'rejected')
twins.verify_pair(AJI, self.root, row, row['sources'][0])
def test_one_source_array_borrow_keeps_first_raw_error_per_location(self):
rows = twins.inventory()
row = next(r for r in rows if r['air'] == 'phase1/reject/mut_and_shared.air')
twins.verify_pair(AJI, self.root, row, row['sources'][0])
def test_budget_header_uses_marked_function_not_instruction_annotation(self):
rows = twins.inventory()
row = next(r for r in rows if r['air'] == 'phase1/reject/frame_too_large.air')
self.assertEqual(row['site'], 'function')
twins.verify_pair(AJI, self.root, row, row['sources'][0])
if __name__ == '__main__':
unittest.main()