tests: audit buffer and error-value rejection twins
This commit is contained in:
1 parent
2742867ef7
commit
5371eb7a2f
14 files changed
+273
-17
No files matched your search
@@ -48,7 +48,7 @@ A key is a single lowercase word; header lines without a `key:` prefix are free-
|
||||
|
||||
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. 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. `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.
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@@ -895,6 +895,160 @@
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/06-resources-and-errors.md \u00a76.3",
|
||||
"rule": "selected returns without consuming its owning parameter; source also invokes it through explicit specialization."
|
||||
},
|
||||
"buffers/reserve_missing_effect.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/15-source-language.md \u00a717",
|
||||
"rule": "buffer.reserve requires explicit mem.alloc even when both outcomes trap."
|
||||
},
|
||||
"buffers/wrong_capability.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/15-source-language.md \u00a717",
|
||||
"rule": "buffer.reserve is supplied cap<io.write> instead of the required cap<mem.alloc>."
|
||||
},
|
||||
"buffers/readonly_view_push.air": {
|
||||
"kind": "same_code",
|
||||
"site": "instruction",
|
||||
"spec": "docs/spec/15-source-language.md \u00a717",
|
||||
"rule": "buffer.push mutates a buffer while its shared buffer.view borrow is live, even when both outcomes trap.",
|
||||
"required_ops": {
|
||||
"borrow.ref": 1,
|
||||
"buffer.view": 1,
|
||||
"buffer.push": 1,
|
||||
"const.u64": 1,
|
||||
"trap": 2
|
||||
},
|
||||
"exact_ops": true,
|
||||
"required_identity_uses": {
|
||||
"conflicts_with": "buffer.view"
|
||||
}
|
||||
},
|
||||
"error_values/no_authority.air": {
|
||||
"kind": "source_error",
|
||||
"spec": "docs/spec/15-source-language.md \u00a710",
|
||||
"rule": "An error value cannot supply capability authority; the result type mismatch is source-decided E7005.",
|
||||
"analogues": [
|
||||
{
|
||||
"source": "source/error_values/no_authority.aji",
|
||||
"codes": [
|
||||
"E7005"
|
||||
],
|
||||
"fields": {
|
||||
"expected": "cap<mem.alloc>",
|
||||
"found": "alloc_error"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"error_values/wrong_family.air": {
|
||||
"kind": "source_error",
|
||||
"spec": "docs/spec/15-source-language.md \u00a710",
|
||||
"rule": "Returning alloc_error where io_error is declared rejects before AIR as E7005.",
|
||||
"analogues": [
|
||||
{
|
||||
"source": "source/error_values/wrong_family.aji",
|
||||
"codes": [
|
||||
"E7005"
|
||||
],
|
||||
"fields": {
|
||||
"expected": "io_error",
|
||||
"found": "alloc_error"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"error_values/unknown_variant.air": {
|
||||
"kind": "source_error",
|
||||
"spec": "docs/spec/15-source-language.md \u00a76",
|
||||
"rule": "An unknown built-in error variant is E7002 under the source error-construction rule.",
|
||||
"analogues": [
|
||||
{
|
||||
"source": "source/error_values/unknown_variant.aji",
|
||||
"codes": [
|
||||
"E7002"
|
||||
],
|
||||
"fields": {
|
||||
"enum": "alloc_error",
|
||||
"variant": "invalid"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"error_values/payload.air": {
|
||||
"kind": "source_error",
|
||||
"spec": "docs/spec/15-source-language.md \u00a76",
|
||||
"rule": "Built-in error variants reject payload arguments with E7005. This non-empty source payload is an analogue of the AIR empty argument list; empty source () instead rejects E7001.",
|
||||
"analogues": [
|
||||
{
|
||||
"source": "source/error_values/payload.aji",
|
||||
"codes": [
|
||||
"E7005"
|
||||
],
|
||||
"fields": {
|
||||
"variant": "budget_exceeded"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"buffers/borrowed_element.air": {
|
||||
"kind": "source_error",
|
||||
"spec": "docs/spec/15-source-language.md \u00a710",
|
||||
"rule": "A borrowed buffer element violates member-position rules. AIR checks a parameter while this source analogue checks the buffer.new type argument, both before the operation.",
|
||||
"analogues": [
|
||||
{
|
||||
"source": "source/buffers/borrowed_element.aji",
|
||||
"codes": [
|
||||
"E7005"
|
||||
],
|
||||
"fields": {
|
||||
"position": "member",
|
||||
"type_constructor": "ref"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"linear/borrow_array.air": {
|
||||
"kind": "source_error",
|
||||
"spec": "docs/spec/15-source-language.md \u00a710",
|
||||
"rule": "Borrowed inferred array elements reject E7006 invalid_literal before AIR. The source list has two elements and AIR has one; element count does not decide this member-position rule.",
|
||||
"analogues": [
|
||||
{
|
||||
"source": "source/array_literals/list_ref.aji",
|
||||
"codes": [
|
||||
"E7006"
|
||||
],
|
||||
"fields": {
|
||||
"reason": "invalid_literal"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"buffers/undeclared.air": {
|
||||
"kind": "air_only",
|
||||
"spec": "docs/spec/15-source-language.md \u00a79",
|
||||
"rule": "The missing AIR feature or dependency header cannot be authored in source: lowering generates the used features and their full dependency closure."
|
||||
},
|
||||
"linear/without_feature.air": {
|
||||
"kind": "air_only",
|
||||
"spec": "docs/spec/15-source-language.md \u00a79",
|
||||
"rule": "The missing AIR feature or dependency header cannot be authored in source: lowering generates the used features and their full dependency closure."
|
||||
},
|
||||
"error_values/undeclared.air": {
|
||||
"kind": "air_only",
|
||||
"spec": "docs/spec/15-source-language.md \u00a79",
|
||||
"rule": "The missing AIR feature or dependency header cannot be authored in source: lowering generates the used features and their full dependency closure."
|
||||
},
|
||||
"error_values/dependency.air": {
|
||||
"kind": "air_only",
|
||||
"spec": "docs/spec/15-source-language.md \u00a79",
|
||||
"rule": "The missing AIR feature or dependency header cannot be authored in source: lowering generates the used features and their full dependency closure."
|
||||
},
|
||||
"phase0/reject/float_reserved.air": {
|
||||
"kind": "air_only",
|
||||
"spec": "docs/spec/15-source-language.md \u00a73",
|
||||
"rule": "Source has no built-in f32/f64 type (spec 07 \u00a78.4). An undeclared f64 spelling is an ordinary E7002 unknown name; a user nominal f64 lowers to @f64 and cannot produce the reserved AIR primitive f64. Neither tests the reserved_type rule. Spec 15 \u00a71 restricts source to published features."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
|
||||
module test.array_literals
|
||||
fn unused(p: ref<u64>) -> void effects [] { let a = [p, p]; }
|
||||
fn unused(p: ref<u64>) -> void effects [] { let a = [p, p]; } // diagnostic here: p, p]
|
||||
fn main() -> void effects [] {}
|
||||
@@ -5,7 +5,7 @@
|
||||
// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17
|
||||
module test.buffers
|
||||
fn bad(heap: cap<mem.alloc>, value: ref<u64>) -> void effects [mem.alloc] {
|
||||
let data = buffer.new<ref<u64>>(1, heap) or trap;
|
||||
let data = buffer.new<ref<u64>>(1, heap) or trap; // diagnostic here: ref<u64>>(1
|
||||
buffer.free(move data) or trap;
|
||||
}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -2,4 +2,4 @@
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn main() -> cap<mem.alloc> effects [] { return alloc_error::budget_exceeded; }
|
||||
fn main() -> cap<mem.alloc> effects [] { return alloc_error::budget_exceeded; } // diagnostic here: alloc_error::budget_exceeded;
|
||||
@@ -2,4 +2,4 @@
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn main() -> alloc_error effects [] { return alloc_error::budget_exceeded(1u64); }
|
||||
fn main() -> alloc_error effects [] { return alloc_error::budget_exceeded(1u64); } // diagnostic here: alloc_error::budget_exceeded(1u64)
|
||||
@@ -2,4 +2,4 @@
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn main() -> alloc_error effects [] { return alloc_error::invalid; }
|
||||
fn main() -> alloc_error effects [] { return alloc_error::invalid; } // diagnostic here: alloc_error::invalid
|
||||
@@ -2,4 +2,4 @@
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn main() -> io_error effects [] { return alloc_error::budget_exceeded; }
|
||||
fn main() -> io_error effects [] { return alloc_error::budget_exceeded; } // diagnostic here: alloc_error::budget_exceeded;
|
||||
@@ -0,0 +1,11 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §17
|
||||
// AIR twin: buffers/readonly_view_push.air
|
||||
module test.readonly_view_push
|
||||
fn bad(b: mut<buffer<u64>>) -> void effects [] {
|
||||
ref view = buffer.view(b);
|
||||
buffer.push(b, 42u64) or trap; // diagnostic here
|
||||
trap;
|
||||
}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,10 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §17
|
||||
// AIR twin: buffers/reserve_missing_effect.air
|
||||
module test.reserve_missing_effect
|
||||
fn bad(b: mut<buffer<u64>>, heap: cap<mem.alloc>) -> void effects [] {
|
||||
buffer.reserve(b, 2usize, heap) or trap; // diagnostic here
|
||||
trap;
|
||||
}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,10 @@
|
||||
// expect: reject E3201
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §17
|
||||
// AIR twin: buffers/wrong_capability.air
|
||||
module test.buffer_wrong_capability
|
||||
fn bad(b: mut<buffer<u64>>, cap: cap<io.write>) -> void effects [mem.alloc] {
|
||||
buffer.reserve(b, 0usize, cap) or trap; // diagnostic here
|
||||
trap;
|
||||
}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -115,6 +115,58 @@ class CoverageFailures(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'missing required operation witness'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_mutable_view_cannot_replace_shared_view_push_regression(self):
|
||||
row = self.fake_pair(source_path='source/reject_twins/buffer_readonly_view_push.aji',
|
||||
air_path='buffers/readonly_view_push.air')
|
||||
row['required_ops'] = {'borrow.ref': 1, 'buffer.view': 1, 'buffer.push': 1}
|
||||
self.verify_fake(row)
|
||||
p = self.corpus / 's.aji'
|
||||
p.write_text(p.read_text().replace('ref view =', 'mut view ='))
|
||||
with self.assertRaisesRegex(ValueError, 'missing required operation witness'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_ended_shared_decoy_cannot_hide_exclusive_view_conflict(self):
|
||||
row = self.fake_pair(source_path='source/reject_twins/buffer_readonly_view_push.aji',
|
||||
air_path='buffers/readonly_view_push.air')
|
||||
row['required_ops'] = {'borrow.ref': 1, 'buffer.view': 1, 'buffer.push': 1}
|
||||
row['required_ops'].update({'const.u64': 1, 'trap': 2})
|
||||
row['exact_ops'] = True
|
||||
self.verify_fake(row)
|
||||
p = self.corpus / 's.aji'
|
||||
p.write_text(p.read_text().replace('ref view = buffer.view(b);',
|
||||
'{ ref decoy = buffer.view(b); }\n mut view = buffer.view(b);'))
|
||||
with self.assertRaisesRegex(ValueError, 'different exact operation witness'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_dead_view_cannot_replace_live_view_with_plain_shared_borrow(self):
|
||||
row = self.fake_pair(source_path='source/reject_twins/buffer_readonly_view_push.aji',
|
||||
air_path='buffers/readonly_view_push.air')
|
||||
row['required_ops'] = {'borrow.ref': 1, 'buffer.view': 1, 'buffer.push': 1,
|
||||
'const.u64': 1, 'trap': 2}
|
||||
row['exact_ops'] = True
|
||||
self.verify_fake(row)
|
||||
p = self.corpus / 's.aji'
|
||||
p.write_text(p.read_text().replace('ref view = buffer.view(b);',
|
||||
'{ ref decoy = buffer.view(b); }\n ref r = b;'))
|
||||
with self.assertRaisesRegex(ValueError, 'different exact operation witness'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_view_of_another_buffer_cannot_replace_conflicting_buffer_view(self):
|
||||
row = self.fake_pair(source_path='source/reject_twins/buffer_readonly_view_push.aji',
|
||||
air_path='buffers/readonly_view_push.air')
|
||||
row['required_ops'] = {'borrow.ref': 1, 'buffer.view': 1, 'buffer.push': 1,
|
||||
'const.u64': 1, 'trap': 2}
|
||||
row['exact_ops'] = True
|
||||
row['required_identity_uses'] = {'conflicts_with': 'buffer.view'}
|
||||
self.verify_fake(row)
|
||||
p = self.corpus / 's.aji'
|
||||
text = p.read_text().replace('b: mut<buffer<u64>>',
|
||||
'b: mut<buffer<u64>>, other: ref<buffer<u64>>')
|
||||
p.write_text(text.replace('ref view = buffer.view(b);',
|
||||
'ref view = buffer.view(other);\n ref r = b;'))
|
||||
with self.assertRaisesRegex(ValueError, 'missing diagnostic-identity use witness'):
|
||||
self.verify_fake(row)
|
||||
|
||||
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'):
|
||||
|
||||
Reference in new issue
Block a user