From 03305f09578d99f97c6d37faf4ac3d14f8d85887 Mon Sep 17 00:00:00 2001 From: "A.Shakhmatov" Date: Thu, 8 Oct 2026 22:12:04 +0300 Subject: [PATCH] tests: audit feature-header context and rejection boundaries --- docs/plan/phase-6-source-language.md | 6 +- tests/conformance/README.md | 2 + tests/conformance/reject-twins.json | 125 ++++++++++++++++++ .../reject_twins/analogue_endian_u32.aji | 10 ++ .../reject_twins/analogue_fallible_stmt.aji | 10 ++ .../analogue_intrinsic_ok_arity.aji | 13 ++ .../reject_twins/analogue_narrow_ok_arity.aji | 13 ++ .../reject_twins/task_handle_parameter.aji | 11 ++ .../reject_twins/unknown_narrowing_form.aji | 14 ++ .../source/std/bounded_math_payload.aji | 2 +- .../source/std/text_utf8_payload.aji | 2 +- tests/hosted/source_reject_twins.py | 89 +++++++++++++ tools/source_reject_twins.py | 39 +++++- 13 files changed, 326 insertions(+), 10 deletions(-) create mode 100644 tests/conformance/source/reject_twins/analogue_endian_u32.aji create mode 100644 tests/conformance/source/reject_twins/analogue_fallible_stmt.aji create mode 100644 tests/conformance/source/reject_twins/analogue_intrinsic_ok_arity.aji create mode 100644 tests/conformance/source/reject_twins/analogue_narrow_ok_arity.aji create mode 100644 tests/conformance/source/reject_twins/task_handle_parameter.aji create mode 100644 tests/conformance/source/reject_twins/unknown_narrowing_form.aji diff --git a/docs/plan/phase-6-source-language.md b/docs/plan/phase-6-source-language.md index c093ca0..7c9f5bb 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -320,8 +320,8 @@ Validation: unit tests and Zig formatting pass; full conformance is 1,655/1,655. ## P6-7 public rejection-twin audit (2026-10-08) -Verified same-code coverage is 86/199 across ownership/resources, borrows, effects/capabilities, tasks, graphs, atomics, linear aggregates and buffer operations. The inventory retains 32 pending, 34 prescribed E7xxx analogues and 47 AIR-only cases; all three categories remain unmet under the literal exit criterion (Q-053). P6-7 remains doing. +Verified same-code coverage is 88/199 across ownership/resources, borrows, effects/capabilities, tasks, graphs, atomics, linear aggregates and buffer operations. The inventory retains 22 pending, 40 prescribed E7xxx analogues and 49 AIR-only cases; all three categories remain unmet under the literal exit criterion (Q-053). P6-7 remains doing. -The [checker documentation](../../tests/conformance/README.md) records the diagnostic-fact, independent-position and context witnesses. Named type tables preserve the nominal diamond; early cycle pairs pin the two artifacts that exist before lowering. Five CFG loan pairs pin original AIR, source and canonical lowering after a manual shape review: single br handoff, lend/plain merge, loop-carried loans, cancelled-handle forwarding and parent access after handoff. Direct cbr/switch arm-parameter cases remain pending: the tested source expressions instead pass handles to a later br merge. The guard-unlock pair retains the returned view's mutex.borrow ancestor through the generated unlock. Fingerprints attest unchanged artifacts, not audit correctness, and introduce no provenance or lifetime analysis. +The [checker documentation](../../tests/conformance/README.md) records the diagnostic-fact, independent-position and context witnesses. Named type tables preserve the nominal diamond; early cycle pairs pin the two artifacts that exist before lowering. Five CFG loan pairs pin original AIR, source and canonical lowering after a manual shape review: single br handoff, lend/plain merge, loop-carried loans, cancelled-handle forwarding and parent access after handoff. Direct cbr/switch arm-parameter cases remain pending: the tested source expressions instead pass handles to a later br merge. The task-parameter feature pair validates each full repair header before comparing its missing closure; unrelated declared features do not decide that rule. Six more source-boundary analogues retain exact fields and independent markers. The guard-unlock pair retains the returned view's mutex.borrow ancestor through the generated unlock. Fingerprints attest unchanged artifacts, not audit correctness, and introduce no provenance or lifetime analysis. -Validation: full conformance is 1,694/1,694; unit tests, Zig formatting, all 47 checker regressions and the 86-pair source/AIR position check pass. All 52 source reject_twins fixtures pass collection before every instruction; source coverage remains 121/121. The completion gate still rejects partial coverage. Claude independently verified all fifteen CFG fingerprints against another build, audited the seven new pairs and three AIR-only classifications, and confirmed the cross-shape/drift/guard-parent regressions. Existing Git attributes already force LF for pinned AIR/source files. No compiler, verifier, runtime, normative rule, diagnostic code or reference bundle changes. +Validation: full conformance is 1,700/1,700; unit tests, Zig formatting, all 53 checker regressions and the 88-pair source/AIR position check pass. All 58 source reject_twins fixtures pass collection before every instruction; source coverage remains 121/121. The completion gate still rejects partial coverage. Claude independently reviewed the CFG fingerprints and shape regressions, and the feature-header witness, two new pairs, six analogues and two AIR-only classifications. Corrupted repair headers, larger missing closures, task results substituted for parameters and relaxed source/raw payloads are rejected by independent probes. Existing Git attributes already force LF for pinned AIR/source files. No compiler, verifier, runtime, normative rule, diagnostic code or reference bundle changes. diff --git a/tests/conformance/README.md b/tests/conformance/README.md index cd42a7d..77c6da3 100644 --- a/tests/conformance/README.md +++ b/tests/conformance/README.md @@ -50,6 +50,8 @@ The check compares code multisets, diagnostic kinds, offending AIR operations, i 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 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 target-argument cases remain pending: source arm joins do not preserve those reviewed AIR shapes. 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. diff --git a/tests/conformance/reject-twins.json b/tests/conformance/reject-twins.json index 57fabaf..5abd88b 100644 --- a/tests/conformance/reject-twins.json +++ b/tests/conformance/reject-twins.json @@ -1421,6 +1421,131 @@ "kind": "air_only", "spec": "docs/spec/15-source-language.md \u00a77", "rule": "Every normal exit of a source lock block emits explicit borrow endings and mutex.unlock. The guard is never a source value, so leaving that guard live at ret cannot be authored; traps terminate without a normal-path leak." + }, + "phase3/reject/tasks_handle_as_parameter.air": { + "kind": "same_code", + "site": "function", + "spec": "docs/spec/04-concurrency-and-atomics.md \u00a733.1", + "rule": "A task parameter requires reserved task_transfer. Each full canonical repair header is validated against that module's declared features and the supplied closure; the missing closure is task_transfer on both sides. Unused arrays and mandatory source effects are header context, not the forbidden parameter rule.", + "feature_header_context": true + }, + "phase2/reject/unknown_narrowing_form.air": { + "kind": "same_code", + "site": "instruction", + "spec": "docs/spec/05-effects-and-capabilities.md \u00a710.4", + "rule": "cap.narrow.budget is requested for cap, which has no budget narrowing form; both diagnostics retain capability_kind io.write and form budget." + }, + "phase2/reject/narrow_ok_arity.air": { + "kind": "source_error", + "spec": "docs/spec/15-source-language.md \u00a78", + "rule": "The authored cap.narrow.budget success arm omits its required capability binding; source reports E7005 before emitting an outcome target. The source analogue uses mem.alloc to isolate arity; AIR also has an invalid io.write narrowing form masked by its earlier arity rejection.", + "analogues": [ + { + "source": "source/reject_twins/analogue_narrow_ok_arity.aji", + "codes": [ + "E7005" + ], + "fields": { + "outcome": "ok", + "expected": "1" + } + } + ] + }, + "phase2/reject/intrinsic_ok_arity.air": { + "kind": "source_error", + "spec": "docs/spec/15-source-language.md \u00a76", + "rule": "fs.open_read success must bind one file; the authored source binding list is checked before emitting its continuation.", + "analogues": [ + { + "source": "source/reject_twins/analogue_intrinsic_ok_arity.aji", + "codes": [ + "E7005" + ], + "fields": { + "outcome": "ok", + "expected": "1" + } + } + ] + }, + "phase2/reject/fallible_without_targets.air": { + "kind": "source_error", + "spec": "docs/spec/15-source-language.md \u00a78", + "rule": "A fallible fs.open_read is used as a plain statement instead of an outcome match or or trap; source prescribes E7006 invalid_operation.", + "analogues": [ + { + "source": "source/reject_twins/analogue_fallible_stmt.aji", + "codes": [ + "E7006" + ], + "fields": { + "reason": "invalid_operation", + "operation": "fs.open_read" + } + } + ] + }, + "std/endian_payload_type.air": { + "kind": "source_error", + "spec": "docs/spec/15-source-language.md \u00a713", + "rule": "The registered std.bytes.ReadU16 ok variant receives u32 rather than u16; source rejects the same payload mismatch with E7005.", + "analogues": [ + { + "source": "source/reject_twins/analogue_endian_u32.aji", + "codes": [ + "E7005" + ], + "fields": { + "expected": "u16", + "found": "u32" + } + } + ] + }, + "std/bounded_arithmetic_payload.air": { + "kind": "source_error", + "spec": "docs/spec/15-source-language.md \u00a713", + "rule": "A registered standard enum variant receives a bool payload instead of u64; source checks the payload before AIR.", + "analogues": [ + { + "source": "source/std/bounded_math_payload.aji", + "codes": [ + "E7005" + ], + "fields": { + "expected": "u64", + "found": "bool" + } + } + ] + }, + "std/text_utf8_payload.air": { + "kind": "source_error", + "spec": "docs/spec/15-source-language.md \u00a713", + "rule": "A registered standard enum variant receives a bool payload instead of u32; source checks the payload before AIR.", + "analogues": [ + { + "source": "source/std/text_utf8_payload.aji", + "codes": [ + "E7005" + ], + "fields": { + "expected": "u32", + "found": "bool" + } + } + ] + }, + "phase2/reject/resource_copy.air": { + "kind": "air_only", + "spec": "docs/spec/15-source-language.md \u00a75", + "rule": "Source only duplicates Copy values by plain use. A named linear file needs explicit move (E7003), which transfers rather than duplicates it; the frontend cannot emit AIR copy of a resource." + }, + "phase2/reject/unknown_intrinsic.air": { + "kind": "air_only", + "spec": "docs/spec/15-source-language.md \u00a78", + "rule": "Only registered intrinsic names emit AIR intrinsic calls. An undeclared io.teleport in source is ordinary E7002 name resolution, not an unknown AIR intrinsic; user functions are emitted as ordinary calls." } } } diff --git a/tests/conformance/source/reject_twins/analogue_endian_u32.aji b/tests/conformance/source/reject_twins/analogue_endian_u32.aji new file mode 100644 index 0000000..068f5cd --- /dev/null +++ b/tests/conformance/source/reject_twins/analogue_endian_u32.aji @@ -0,0 +1,10 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 effects [] { + let r = std.bytes.ReadU16::ok(1u32); // diagnostic here: 1u32) + return 0; +} diff --git a/tests/conformance/source/reject_twins/analogue_fallible_stmt.aji b/tests/conformance/source/reject_twins/analogue_fallible_stmt.aji new file mode 100644 index 0000000..0f848e2 --- /dev/null +++ b/tests/conformance/source/reject_twins/analogue_fallible_stmt.aji @@ -0,0 +1,10 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §8 +module test.fallible_without_targets + +fn f(c: cap) -> void effects [fs.read] { + fs.open_read(c, b"/a"); // diagnostic here +} + +fn main() -> void effects [] {} diff --git a/tests/conformance/source/reject_twins/analogue_intrinsic_ok_arity.aji b/tests/conformance/source/reject_twins/analogue_intrinsic_ok_arity.aji new file mode 100644 index 0000000..9ababad --- /dev/null +++ b/tests/conformance/source/reject_twins/analogue_intrinsic_ok_arity.aji @@ -0,0 +1,13 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §6 +module test.intrinsic_ok_arity + +fn f(c: cap) -> void effects [fs.read] { + match fs.open_read(c, b"/a") { + ok => {}, // diagnostic here: ok => + err(e) => {} + } +} + +fn main() -> void effects [] {} diff --git a/tests/conformance/source/reject_twins/analogue_narrow_ok_arity.aji b/tests/conformance/source/reject_twins/analogue_narrow_ok_arity.aji new file mode 100644 index 0000000..2139702 --- /dev/null +++ b/tests/conformance/source/reject_twins/analogue_narrow_ok_arity.aji @@ -0,0 +1,13 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §8 +module test.narrow_ok_arity + +fn f(c: cap, n: usize) -> void effects [] { + match cap.narrow.budget(c, n) { + ok => {}, // diagnostic here: ok => + err(e) => {} + } +} + +fn main() -> void effects [] {} diff --git a/tests/conformance/source/reject_twins/task_handle_parameter.aji b/tests/conformance/source/reject_twins/task_handle_parameter.aji new file mode 100644 index 0000000..a0e1adb --- /dev/null +++ b/tests/conformance/source/reject_twins/task_handle_parameter.aji @@ -0,0 +1,11 @@ +// expect: reject E0006 +// phase: 6 +// spec: docs/spec/04-concurrency-and-atomics.md §33.1; docs/spec/15-source-language.md §10 +// AIR twin: phase3/reject/tasks_handle_as_parameter.air +module test.p + +fn f(t: task) -> void effects [] { // diagnostic here + trap; +} + +fn main() -> void effects [] {} diff --git a/tests/conformance/source/reject_twins/unknown_narrowing_form.aji b/tests/conformance/source/reject_twins/unknown_narrowing_form.aji new file mode 100644 index 0000000..489b73e --- /dev/null +++ b/tests/conformance/source/reject_twins/unknown_narrowing_form.aji @@ -0,0 +1,14 @@ +// expect: reject E3202 +// phase: 6 +// spec: docs/spec/05-effects-and-capabilities.md §10.4; docs/spec/15-source-language.md §8 +// AIR twin: phase2/reject/unknown_narrowing_form.air +module test.unknown_narrowing_form + +fn f(c: cap, n: usize) -> void effects [] { + match cap.narrow.budget(c, n) { // diagnostic here: cap.narrow.budget + ok(d) => {}, + err(e) => {} + } +} + +fn main() -> void effects [] {} diff --git a/tests/conformance/source/std/bounded_math_payload.aji b/tests/conformance/source/std/bounded_math_payload.aji index 260de02..595b8b6 100644 --- a/tests/conformance/source/std/bounded_math_payload.aji +++ b/tests/conformance/source/std/bounded_math_payload.aji @@ -5,4 +5,4 @@ module test.bounded_math import std.math; fn main() -> std.math.U64Result effects [] -{ return std.math.U64Result::ok(true); } +{ return std.math.U64Result::ok(true); } // diagnostic here: true) diff --git a/tests/conformance/source/std/text_utf8_payload.aji b/tests/conformance/source/std/text_utf8_payload.aji index 6409290..c9abab5 100644 --- a/tests/conformance/source/std/text_utf8_payload.aji +++ b/tests/conformance/source/std/text_utf8_payload.aji @@ -3,4 +3,4 @@ // spec: docs/spec/16-standard-library.md §2.5–§2.7 module test.text import std.utf8; -fn main() -> std.utf8.NextResult effects [] { return std.utf8.NextResult::ok(true, 1); } +fn main() -> std.utf8.NextResult effects [] { return std.utf8.NextResult::ok(true, 1); } // diagnostic here: true, 1 diff --git a/tests/hosted/source_reject_twins.py b/tests/hosted/source_reject_twins.py index cebc3bf..3304d6e 100644 --- a/tests/hosted/source_reject_twins.py +++ b/tests/hosted/source_reject_twins.py @@ -167,6 +167,95 @@ class CoverageFailures(unittest.TestCase): with self.assertRaisesRegex(ValueError, 'missing diagnostic-identity use witness'): self.verify_fake(row) + def task_parameter_pair(self): + row = self.fake_pair(source_path='source/reject_twins/task_handle_parameter.aji', + air_path='phase3/reject/tasks_handle_as_parameter.air') + row.update(site='function', feature_header_context=True) + return row + + def test_feature_pair_keeps_rule_with_different_unrelated_features(self): + row = self.task_parameter_pair() + air = self.corpus / 'a.air' + original = air.read_text() + for header in ('features [ownership, tasks]', + 'features [arrays, effects, ownership, tasks] ; inline context'): + with self.subTest(header=header): + air.write_text(original.replace('features [arrays, ownership, tasks]', header)) + self.verify_fake(row) + + def test_task_result_cannot_replace_task_parameter_feature_rule(self): + row = self.task_parameter_pair() + source = self.corpus / 's.aji' + source.write_text(source.read_text().replace('fn f(t: task) -> void', + 'fn f() -> task')) + with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'): + self.verify_fake(row) + + def test_additional_missing_feature_cannot_reuse_single_error_pair(self): + row = self.task_parameter_pair() + air = self.corpus / 'a.air' + air.write_text(air.read_text().replace('features [arrays, ownership, tasks]', + 'features [arrays, ownership]')) + with self.assertRaisesRegex(ValueError, 'diagnostics do not match rejection header'): + self.verify_fake(row) + + def test_same_feature_error_cannot_hide_a_larger_missing_closure(self): + row = self.task_parameter_pair() + air = self.corpus / 'a.air' + air.write_text(air.read_text().replace('features [arrays, ownership, tasks]', + 'features [arrays, ownership]')) + real_command = twins.command + def changed(aji, *args, status): + result = real_command(aji, *args, status=status) + if args[0] == 'check' and Path(args[1]) == air: + ds = [json.loads(line) for line in result.splitlines()] + # Isolate task_transfer so diagnostic count cannot mask the closure check. + return '\n'.join(json.dumps(d) for d in ds if d.get('feature') == 'task_transfer') + '\n' + return result + with patch.object(twins, 'command', changed): + with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'): + self.verify_fake(row) + + def test_invalid_feature_repair_facts_fail_closed(self): + row = self.task_parameter_pair() + real_command = twins.command + changes = [ + {'canonical_header': 'features [arrays, task_transfer, tasks]'}, + {'canonical_header': 'features [arrays, heap, ownership, task_transfer, tasks]'}, + {'canonical_header': 'features [tasks, task_transfer, ownership, arrays]'}, + {'closure': 'ownership, task_transfer, task_transfer, tasks'}, + {'closure': 'ownership, , task_transfer, tasks'}, + {'closure': 'ownership, tasks'}, + {'closure': None}, {'canonical_header': None}, + {'reason': 'missing_dependency'}, + ] + for fields in changes: + with self.subTest(fields=fields): + def changed(aji, *args, status): + result = real_command(aji, *args, status=status) + if args[0] == 'check' and Path(args[1]) == self.corpus / 'a.air': + ds = [json.loads(line) for line in result.splitlines()] + ds[0].update(fields) + return '\n'.join(json.dumps(d) for d in ds) + '\n' + return result + with patch.object(twins, 'command', changed): + with self.assertRaisesRegex(ValueError, 'feature.*(context|header|rule)'): + self.verify_fake(row) + + def test_feature_context_does_not_relax_source_raw_payload_mapping(self): + row = self.task_parameter_pair() + 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]['canonical_header'] = 'features [ownership, task_transfer, tasks]' + 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 rule facts'): + self.verify_fake(row) + def audited_cfg_pair(self, source='cfg_provenance_loan_br', air='cfg_provenance_loan_br'): row = self.fake_pair(source_path=f'source/reject_twins/{source}.aji', air_path=f'phase3/reject/{air}.air') diff --git a/tools/source_reject_twins.py b/tools/source_reject_twins.py index 569fcff..a319363 100644 --- a/tools/source_reject_twins.py +++ b/tools/source_reject_twins.py @@ -88,7 +88,8 @@ def inventory(): else: allowed = {'kind', 'rule', 'spec', 'site', 'lowering', 'analogues', 'required_ops', 'exact_ops', 'required_identity_uses', - 'match_type_declarations', 'early_context', 'audited_context'} + 'match_type_declarations', 'early_context', 'audited_context', + 'feature_header_context'} if set(review) - allowed: raise ValueError(f'{name}: unknown/reserved review keys: {sorted(set(review) - allowed)}') witnesses = review.get('required_ops', {}) @@ -109,10 +110,13 @@ def inventory(): raise ValueError(f'{name}: invalid lowering mode') if 'match_type_declarations' in review and review['match_type_declarations'] is not True: raise ValueError(f'{name}: type-declaration witness must be true') + if 'feature_header_context' in review and ( + review['feature_header_context'] is not True or expected != ['E0006']): + raise ValueError(f'{name}: feature-header context needs one E0006 rejection') if review['kind'] not in {'same_code', 'source_error', 'air_only'}: raise ValueError(f'{name}: invalid classification') if ({'required_ops', 'exact_ops', 'required_identity_uses', 'match_type_declarations', - 'audited_context'} & review.keys()) and ( + 'audited_context', 'feature_header_context'} & review.keys()) and ( review['kind'] != 'same_code' or review.get('lowering') == 'rejected'): raise ValueError(f'{name}: AIR witnesses require a lowered same-code pair') if not review.get('rule') or not review.get('spec'): @@ -303,12 +307,36 @@ def identity_fact(air, d, field): return identity_class(air, d, d[field]) -def signature(air, d, site): +def feature_header_facts(air, d): + # Compare the missing closure, after checking each module's repair line. + # The verifier supplies closure; this does not compute dependencies. + if d['code'] != 'E0006' or d.get('reason') != 'feature_not_declared': + raise ValueError('unsupported feature-header context rule') + uncommented = re.sub(r';[^\n]*', '', air) + headers = re.findall(r'^\s*features \[([^]\n]*)\]\s*$', uncommented, re.MULTILINE) + if len(headers) != 1 or not isinstance(d.get('closure'), str): + raise ValueError('feature-header context lacks a unique header/closure') + declared = [x.strip() for x in headers[0].split(',')] if headers[0].strip() else [] + closure = [x.strip() for x in d['closure'].split(',')] + if (any(not re.fullmatch(r'[a-z][a-z0-9_]*', x) for x in declared + closure) or + len(set(declared)) != len(declared) or len(set(closure)) != len(closure) or + d.get('feature') not in closure or d['feature'] in declared): + raise ValueError('invalid declared/missing feature context') + expected = 'features [' + ', '.join(sorted(set(declared) | set(closure))) + ']' + if d.get('canonical_header') != expected: + raise ValueError('feature repair header differs from declared features and closure') + facts = payload(d) + del facts['canonical_header'] + facts['missing_feature_closure'] = sorted(set(closure) - set(declared)) + return facts + + +def signature(air, d, site, feature_header_context=False): return (d['code'], d['kind'], site_key(air, d, site), tuple(sorted((k, identity_fact(air, d, k)) for k in (IDENTITIES - {'function', 'block', 'inst'}) & d.keys())), tuple(x['role'] for x in d.get('related_locations', [])), - json.dumps(payload(d), sort_keys=True)) + json.dumps(feature_header_facts(air, d) if feature_header_context else payload(d), sort_keys=True)) def annotation_map(annotated): @@ -479,7 +507,8 @@ def verify_pair(aji, root, row, source): for air, diagnostics in ((original, air_ds), (canonical, projected)): operation_witnesses(air, diagnostics, row.get('required_ops', {}), row.get('exact_ops', False), row.get('required_identity_uses')) - if Counter(signature(original, d, row['site']) for d in air_ds) != Counter(signature(canonical, d, row['site']) for d in projected): + feature_context = row.get('feature_header_context', False) + if Counter(signature(original, d, row['site'], feature_context) for d in air_ds) != Counter(signature(canonical, d, row['site'], feature_context) for d in projected): raise ValueError(f'{source}: same codes but different offending operation/rule facts') if any(d['code'] == 'E5101' and ('limit' not in d or 'max' not in d) for d in ds): raise ValueError(f'{source}: budget twin lacks stable limit facts')