tests: audit task argument identities and source error boundaries
This commit is contained in:
1 parent
fd92604f36
commit
2742867ef7
18 files changed
+344
-20
No files matched your search
@@ -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.
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user