tests: preserve rejection contexts and normalize callee effects
This commit is contained in:
1 parent
06d8a1a76a
commit
fd92604f36
11 files changed
+344
-35
No files matched your search
@@ -46,9 +46,11 @@ A key is a single lowercase word; header lines without a `key:` prefix are free-
|
||||
|
||||
`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.
|
||||
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. Other callee-identity rules fail closed. 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. 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. 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.
|
||||
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. `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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@@ -21,7 +21,13 @@
|
||||
"site": "declaration",
|
||||
"spec": "docs/spec/15-source-language.md \u00a715",
|
||||
"rule": "The non-generic Node recursively contains an array of itself by value, retaining E1003 before source lowering.",
|
||||
"lowering": "rejected"
|
||||
"lowering": "rejected",
|
||||
"early_context": {
|
||||
"air": "9ab84709f2349a215db70a0cad5cb3d8255dac91170c45cc3183972ad5a68b79",
|
||||
"sources": {
|
||||
"source/generics/monomorphic_layout_cycle.aji": "0e1495cfc4cee39827f3946b269583db945034470785b65b8cde5a6956c6818f"
|
||||
}
|
||||
}
|
||||
},
|
||||
"linear/field.air": {
|
||||
"kind": "same_code",
|
||||
@@ -43,7 +49,20 @@
|
||||
"site": "declaration",
|
||||
"spec": "docs/spec/15-source-language.md \u00a71",
|
||||
"rule": "The N0 through N40 by-value cycle is rejected as E1003 at N0 before source lowering. Pure by-value cycles retain E1003 (Q-043/Q-044; AIR type rules in spec 07).",
|
||||
"lowering": "rejected"
|
||||
"lowering": "rejected",
|
||||
"early_context": {
|
||||
"air": "38bd028b4851500690cfa0f3022e726f86075cf304582d970f849d0b3c13ecd0",
|
||||
"sources": {
|
||||
"source/nominal_queries/cycle.aji": "29d2fd93a85456a73cd935190516622525bd0432570cf4977b9a5ac2b71fc620"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nominal_queries/diamond_21_u64.air": {
|
||||
"kind": "same_code",
|
||||
"site": "declaration",
|
||||
"spec": "docs/spec/08-verifier.md \u00a77",
|
||||
"rule": "The N0\u2013N3 shared diamond value layouts exceed max_value_size at their type declarations; all four limit/max/found/type facts agree after successful lowering.",
|
||||
"match_type_declarations": true
|
||||
},
|
||||
"phase0/reject/block_argument_type.air": {
|
||||
"kind": "air_only",
|
||||
@@ -127,8 +146,14 @@
|
||||
"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"
|
||||
"rule": "Node contains itself by value; source declaration validation retains E1003 (Q-043/Q-044). The scalar value field is u8 in AIR and u64 in source; its width does not decide the by-value self-cycle rule.",
|
||||
"lowering": "rejected",
|
||||
"early_context": {
|
||||
"air": "2014f05595edd77a7840d910eff8e26f338b7724fc25701cdb62f9f0dd359524",
|
||||
"sources": {
|
||||
"source/layer2/reject/verifier_recursive.aji": "c88b9db00d9d382adfd0282f650ff248c7613d0b0e0b83c8ec4b6493e1fff73a"
|
||||
}
|
||||
}
|
||||
},
|
||||
"phase0/reject/reserved_feature.air": {
|
||||
"kind": "air_only",
|
||||
@@ -274,6 +299,18 @@
|
||||
"spec": "docs/spec/05-effects-and-capabilities.md",
|
||||
"rule": "own.new lacks mem.alloc; the missing effect and complete suggested list agree."
|
||||
},
|
||||
"phase2/reject/alloc_wrong_capability.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/05-effects-and-capabilities.md \u00a710.5",
|
||||
"rule": "own.new receives cap<fs.read> instead of mem.alloc authority; ok consumes the owner and err returns normally."
|
||||
},
|
||||
"phase2/reject/flat_effects.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/05-effects-and-capabilities.md \u00a79.2/\u00a79.3",
|
||||
"rule": "A call lacks atomic.weak despite atomic being declared; effect sets are flat and callee effect sets agree."
|
||||
},
|
||||
"phase2/reject/intrinsic_effect.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
@@ -304,6 +341,11 @@
|
||||
"spec": "docs/spec/06-resources-and-errors.md \u00a76.2",
|
||||
"rule": "An owner transferred to a consuming call is subsequently borrowed."
|
||||
},
|
||||
"phase2/reject/region_allocation_outlives_borrow.air": {
|
||||
"kind": "air_only",
|
||||
"spec": "docs/spec/15-source-language.md \u00a78/\u00a79",
|
||||
"rule": "The explicit region borrow lexically outlives its derived allocation borrow. Source generates reverse-order ends and forbids yielding a borrow out of an arm/block, so parent-before-allocation-end cannot be authored."
|
||||
},
|
||||
"phase2/reject/region_destroy_with_live_reference.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
@@ -352,6 +394,21 @@
|
||||
"spec": "docs/spec/06-resources-and-errors.md",
|
||||
"rule": "A closed/freed resource is borrowed again."
|
||||
},
|
||||
"phase2/reject/resource_use_after_move.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/06-resources-and-errors.md \u00a76.2",
|
||||
"rule": "An opened file<read> is transferred to a consuming call and then borrowed again.",
|
||||
"required_ops": {
|
||||
"call": 1
|
||||
}
|
||||
},
|
||||
"phase2/reject/undeclared_effect.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/05-effects-and-capabilities.md \u00a79.3",
|
||||
"rule": "A call lacks the callee io.write effect; callee identities may differ but declared effect sets agree."
|
||||
},
|
||||
"phase2/reject/unsafe_call_from_safe.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
@@ -400,6 +457,15 @@
|
||||
"spec": "docs/spec/04-concurrency-and-atomics.md \u00a737.4/\u00a738",
|
||||
"rule": "channel.recv lacks task.wait on a borrowed receiver parameter; no allocation adds another missing effect."
|
||||
},
|
||||
"phase3/reject/channels_use_after_send.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/04-concurrency-and-atomics.md \u00a738",
|
||||
"rule": "The old owner is borrowed after failed send returns its ownership under a new name; closed and cancelled both merge to the same error site, as in AIR.",
|
||||
"required_ops": {
|
||||
"channel.send": 1
|
||||
}
|
||||
},
|
||||
"phase3/reject/sync_call_waiting_function.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
// phase: 6
|
||||
// spec: docs/spec/08-verifier.md §7; docs/spec/15-source-language.md §10
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1, b: N1 }
|
||||
struct N1 { a: N2, b: N2 }
|
||||
struct N2 { a: N3, b: N3 }
|
||||
struct N3 { a: N4, b: N4 }
|
||||
// AIR twin: nominal_queries/diamond_21_u64.air
|
||||
struct N0 { a: N1, b: N1 } // diagnostic here
|
||||
struct N1 { a: N2, b: N2 } // diagnostic here
|
||||
struct N2 { a: N3, b: N3 } // diagnostic here
|
||||
struct N3 { a: N4, b: N4 } // diagnostic here
|
||||
struct N4 { a: N5, b: N5 }
|
||||
struct N5 { a: N6, b: N6 }
|
||||
struct N6 { a: N7, b: N7 }
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// own.new receives cap<fs.read> where the allocation needs cap<mem.alloc>.
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §10.5
|
||||
// expect: reject E3201
|
||||
// AIR twin: phase2/reject/alloc_wrong_capability.air
|
||||
module test.source_alloc_wrong_capability
|
||||
fn f(heap: cap<fs.read>) -> void effects [mem.alloc] {
|
||||
match own.new(1u64, heap) { // diagnostic here: own.new
|
||||
ok(o) => { own.free(move o); }
|
||||
err(e) => {}
|
||||
}
|
||||
}
|
||||
fn main() -> u64 effects [] { return 0u64; }
|
||||
@@ -0,0 +1,16 @@
|
||||
// Failed send returns the owner under a new name on both failure edges.
|
||||
// phase: 6
|
||||
// spec: docs/spec/04-concurrency-and-atomics.md §38
|
||||
// AIR twin: phase3/reject/channels_use_after_send.air
|
||||
// expect: reject E2001
|
||||
module test.source_use_after_failed_send
|
||||
fn f(tx: mut<sender<own<u64>>>, o: own<u64>) -> u64 effects [task.wait] {
|
||||
let back = match channel.send(tx, move o) {
|
||||
ok => { return 0u64; }
|
||||
closed(value) => move value,
|
||||
cancelled(value) => move value,
|
||||
};
|
||||
{ ref old = o; } // diagnostic here: ref old
|
||||
return own.take(move back);
|
||||
}
|
||||
fn main() -> u64 effects [] { return 0u64; }
|
||||
@@ -0,0 +1,11 @@
|
||||
// atomic does not imply atomic.weak: effect sets are flat.
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §9.2/§9.3
|
||||
// expect: reject E3101
|
||||
// AIR twin: phase2/reject/flat_effects.air
|
||||
module test.source_flat_effects
|
||||
fn relaxed_work() -> void effects [atomic.weak] {}
|
||||
fn f() -> void effects [atomic] {
|
||||
relaxed_work(); // diagnostic here
|
||||
}
|
||||
fn main() -> u64 effects [] { return 0u64; }
|
||||
@@ -0,0 +1,19 @@
|
||||
// An opened file is moved into a consuming call and then borrowed.
|
||||
// phase: 6
|
||||
// spec: docs/spec/06-resources-and-errors.md §6.2
|
||||
// expect: reject E2001
|
||||
// AIR twin: phase2/reject/resource_use_after_move.air
|
||||
module test.source_resource_use_after_move
|
||||
fn take(file: file<read>) -> void effects [] {
|
||||
fs.close(move file) or trap;
|
||||
}
|
||||
fn f(c: cap<fs.read>, p: slice<u8>) -> void effects [fs.read] {
|
||||
match fs.open_read(c, p) {
|
||||
ok(file) => {
|
||||
take(move file);
|
||||
{ mut m = file; } // diagnostic here: mut m
|
||||
}
|
||||
err(e) => {}
|
||||
}
|
||||
}
|
||||
fn main() -> u64 effects [] { return 0u64; }
|
||||
@@ -0,0 +1,11 @@
|
||||
// The caller does not declare the effect of its callee.
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §9.3
|
||||
// expect: reject E3101
|
||||
// AIR twin: phase2/reject/undeclared_effect.air
|
||||
module test.source_undeclared_effect
|
||||
fn emit() -> void effects [io.write] {}
|
||||
fn f() -> void effects [] {
|
||||
emit(); // diagnostic here
|
||||
}
|
||||
fn main() -> u64 effects [] { return 0u64; }
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Independent failure probes for the rejection-twin coverage check."""
|
||||
import importlib.util
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
@@ -188,6 +189,53 @@ class CoverageFailures(unittest.TestCase):
|
||||
self.assertEqual(row['lowering'], 'rejected')
|
||||
twins.verify_pair(AJI, self.root, row, row['sources'][0])
|
||||
|
||||
def test_self_loop_cannot_replace_audited_long_cycle(self):
|
||||
row = self.fake_pair(source_path='source/nominal_queries/cycle.aji',
|
||||
air_path='nominal_queries/cycle.air')
|
||||
source = self.corpus / 's.aji'
|
||||
row.update(site='declaration', lowering='rejected', early_context={
|
||||
'air': hashlib.sha256((self.corpus / 'a.air').read_bytes()).hexdigest(),
|
||||
'sources': {'s.aji': hashlib.sha256(source.read_bytes()).hexdigest()}})
|
||||
source.write_text(source.read_text().replace('struct N0 { a: N1, b: N1 }',
|
||||
'struct N0 { a: N0, b: N0 }'))
|
||||
with self.assertRaisesRegex(ValueError, 'audited early source changed'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_direct_cycle_cannot_replace_audited_array_cycle(self):
|
||||
row = self.fake_pair(source_path='source/generics/monomorphic_layout_cycle.aji',
|
||||
air_path='generics/recursive_array.air')
|
||||
source = self.corpus / 's.aji'
|
||||
row.update(site='declaration', lowering='rejected', early_context={
|
||||
'air': hashlib.sha256((self.corpus / 'a.air').read_bytes()).hexdigest(),
|
||||
'sources': {'s.aji': hashlib.sha256(source.read_bytes()).hexdigest()}})
|
||||
source.write_text(source.read_text().replace('[Node; 1]', 'Node'))
|
||||
with self.assertRaisesRegex(ValueError, 'audited early source changed'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_changed_early_air_cannot_reuse_the_old_source_audit(self):
|
||||
row = self.fake_pair(source_path='source/generics/monomorphic_layout_cycle.aji',
|
||||
air_path='generics/recursive_array.air')
|
||||
air, source = self.corpus / 'a.air', self.corpus / 's.aji'
|
||||
row.update(site='declaration', lowering='rejected', early_context={
|
||||
'air': hashlib.sha256(air.read_bytes()).hexdigest(),
|
||||
'sources': {'s.aji': hashlib.sha256(source.read_bytes()).hexdigest()}})
|
||||
original = air.read_text()
|
||||
changed = original.replace('array<@Node, 1>', '@Node')
|
||||
self.assertNotEqual(changed, original)
|
||||
air.write_text(changed)
|
||||
with self.assertRaisesRegex(ValueError, 'audited early AIR changed'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_early_mode_cannot_omit_its_context_audit(self):
|
||||
row = self.fake_pair(source_path='source/generics/monomorphic_layout_cycle.aji',
|
||||
air_path='generics/recursive_array.air')
|
||||
review = {k: v for k, v in row.items() if k not in {'air', 'sources', 'codes'}}
|
||||
review.update(site='declaration', lowering='rejected')
|
||||
self.manifest.write_text(json.dumps({'version': 1, 'cases': {'a.air': review}}))
|
||||
with patch.object(twins, 'CORPUS', self.corpus), patch.object(twins, 'MANIFEST', self.manifest):
|
||||
with self.assertRaisesRegex(ValueError, 'early rejection needs audited'):
|
||||
twins.inventory()
|
||||
|
||||
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')
|
||||
@@ -199,6 +247,66 @@ class CoverageFailures(unittest.TestCase):
|
||||
self.assertEqual(row['site'], 'function')
|
||||
twins.verify_pair(AJI, self.root, row, row['sources'][0])
|
||||
|
||||
def test_four_type_budget_headers_use_exact_marked_declarations(self):
|
||||
rows = twins.inventory()
|
||||
row = next(r for r in rows if r['air'] == 'nominal_queries/diamond_21_u64.air')
|
||||
self.assertEqual(row['site'], 'declaration')
|
||||
self.assertNotIn('lowering', row)
|
||||
twins.verify_pair(AJI, self.root, row, row['sources'][0])
|
||||
|
||||
def test_consistent_but_wrong_type_header_projection_is_rejected(self):
|
||||
row = self.fake_pair(source_path='source/nominal_queries/diamond_21_u64.aji',
|
||||
air_path='nominal_queries/diamond_21_u64.air')
|
||||
row['site'] = 'declaration'
|
||||
p = self.corpus / 's.aji'
|
||||
lines = p.read_text().splitlines()
|
||||
marked = [i for i, line in enumerate(lines) if '// diagnostic here' in line]
|
||||
for i in marked:
|
||||
lines[i] = lines[i].replace(' // diagnostic here', '')
|
||||
lines[i + 4] += ' // diagnostic here'
|
||||
p.write_text('\n'.join(lines) + '\n')
|
||||
real_command = twins.command
|
||||
def changed(aji, *args, status):
|
||||
result = real_command(aji, *args, status=status)
|
||||
if args[0] == 'check' and Path(args[1]) == p:
|
||||
ds = [json.loads(line) for line in result.splitlines()]
|
||||
for d in ds:
|
||||
d['line'] += 4
|
||||
return '\n'.join(json.dumps(d) for d in ds) + '\n'
|
||||
return result
|
||||
with patch.object(twins, 'command', changed):
|
||||
with self.assertRaisesRegex(ValueError, 'incorrect source position'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_flat_array_sizes_cannot_replace_nominal_diamond_context(self):
|
||||
row = self.fake_pair(source_path='source/nominal_queries/diamond_21_u64.aji',
|
||||
air_path='nominal_queries/diamond_21_u64.air')
|
||||
row.update(site='declaration', match_type_declarations=True)
|
||||
p = self.corpus / 's.aji'
|
||||
lines = [line for line in p.read_text().splitlines() if not line.startswith('struct ')]
|
||||
index = next(i for i, line in enumerate(lines) if line.startswith('module ')) + 1
|
||||
lines[index:index] = [f'struct N{i} {{ a: [u64; {2097152 >> i}] }} // diagnostic here'
|
||||
for i in range(4)]
|
||||
p.write_text('\n'.join(lines) + '\n')
|
||||
with self.assertRaisesRegex(ValueError, 'different type-declaration context'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_effect_pair_survives_a_renamed_callee(self):
|
||||
self.verify_fake(self.fake_pair(source_path='source/reject_twins/undeclared_effect.aji',
|
||||
air_path='phase2/reject/undeclared_effect.air'))
|
||||
|
||||
def test_same_missing_effect_does_not_hide_different_callee_effect_sets(self):
|
||||
row = self.fake_pair(source_path='source/reject_twins/undeclared_effect.aji',
|
||||
air_path='phase2/reject/undeclared_effect.air')
|
||||
air = self.corpus / 'a.air'
|
||||
air.write_text(air.read_text().replace('effects []', 'effects [atomic]', 1)
|
||||
.replace('effects [io.write]', 'effects [atomic, io.write]'))
|
||||
source = self.corpus / 's.aji'
|
||||
source.write_text(source.read_text().replace('fn f() -> void effects []',
|
||||
'fn f() -> void effects [atomic]'))
|
||||
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
|
||||
self.verify_fake(row)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user