tests: audit task argument identities and source error boundaries

This commit is contained in:
dev committed 2026-10-08 20:57:51 +03:00
1 parent fd92604f36
commit 2742867ef7
18 files changed
+344 -20

No files matched your search

+2 -2
View File
@@ -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 71/199. Audited pairs cover owner/file/receiver leaks, use after transfer, authority/effects, unsafe calls, live task loans, mutex guards, graph content/access, atomic orders/effects, linear unpack/projection, buffer views/failure, static calls and recursive layouts. Independent markers verify instruction, outcome-block and function/type declaration positions. A new island-destroy fixture retains a child object borrow and its subsequent load; witnesses also preserve discarded-unpack and returned-buffer-failure contexts. Failed-send closed/cancelled edges now converge at one source error, matching AIR's merged failure path. E3101 callee identities resolve to their explicit flat effect sets, preserving effect facts without requiring the same name or irrelevant parameter types. The producer lookup recognizes island.borrow as a borrow. The legacy reserved_feature comment describes its actual missing_dependency rejection; its body and permanent name are unchanged. The inventory retains 96 pending, seven E7xxx analogues and 25 AIR-only cases, all still unmet under Q-053. P6-7 remains doing.
Verified same-code coverage is 74/199. Audited pairs cover owner/file/receiver leaks, use after transfer, authority/effects, unsafe calls, Send/Share, live task loans, mutex guards, graph content/access, atomic orders/effects, linear unpack/projection, buffer views/failure, static calls and recursive layouts. Independent markers verify instruction, outcome-block and function/type declaration positions. An island-destroy fixture retains a child object borrow and its subsequent load; witnesses preserve discarded-unpack and returned-buffer-failure contexts. Failed-send closed/cancelled edges converge at one source error, matching AIR's merged failure path. E3101 callee identities resolve to their explicit flat effect sets. Send/Share argument comparisons preserve the complete rejected parameter type while normalizing worker/SSA names; source/raw identities and related values remain identical. The producer lookup recognizes island.borrow as a borrow. The legacy reserved_feature comment describes its actual missing_dependency rejection; its body and permanent name are unchanged. The inventory retains 82 pending, 17 E7xxx analogues and 26 AIR-only cases, all still unmet under Q-053. P6-7 remains doing.
The diamond budget pair requires an identical named type-declaration table so equal-sized flat arrays cannot replace its shared nominal graph. Early cycle pairs, which produce no canonical AIR, pin both manually audited files with SHA-256; edits require a fresh context review while compiled diagnostics and positions remain checked. These are explicit fixture witnesses, not a second type/layout evaluator or proof of the manual audit.
Validation: full conformance is 1,671/1,671; unit tests, Zig formatting, all 32 checker regressions and the 71-pair source/AIR position check pass. All 29 source reject_twins fixtures pass collection before every instruction; source coverage remains 121/121. The completion gate still rejects partial coverage. Claude independently audited the pairs and reviewed generated-only classifications, failure paths, effect contracts, markers and witnesses. Its flat-array and substituted-cycle findings are covered by negative probes, as are incorrect declaration projections and changed callee effect sets. No compiler, verifier, runtime, normative rule, diagnostic code or reference bundle changes.
Validation: full conformance is 1,677/1,677; unit tests, Zig formatting, all 37 checker regressions and the 74-pair source/AIR position check pass. All 35 source reject_twins fixtures pass collection before every instruction; source coverage remains 121/121. The completion gate still rejects partial coverage. Claude independently audited the pairs, the ten additional E7xxx analogues and undefined-SSA classification, including their exact codes, fields, markers and normative basis. Renamed-worker, distinct-type and corrupted-identity probes supplement the earlier context regressions. No compiler, verifier, runtime, normative rule, diagnostic code or reference bundle changes.
+1 -1
View File
@@ -46,7 +46,7 @@ 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. 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.
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.
+190
View File
@@ -101,6 +101,40 @@
"spec": "docs/spec/15-source-language.md \u00a79",
"rule": "Source does not declare an AIR features header; lowering generates its closure."
},
"phase0/reject/duplicate_function.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
"rule": "A duplicate function declaration rejects before AIR with the duplicate_declaration reason registered by spec 15 \u00a710 in reference/error-codes.md.",
"analogues": [
{
"source": "source/reject_twins/analogue_duplicate_function.aji",
"codes": [
"E7006"
],
"fields": {
"name": "f",
"reason": "duplicate_declaration"
}
}
]
},
"phase0/reject/literal_out_of_range.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
"rule": "The integer literal 256 cannot fit u8; source checks its typed range before AIR under the general source-decided type rule.",
"analogues": [
{
"source": "source/reject_twins/analogue_literal_out_of_range.aji",
"codes": [
"E7005"
],
"fields": {
"type": "u8",
"literal": "256"
}
}
]
},
"phase0/reject/lossy_widen.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
@@ -125,6 +159,22 @@
"spec": "docs/spec/15-source-language.md \u00a71",
"rule": "Block terminators are generated, and malformed lowered CFG is a compiler defect."
},
"phase0/reject/non_exhaustive_enum_switch.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a76/\u00a710",
"rule": "An enum match missing a variant is E7004 in source; lowered invalid CFG would be E7900, not a source E5002.",
"analogues": [
{
"source": "source/layer2/reject/not_exhaustive.aji",
"codes": [
"E7004"
],
"fields": {
"missing": "State::Done"
}
}
]
},
"phase0/reject/operand_type_mismatch.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
@@ -160,6 +210,23 @@
"spec": "docs/spec/15-source-language.md \u00a79",
"rule": "This legacy heap header now rejects missing_dependency (capabilities), not a reserved feature. Source generates the full dependency closure and cannot spell the faulty header."
},
"phase0/reject/return_type_mismatch.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
"rule": "u64 cannot be returned from a u32 function; this type-decided error is E7005.",
"analogues": [
{
"source": "source/reject_twins/analogue_return_type_mismatch.aji",
"codes": [
"E7005"
],
"fields": {
"expected": "u32",
"found": "u64"
}
}
]
},
"phase0/reject/terminator_mid_block.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
@@ -171,6 +238,11 @@
"spec": "docs/spec/08-verifier.md",
"rule": "The same deterministic budget is exceeded, with identical limit/max/found/type facts."
},
"phase0/reject/undefined_value.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71/\u00a710",
"rule": "An undefined SSA operand is malformed generated AIR and becomes E7900. Source unknown-name resolution is a different rule, not an undefined SSA operation."
},
"phase0/reject/unknown_block.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a71",
@@ -201,6 +273,23 @@
"spec": "docs/spec/15-source-language.md \u00a75/\u00a719",
"rule": "Borrow-typed branch block arguments require reserved borrow_joins. Source binds borrows only with ref/mut, never in an assignable var, and forbids yielding them from blocks/if/match; branches may return directly. Region allocation outcome parameters do not request borrow_joins."
},
"phase1/reject/borrow_in_struct.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
"rule": "A borrow constructor in a struct field violates member-position rules; source rejects E7005. Content width u8/u64 does not decide this rule.",
"analogues": [
{
"source": "source/type_positions/field.aji",
"codes": [
"E7005"
],
"fields": {
"position": "member",
"type_constructor": "ref"
}
}
]
},
"phase1/reject/borrow_not_ended.air": {
"kind": "air_only",
"spec": "docs/spec/15-source-language.md \u00a79",
@@ -293,6 +382,22 @@
"spec": "docs/spec/08-verifier.md",
"rule": "The same deterministic budget is exceeded, with identical limit/max/found/type facts."
},
"phase1/reject/zero_enum.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a74/\u00a710",
"rule": "zero initialization requires a zeroable type; an enum rejects with registered zero_not_zeroable.",
"analogues": [
{
"source": "source/reject_twins/analogue_zero_enum.aji",
"codes": [
"E7006"
],
"fields": {
"reason": "zero_not_zeroable"
}
}
]
},
"phase2/reject/alloc_without_effect.air": {
"kind": "same_code",
"site": "instruction",
@@ -305,6 +410,22 @@
"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/capability_not_zeroable.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a74/\u00a710",
"rule": "A struct containing capability authority cannot be zero initialized, using zero_not_zeroable.",
"analogues": [
{
"source": "source/reject_twins/analogue_capability_not_zeroable.aji",
"codes": [
"E7006"
],
"fields": {
"reason": "zero_not_zeroable"
}
}
]
},
"phase2/reject/flat_effects.air": {
"kind": "same_code",
"site": "instruction",
@@ -409,6 +530,23 @@
"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/unknown_effect.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a79",
"rule": "An unregistered effect atom rejects E7002 before the function body; the source position is the function start.",
"analogues": [
{
"source": "source/effect_names/ordinary_unused.aji",
"codes": [
"E7002"
],
"fields": {
"name": "unknown",
"effect": "unknown"
}
}
]
},
"phase2/reject/unsafe_call_from_safe.air": {
"kind": "same_code",
"site": "instruction",
@@ -445,6 +583,23 @@
"task.join.cancel": 2
}
},
"phase3/reject/channels_borrow_element.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a710",
"rule": "A channel element cannot contain a borrow. Source checks the constructor type argument once (E7005), while AIR rejects both annotated endpoint parameters (two E1001); this is an analogue, not a same-code/count twin.",
"analogues": [
{
"source": "source/typecheck/channel_borrow_element.aji",
"codes": [
"E7005"
],
"fields": {
"position": "member",
"type_constructor": "ref"
}
}
]
},
"phase3/reject/channels_receiver_leak.air": {
"kind": "same_code",
"site": "instruction",
@@ -496,12 +651,41 @@
"spec": "docs/spec/04-concurrency-and-atomics.md \u00a734",
"rule": "The parent indexes an exclusive slice lent to an unjoined task; raw borrow.index/load errors share one source location."
},
"phase3/reject/tasks_borrow_return.air": {
"kind": "source_error",
"spec": "docs/spec/15-source-language.md \u00a719",
"rule": "The specific source rule rejects passing a borrow-returning function to task.spawn with E7006 at the spawn, while AIR retains the reserved task_borrow_returns gate.",
"analogues": [
{
"source": "source/borrow_returns/spawn_return.aji",
"codes": [
"E7006"
],
"fields": {
"function": "first",
"reason": "invalid_borrow_return"
}
}
]
},
"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."
},
"phase3/reject/tasks_not_send.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md \u00a735",
"rule": "An exclusive borrow of a live task handle is lent to another task although mut<task<u8>> is not Send; the second task is joined before the borrow ends and the original task is joined last."
},
"phase3/reject/tasks_not_share.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md \u00a735",
"rule": "A shared borrow of a region is lent to a task although region is not Share. Worker and argument spellings are identities; the complete rejected parameter type and argument role agree."
},
"phase3/reject/tasks_same_mut_twice.air": {
"kind": "same_code",
"site": "instruction",
@@ -568,6 +752,12 @@
"load": 1
}
},
"phase4/reject/island_lend_task.air": {
"kind": "same_code",
"site": "instruction",
"spec": "docs/spec/04-concurrency-and-atomics.md \u00a735",
"rule": "A shared borrow of an island is lent to a task although its mutable graph is not Share. Worker and argument spellings are identities; the complete rejected parameter type and argument role agree."
},
"phase4/reject/island_two_mut.air": {
"kind": "same_code",
"site": "instruction",
@@ -8,7 +8,7 @@ fn main() -> void effects [task.spawn, task.wait] {
let data = [42u64, 2u64];
ref s = data;
scope sc {
let t = task.spawn(sc, first, s);
let t = task.spawn(sc, first, s); // diagnostic here: task.spawn
task.cancel(t);
trap;
}
@@ -2,5 +2,5 @@
// phase: 6
// spec: docs/spec/15-source-language.md §9, §18
module test.effects.ordinary_unused
fn unused() -> void effects [unknown] {}
fn unused() -> void effects [unknown] {} // diagnostic here
fn main() -> u64 effects [] { return 42; }
@@ -14,7 +14,7 @@ fn main() -> u64
effects []
{
let s = State::Busy(3);
return match s {
return match s { // diagnostic here: match
State::Ready => 0,
State::Busy(n) => n,
};
@@ -3,6 +3,7 @@
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.not_share
// AIR twin: phase3/reject/tasks_not_share.air
fn look(r: ref<region>) -> u64
effects []
@@ -18,7 +19,7 @@ effects [mem.alloc, task.spawn]
{
ref arena = r;
scope sc {
let t = task.spawn(sc, look, arena);
let t = task.spawn(sc, look, arena); // diagnostic here: task.spawn
v = task.join(move t);
}
}
@@ -3,6 +3,7 @@
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.lend_island
// AIR twin: phase4/reject/island_lend_task.air
fn read(g: ref<island<u64>>) -> u64
effects []
@@ -20,7 +21,7 @@ effects [mem.alloc, task.spawn]
{
ref g = isl;
scope sc {
let t = task.spawn(sc, read, g);
let t = task.spawn(sc, read, g); // diagnostic here: task.spawn
v = task.join(move t);
}
}
@@ -0,0 +1,7 @@
// A struct containing capability authority cannot be zero initialized, using zero_not_zeroable.
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §4/§10
module test.source_analogue_capability_not_zeroable
struct H { c: cap<fs.read> }
fn main() -> u64 effects [] { var h: H = zero; return 0u64; } // diagnostic here: var h
@@ -0,0 +1,8 @@
// A duplicate function declaration rejects before AIR with the duplicate_declaration reason registered by spec 15 §10 in reference/error-codes.md.
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §10
module test.source_analogue_duplicate_function
fn f() -> void effects [] {}
fn f() -> void effects [] {} // diagnostic here
fn main() -> u64 effects [] { return 0u64; }
@@ -0,0 +1,6 @@
// The integer literal 256 cannot fit u8; source checks its typed range before AIR under the general source-decided type rule.
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §10
module test.source_analogue_literal_out_of_range
fn main() -> u64 effects [] { let x: u8 = 256; return 0u64; } // diagnostic here: 256
@@ -0,0 +1,7 @@
// u64 cannot be returned from a u32 function; this type-decided error is E7005.
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §10
module test.source_analogue_return_type_mismatch
fn f() -> u32 effects [] { return 1u64; } // diagnostic here: 1u64
fn main() -> u64 effects [] { return 0u64; }
@@ -0,0 +1,7 @@
// zero initialization requires a zeroable type; an enum rejects with registered zero_not_zeroable.
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §4/§10
module test.source_analogue_zero_enum
enum E { A, B }
fn main() -> u64 effects [] { var e: E = zero; return 0u64; } // diagnostic here: var e
@@ -0,0 +1,20 @@
// An exclusive view of a task handle is not Send.
// expect: reject E4001
// phase: 6
// spec: docs/spec/04-concurrency-and-atomics.md §35
// AIR twin: phase3/reject/tasks_not_send.air
module test.source_task_non_send
fn noop() -> u8 effects [] { return 0u8; }
fn hold(handle: mut<task<u8>>) -> void effects [] {}
fn main() -> void effects [task.spawn] {
scope sc {
let first = task.spawn(sc, noop);
{
mut lent = first;
let second = task.spawn(sc, hold, lent); // diagnostic here: task.spawn
task.join(move second);
}
task.join(move first);
}
}
@@ -2,5 +2,5 @@
// phase: 6
// spec: docs/spec/15-source-language.md §10; docs/spec/07-air.md §8.8
module test.type_positions
struct Bad { p: ref<u64> }
struct Bad { p: ref<u64> } // diagnostic here: ref<u64>
fn main() -> void effects [] {}
@@ -7,7 +7,7 @@ module demo.channel_borrow_element
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
match channel.make<ref<u64>>(1, heap) {
match channel.make<ref<u64>>(1, heap) { // diagnostic here: ref<u64>
ok(tx, rx) => {
channel.close_sender(move tx);
channel.close_receiver(move rx) or trap;
+52
View File
@@ -46,6 +46,58 @@ class CoverageFailures(unittest.TestCase):
def test_valid_pair_survives_changed_file_and_ssa_identity(self):
self.verify_fake(self.fake_pair())
def test_share_pair_survives_worker_and_argument_renaming(self):
row = self.fake_pair(source_path='source/layer7/reject/not_share.aji',
air_path='phase3/reject/tasks_not_share.air')
p = self.corpus / 's.aji'
text = p.read_text().replace('look', 'inspect_region')
p.write_text(re.sub(r'\br\b', 'arena_owner', text))
self.verify_fake(row)
def test_same_share_code_does_not_hide_a_different_parameter_type(self):
row = self.fake_pair(source_path='source/layer9/reject/lend_island.aji',
air_path='phase3/reject/tasks_not_share.air')
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
def test_same_send_code_does_not_hide_a_different_task_handle_type(self):
row = self.fake_pair(source_path='source/reject_twins/task_handle_not_send.aji',
air_path='phase3/reject/tasks_not_send.air')
p = self.corpus / 's.aji'
p.write_text(p.read_text().replace('u8', 'u64'))
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
def test_changed_argument_identity_cannot_survive_source_mapping(self):
row = self.fake_pair(source_path='source/layer7/reject/not_share.aji',
air_path='phase3/reject/tasks_not_share.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]['argument'] = '%wrong'
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 diagnostic identities'):
self.verify_fake(row)
def test_changed_related_value_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]['value'] = '%wrong'
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 identity'):
self.verify_fake(row)
def test_graph_borrow_pair_survives_renamed_bindings(self):
row = self.fake_pair(source_path='source/layer9/reject/two_mut_access.aji',
air_path='phase4/reject/island_two_mut.air')
+35 -10
View File
@@ -20,7 +20,8 @@ ROOT = Path(__file__).resolve().parents[1]
CORPUS = ROOT / 'tests/conformance'
MANIFEST = CORPUS / 'reject-twins.json'
IDENTITIES = {'function', 'block', 'inst', 'borrow', 'resource', 'task',
'conflicts_with', 'scope', 'guard', 'child', 'inner', 'local', 'from', 'callee'}
'conflicts_with', 'scope', 'guard', 'child', 'inner', 'local', 'from',
'callee', 'argument', 'task_function'}
ENVELOPE = {'code', 'kind', 'severity', 'file', 'line', 'col', 'air_line',
'air_col', 'message', 'related_locations'}
@@ -249,22 +250,42 @@ def positions(source):
return marked
def callee_effects(air, d):
# For E3101, the callee's explicit flat effect set is the rule-relevant
# contract. Parameter/return types do not decide this effect rule.
if d['code'] != 'E3101':
raise ValueError('unsupported callee identity rule')
name = d['callee']
def function_declaration(air, name):
declaration = re.search(r'^fn @' + re.escape(name) +
r'\(([^)]*)\)([^\n]*)\n\s*effects \[([^]]*)\]', air, re.MULTILINE)
if not declaration:
raise ValueError(f'callee lacks an audited declaration: {name}')
return tuple(sorted(x.strip() for x in declaration[3].split(',') if x.strip()))
raise ValueError(f'function lacks an audited declaration: {name}')
parameters, result, effects = declaration.groups()
return parameters, result.strip(), tuple(sorted({x.strip() for x in effects.split(',') if x.strip()}))
def identity_fact(air, d, field):
if field == 'callee':
# Parameter/result types do not decide the flat-effect rule.
if d['code'] != 'E3101':
raise ValueError('unsupported callee identity rule')
return function_declaration(air, d[field])[2]
if field == 'task_function':
if d['code'] not in {'E4001', 'E4002'}:
raise ValueError('unsupported worker identity rule')
_, result, _ = function_declaration(air, d[field])
if 'argument' in d:
# checkSpawn selects Send/Share from this argument's parameter
# type. Its complete type remains a stable diagnostic fact.
if not isinstance(d.get('type'), str):
raise ValueError('task argument rule lacks its type fact')
return 'argument_Send' if d['code'] == 'E4001' else 'argument_Share'
if d['code'] != 'E4001':
raise ValueError('unsupported worker-result identity rule')
return 'result_Send', result
if field == 'argument' and d['code'] not in {'E4001', 'E4002'}:
raise ValueError('unsupported argument identity rule')
return identity_class(air, d, d[field])
def signature(air, d, site):
return (d['code'], d['kind'], site_key(air, d, site),
tuple(sorted((k, callee_effects(air, d) if k == 'callee' else identity_class(air, d, d[k]))
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))
@@ -404,9 +425,13 @@ def verify_pair(aji, root, row, source):
raise ValueError(f'{source}: wrong source file')
if payload(d) != payload(rd):
raise ValueError(f'{source}: mapping changed rule facts')
if {k: d[k] for k in IDENTITIES & d.keys()} != {k: rd[k] for k in IDENTITIES & rd.keys()}:
raise ValueError(f'{source}: mapping changed diagnostic identities')
if [x['role'] for x in d.get('related_locations', [])] != [x['role'] for x in rd.get('related_locations', [])]:
raise ValueError(f'{source}: mapping changed related roles')
for related, rr in zip(d.get('related_locations', []), rd.get('related_locations', [])):
if related.get('value') != rr.get('value'):
raise ValueError(f'{source}: mapping changed related identity')
origin = mapping[related['air_line']]
if origin is None or (related['line'], related['col']) != origin[1:]:
raise ValueError(f'{source}: incorrect related source position')