frontend: validate unknown effect names before body lowering
This commit is contained in:
1 parent
4c9c5626c9
commit
762c5abe7b
40 files changed
+335
-9
No files matched your search
@@ -36,6 +36,7 @@ jobs:
|
||||
- run: python3 tests/hosted/source_store_modes.py
|
||||
- run: python3 tests/hosted/source_nominal_queries.py
|
||||
- run: python3 tests/hosted/source_grammar.py
|
||||
- run: python3 tests/hosted/source_effect_names.py
|
||||
- run: python3 tests/hosted/examples.py --stress 200
|
||||
- run: python3 tests/hosted/source_static_functions.py
|
||||
- run: python3 tests/hosted/source_linear.py
|
||||
|
||||
@@ -32,6 +32,7 @@ python3 tests/hosted/source_nonvalue_operands.py # never operands, divergent rec
|
||||
python3 tests/hosted/source_store_modes.py # exclusive places, source positions, array modes and package provenance
|
||||
python3 tests/hosted/source_nominal_queries.py # deep shared types, deterministic limits and package cache indices
|
||||
python3 tests/hosted/source_grammar.py # syntax boundaries, canonical enum lists and formatter/AIR fidelity
|
||||
python3 tests/hosted/source_effect_names.py # effect-name errors, signature priority and package provenance
|
||||
python3 tests/hosted/examples.py --stress 200 # all examples/packages, wire bytes, partial I/O and source/AIR schedules
|
||||
python3 tests/hosted/source_static_functions.py # explicit operations, effects, nominal policy identity and workers
|
||||
python3 tests/hosted/source_linear.py # whole-value owners, canonical AIR and CLI errors
|
||||
|
||||
@@ -168,3 +168,5 @@ Q-047 non-value operands (cl100k): Quick Reference stays 8,948; other source doc
|
||||
Q-048 source access modes (cl100k): Quick Reference stays 8,948; other source docs 67,258 → 67,343 (+85), full source 76,206 → 76,291 (+0.11%). o200k groups are 8,984 / 67,546 / 76,530; Qwen2.5 9,226 / 69,001 / 78,227. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Shared places reject at source stores and explicit mut bindings/arguments before array shape conversion; valid canonical AIR is preserved. No new concept, syntax, code/reason, feature or verifier/runtime state is added. No empirical MCC benefit is claimed.
|
||||
|
||||
DD-022 grammar surface (cl100k): Quick Reference stays 8,948; other source docs 67,343 → 68,219 (+876), full source 76,291 → 77,167 (+1.15%). o200k groups are 8,984 / 68,422 / 77,406; Qwen2.5 9,226 / 69,887 / 79,113. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing syntax and ordered parsing choices replace incomplete grammar descriptions. Empty qualified enum payload lists now reject E7001; accepted public-source canonical AIR is preserved. No new programming concept, feature, diagnostic code or verifier/runtime state is added. The grammar stays a reference read on demand; no empirical MCC benefit is claimed.
|
||||
|
||||
Q-051 source effect names (DD-023, cl100k): Quick Reference 8,948 → 8,955 (+7); other source docs 68,219 → 68,323 (+104), full source 77,167 → 77,278 (+0.14%). o200k groups are 8,991 / 68,526 / 77,517; Qwen2.5 9,233 / 69,994 / 79,227. AIR grows 47,445 → 47,458 (+13), 184,628 → 184,678 bytes, through the shared E7002 registry description; library/std.md is unchanged. Unknown effects use existing E7002 with structured `name`/`effect`, replacing erroneous source E7900 or E0006. Accepted canonical AIR and authority/effect semantics are preserved. No new concept, syntax, code/reason, feature or verifier/runtime state is added; no empirical MCC benefit is claimed.
|
||||
@@ -309,7 +309,7 @@ scope s { // every task spawned in s must
|
||||
| Code | Meaning | Usual repair |
|
||||
|---|---|---|
|
||||
| E7001 | syntax | check `;`, braces, `=>` in `match` |
|
||||
| E7002 | unknown name | spelling; declare the variable or function |
|
||||
| E7002 | unknown name | spelling; declare missing bindings; for `effect`, use a registered atom |
|
||||
| E7003 | linear value consumed without `move` | write `move x` (or borrow it with `ref`/`mut` if it must stay) |
|
||||
| E7004 | `match` not exhaustive | add the arms listed in `missing` (integers: add `_`) |
|
||||
| E7005, E1001 | type mismatch | convert with `as`, `as!`, `as%`; check borrow vs value |
|
||||
|
||||
@@ -137,3 +137,9 @@ Compatibility: formerly rejected array-borrow calls become available; accepted s
|
||||
P6-1/P6-2 synchronizes the grammar with implemented syntax: graph/atomic wrappers, binary literals, signed integer patterns, parenthesized places, declared borrow-return calls and existing list/arm punctuation. Contextual words and the ordered choices for statements, body-opening braces and typed built-ins are explicit. The grammar is not claimed to be LL(k). Existing grouping and optional list delimiters introduce no operation; formatter token preservation remains mandatory.
|
||||
|
||||
Q-050 corrects empty parentheses on qualified enum variants, contrary to spec 15 §5–§6. Construction and pattern parsing reject E7001 at the opening parenthesis without symbol lookup, including generic, qualified and built-in variants. Payload-bearing variants with empty lists change from E7005 to E7001; non-empty arity/type checks remain. Bare variants, ordinary zero-argument calls and empty outcome bindings retain their meanings. No AIR, verifier, runtime, ownership/concurrency, feature or code changes; accepted public-source canonical AIR is preserved. Source grammar/CLI tests cover both sides and formatting. Bundle growth is recorded in docs/agent/README.md. Future grammar features still require their RFCs; P6-1 remains open. Q-051 separately records unknown ordinary-function effects.
|
||||
|
||||
## DD-023 — Unknown source effects are name errors
|
||||
|
||||
Q-051 validates ordinary effect names before body lowering using the existing closed registry. Templates/static contracts use the same E7002 with `name` and `effect`; legacy E0006 without a feature reason was incorrect. Function/template positions remain declaration starts, static contracts use their parameter start. Ordinary parameter/return/from checks retain priority; existing template/header ordering remains. Unknown effects cannot generate malformed AIR or E7900. AIR E0004 and its registry contract are unchanged.
|
||||
|
||||
Only invalid-source codes/priority/fields change. Registered effects, explicit authority, effect coverage, duplicate-list set semantics and static-contract uniqueness remain unchanged; no code, reason, syntax, AIR feature, verifier/runtime or ownership/concurrency state is added. Positive/rejected source tests and CLI/package tests cover headers, unused declarations, priority, missing-effect/capability diagnostics, formatting and source/AIR execution. Budget growth is measured in docs/agent/README.md. This completes this diagnostic correction, not P6-2 or an empirical MCC claim.
|
||||
@@ -372,3 +372,5 @@ The parser accepted `E::Empty()` and the corresponding match pattern, although s
|
||||
## Q-051 — Unknown effects in ordinary source signatures
|
||||
|
||||
An ordinary function declaring `effects [bogus.effect]` reaches AIR and reports E7900 with `air_code: E0004`; templates/static contracts reject the same known-invalid effect directly with E0006. Effect membership is determined entirely from source and the registry. A P6-2 task should align ordinary signature validation with the existing template contract, preserving effect/capability semantics and checking diagnostic priority/positions. No implementation is included in DD-022.
|
||||
|
||||
**Resolved (DD-023, spec 15 §9):** ordinary signatures validate the existing effect registry before body lowering; templates/static contracts replace the incorrect E0006 with E7002. Fields `name` and `effect` identify the atom without prose; locations retain declaration/parameter starts. Signature/type/from and template/header priority, accepted AIR, effect/capability semantics and AIR E0004 are preserved. Invalid-source diagnostics can change; no new code or reason.
|
||||
@@ -297,3 +297,9 @@ Validation: units and Zig formatting pass; full conformance is 1,560/1,560, with
|
||||
DD-022 synchronizes the grammar/spec 15 with implemented wrappers, binary literals, negative patterns, parenthesized places, declared borrow-return calls and list/arm delimiters. Ordered statement, header-brace and typed-built-in choices are documented; no LL(k) claim is made. Q-050 rejects empty qualified enum payload lists with E7001 at `(`, including generic/grouped/built-in variants and patterns. Ordinary `f()`, bare variants, non-empty payloads and outcome bindings retain their rules. No AIR, verifier/runtime, ownership/concurrency, feature or diagnostic-code changes.
|
||||
|
||||
Validation: units and Zig formatting pass; full conformance is 1,594/1,594, and all 34 new fixtures pass collection before every instruction, including select schedules. CLI integration passes 288 checks for syntax locations, packages, formatting and source/AIR execution. Old/new comparison changes zero check/lower outputs on 1,269 public sources (695 old lowerings); source coverage remains 121/121. The public formatter corpus passes 5,435 checks on 1,303 files, preserving 709 lowered outputs. Claude independently reviewed the change and reran units and CLI checks. Bundle growth is recorded in docs/agent/README.md. P6-1/P6-2 remain open; future syntax still needs its RFCs, and Q-051 is a separate ordinary-effect validation task.
|
||||
|
||||
## P6-2 effect-name diagnostic increment (2026-10-08)
|
||||
|
||||
DD-023 resolves Q-051: ordinary effect declarations validate the existing registry after signature types/from and before body lowering. Templates/static contracts replace incorrect E0006 with E7002; `name` and `effect` identify the atom. Declaration/parameter positions and prior signature/template check order remain. Registered atoms, flat effect sets, static-contract uniqueness, effect coverage, explicit capabilities and AIR E0004 remain unchanged. No new code/reason, syntax, feature, verifier/runtime, ownership/concurrency or evaluation input changes.
|
||||
|
||||
Validation: units and Zig formatting pass; full conformance is 1,618/1,618, and all 24 new fixtures pass collection before every instruction. CLI integration passes 236 checks, including unused/package headers, diagnostic priority, formatter preservation, source/AIR execution, instantiation and independent AIR rejection. Existing generic/static-function/grammar suites pass 32/25/288 checks. Old/new comparison on 1,303 public sources (709 old lowerings) changes only the two corrected E0006 fixtures, preserving their primary positions and `name`; accepted AIR is byte-identical. Claude independently reviewed the change and ran units/fixtures and all 236 CLI checks. Bundle growth is recorded in docs/agent/README.md; P6-2 remains open.
|
||||
@@ -87,7 +87,7 @@ Only problems that exist because of the frontend. Everything the verifier decide
|
||||
| Code | Kind | Meaning |
|
||||
|---|---|---|
|
||||
| E7001 | source.syntax | Malformed `.aji` source |
|
||||
| E7002 | source.unknown_name | Undefined variable, function, type, field or variant; an unknown capability kind is `capability_kind` |
|
||||
| E7002 | source.unknown_name | Undefined variable, function, type, field, variant or effect; an unknown capability kind is `capability_kind`, an unknown effect is `name` and `effect` |
|
||||
| E7003 | source.missing_move | Named linear value consumed without `move` |
|
||||
| E7004 | source.not_exhaustive | `match` misses an outcome, variant or default |
|
||||
| E7005 | source.type_mismatch | Expression has the wrong type in a source position |
|
||||
|
||||
@@ -387,7 +387,7 @@ A byte string or array used where a `slice<u8>` is expected is materialized in f
|
||||
- **Frame storage.** Addressability is a property of lowering, not of source types. Linear values (owners, regions, resources, endpoints, tasks, mutexes) never get frame storage: they are borrowed in place. A variable whose name is borrowed, indexed, or written through a field or element anywhere in the function lowers to `local<T>` storage, allocated in the entry block (spec 08 §11.5). Every other variable is an SSA value. The decision is by name, so the same source always gives the same placement. The frame-size limit applies to the lowered AIR. There is no implicit heap allocation.
|
||||
- **Borrow scopes.** A borrow bound by `ref`/`mut` ends at the end of the block that contains the binding. Because a borrow's name is not visible after its scope, a use after the borrow ended (`E2106`) cannot be written in source. A temporary borrow, used directly as an operand, ends at the end of its statement. Both end at every normal exit from their scope, except the named returned borrow and its owned ancestors transferred under §19. The frontend emits `borrow.end` in reverse order of creation. A borrow that must end earlier is placed in an inner block. Borrows lent to tasks end at the join (spec 04 §34).
|
||||
- **Features.** The frontend emits the `features [...]` header as the dependency closure of the constructs used, always including `effects`.
|
||||
- **Effects.** They are declared by the programmer. `E3101` names the missing effect and suggests the complete effect list (`suggested_effects`).
|
||||
- **Effects.** They are declared by the programmer. Every function/template/static-function contract MUST use registered atoms (`reference/effects.md`); an unknown atom MUST reject E7002 with `name` and `effect`, before body lowering. The source position is the function start, or the static parameter start for its contract. Ordinary signature type/`from` checks and existing template/header check order remain prior checks. Ordinary effect lists retain AIR set semantics; static-function contract effects remain unique (§18). `E3101` names the missing effect and suggests the complete effect list (`suggested_effects`).
|
||||
|
||||
## 10. Diagnostics
|
||||
|
||||
@@ -431,7 +431,7 @@ Its diagnostics keep their AIR codes, reported at the source location.
|
||||
| Code | Kind | Meaning |
|
||||
|---|---|---|
|
||||
| E7001 | source.syntax | Malformed `.aji` source |
|
||||
| E7002 | source.unknown_name | Undefined variable, function, type, field or variant |
|
||||
| E7002 | source.unknown_name | Undefined variable, function, type, field, variant or effect |
|
||||
| E7003 | source.missing_move | Named linear value consumed without `move` |
|
||||
| E7004 | source.not_exhaustive | `match` misses an outcome, variant or default |
|
||||
| E7005 | source.type_mismatch | Expression has the wrong type in a source position |
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ pub const registry = [_]Code{
|
||||
.{ .id = "E6001", .kind = "unsafe.required", .meaning = "Operation requires explicit unsafe boundary; field `reason`: `outside_boundary`, `trusted_declares_unsafe`" },
|
||||
.{ .id = "E6101", .kind = "abi.unaligned_reference", .meaning = "Normal reference requested from insufficiently aligned storage" },
|
||||
.{ .id = "E7001", .kind = "source.syntax", .meaning = "Malformed `.aji` source" },
|
||||
.{ .id = "E7002", .kind = "source.unknown_name", .meaning = "Undefined variable, function, type, field or variant" },
|
||||
.{ .id = "E7002", .kind = "source.unknown_name", .meaning = "Undefined variable, function, type, field, variant or effect" },
|
||||
.{ .id = "E7003", .kind = "source.missing_move", .meaning = "Named linear value consumed without `move`" },
|
||||
.{ .id = "E7004", .kind = "source.not_exhaustive", .meaning = "`match` misses an outcome, variant or default" },
|
||||
.{ .id = "E7005", .kind = "source.type_mismatch", .meaning = "Expression has the wrong type in a source position" },
|
||||
|
||||
@@ -187,3 +187,33 @@ test canonicalBytes {
|
||||
defer a.deinit();
|
||||
try std.testing.expectEqualStrings("b\"hi\\n\\\"\\x01\"", try canonicalBytes(a.allocator(), "hi\n\"\x01"));
|
||||
}
|
||||
|
||||
test "unknown effect names are source errors before AIR in ordinary and template contracts" {
|
||||
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const a = arena.allocator();
|
||||
for ([_][]const u8{
|
||||
"fn bad() -> void effects [bogus.effect] {}",
|
||||
"fn bad<T>(x: T) -> T effects [bogus.effect] { return x; }",
|
||||
"fn bad<F: fn(u64) -> u64 effects [bogus.effect]>() -> void effects [] {}",
|
||||
"struct Bad<F: fn(u64) -> u64 effects [bogus.effect]> { value: u64 }",
|
||||
}, 0..) |declaration, i| {
|
||||
const source = try std.fmt.allocPrint(a, "module test.effects\n{s}\nfn main() -> u64 effects [] {{ return 42; }}", .{declaration});
|
||||
const r = try compile(a, "effects.aji", source);
|
||||
try std.testing.expect(r == .err);
|
||||
try std.testing.expectEqualStrings("E7002", r.err.code.id);
|
||||
try std.testing.expectEqualStrings("effects.aji", r.err.span.?.file);
|
||||
try std.testing.expectEqual(@as(u32, 2), r.err.span.?.line);
|
||||
const col: u32 = if (i == 2) 8 else if (i == 3) 12 else 1;
|
||||
try std.testing.expectEqual(col, r.err.span.?.col);
|
||||
try std.testing.expectEqual(@as(usize, 2), r.err.fields.len);
|
||||
for (r.err.fields) |field| {
|
||||
try std.testing.expect(std.mem.eql(u8, field.name, "name") or std.mem.eql(u8, field.name, "effect"));
|
||||
try std.testing.expectEqualStrings("bogus.effect", field.value.str);
|
||||
}
|
||||
}
|
||||
for (@import("air/authority.zig").effects) |effect| {
|
||||
const source = try std.fmt.allocPrint(a, "module test.effects\nfn unused() -> void effects [{s}] {{}}\nfn main() -> u64 effects [] {{ return 42; }}", .{effect.name});
|
||||
try std.testing.expect((try compile(a, "effects.aji", source)) == .ok);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,14 @@ const Generator = struct {
|
||||
return error.InvalidGeneric;
|
||||
}
|
||||
|
||||
fn unknownEffect(g: *Generator, span: ast.Span, effect: []const u8) Error {
|
||||
g.problem = .{ .code = "E7002", .span = span, .message = "unknown effect", .fields = try g.arena.dupe(lower.Problem.Field, &.{
|
||||
.{ .name = "name", .value = effect },
|
||||
.{ .name = "effect", .value = effect },
|
||||
}) };
|
||||
return error.InvalidGeneric;
|
||||
}
|
||||
|
||||
fn invalid(g: *Generator, reason: lower.InvalidReason, span: ast.Span, message: []const u8, name: []const u8) Error {
|
||||
g.problem = .{ .code = "E7006", .reason = reason, .span = span, .message = message, .fields = try g.arena.dupe(lower.Problem.Field, &.{.{ .name = "name", .value = name }}) };
|
||||
return error.InvalidGeneric;
|
||||
@@ -171,7 +179,7 @@ const Generator = struct {
|
||||
if (std.mem.eql(u8, w, "ref") or std.mem.eql(u8, w, "mut") or std.mem.eql(u8, w, "slice") or std.mem.eql(u8, w, "slice_mut")) return g.invalid(.invalid_static_function, c.ret.span, "static function contracts do not support borrowed returns", p.name);
|
||||
}
|
||||
for (c.effects, 0..) |effect, j| {
|
||||
if (authority.effectIndex(effect) == null) return g.fail("E0006", p.span, "unknown effect in static function contract", effect);
|
||||
if (authority.effectIndex(effect) == null) return g.unknownEffect(p.span, effect);
|
||||
for (c.effects[0..j]) |prev| if (std.mem.eql(u8, prev, effect)) return g.invalid(.invalid_static_function, p.span, "duplicate effect in static function contract", effect);
|
||||
}
|
||||
}
|
||||
@@ -301,7 +309,7 @@ const Generator = struct {
|
||||
try g.validate(f.name, f.generics, f.span);
|
||||
if (f.generics.len != 0) {
|
||||
if (f.trusted != null) return g.invalid(.trusted_unavailable, f.span, "trusted is not available in source templates", f.name);
|
||||
for (f.effects) |effect| if (authority.effectIndex(effect) == null) return g.fail("E0006", f.span, "unknown effect in template contract", effect);
|
||||
for (f.effects) |effect| if (authority.effectIndex(effect) == null) return g.unknownEffect(f.span, effect);
|
||||
for (f.params, 0..) |p, j| {
|
||||
try g.checkBinding(p.name, p.span, .{ .params = f.generics });
|
||||
for (f.params[0..j]) |prev| if (std.mem.eql(u8, p.name, prev.name)) return g.invalid(.duplicate_declaration, p.span, "duplicate value parameter", p.name);
|
||||
|
||||
@@ -466,6 +466,10 @@ const Lowerer = struct {
|
||||
if (ret.isMutBorrow() and !ps[i].isMutBorrow()) return l.fail("E7005", f.span, "an exclusive return requires an exclusive `from` parameter", &.{});
|
||||
} else if (ret.isBorrow()) return l.invalid(.invalid_borrow_return, f.span, "a borrow return requires `from parameter`", &.{});
|
||||
if (std.mem.eql(u8, f.name, "main") and ret.isBorrow()) return l.invalid(.invalid_borrow_return, f.span, "main cannot return a borrow", &.{});
|
||||
for (f.effects) |effect| if (authority.effectIndex(effect) == null) return l.fail("E7002", f.span, "unknown effect", &.{
|
||||
.{ .name = "name", .value = effect },
|
||||
.{ .name = "effect", .value = effect },
|
||||
});
|
||||
try l.sigs.put(l.arena, f.name, .{ .params = ps, .ret = ret, .from = origin, .air_name = f.air_name orelse f.name, .display_name = f.display_name orelse f.name });
|
||||
}
|
||||
if (!l.sigs.contains("main")) return l.fail("E7002", .{ .start = .{ .line = 1, .col = 1 }, .end = .{ .line = 1, .col = 1 } }, "the module has no `main` function", &.{.{ .name = "name", .value = "main" }});
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// grant: heap=mem.alloc:8
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §8, §9
|
||||
module test.effects.allocation
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let value = own.new(42u64, heap) or trap;
|
||||
return own.take(move value);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.body_priority
|
||||
fn main() -> u64 effects [bogus.effect] { return missing; }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: run
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
// result: 42
|
||||
module test.effects.duplicates
|
||||
fn worker() -> u64 effects [atomic, atomic] { return 42; }
|
||||
fn identity<T: Copy>(x: T) -> T effects [atomic, atomic] { return x; }
|
||||
fn main() -> u64 effects [atomic, atomic] { return identity::<u64>(worker()); }
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.entry
|
||||
fn main() -> u64 effects [bogus.effect] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.first_unknown
|
||||
fn unused() -> void effects [atomic, bogus.first, bogus.second,] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §9.2
|
||||
module test.effects.flat_effects
|
||||
fn worker() -> u64 effects [atomic.weak] { return 42; }
|
||||
fn main() -> u64 effects [atomic] { return worker(); }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.from_priority
|
||||
fn unused(x: ref<u64>) -> ref<u64> from missing effects [bogus.effect] { return x; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.keyword_atom
|
||||
fn unused() -> void effects [task.cancelled] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.missing_effect
|
||||
fn worker() -> u64 effects [atomic] { return 42; }
|
||||
fn main() -> u64 effects [] { return worker(); }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.ordinary_trusted
|
||||
fn unused() -> void effects [bogus.effect] trusted "not allowed" {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.ordinary_unused
|
||||
fn unused() -> void effects [unknown] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.other_body_priority
|
||||
fn first() -> u64 effects [] { return missing; }
|
||||
fn last() -> void effects [bogus.effect] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: run
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
// result: 42
|
||||
module test.effects.registered_unused
|
||||
fn unused() -> void effects [atomic, atomic.weak, clock.read, ffi, fs.read, fs.write, io.read, io.write, mem.alloc, mem.map, net.connect, net.listen, net.read, net.write, process.env, process.spawn, random.read, task.spawn, task.wait, thread.block, thread.spawn, unsafe] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.return_priority
|
||||
fn unused() -> Missing effects [bogus.effect] { trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.static_duplicate
|
||||
fn unused<F: fn(u64) -> u64 effects [atomic, atomic]>() -> void effects [] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.static_type
|
||||
struct Holder<F: fn(u64) -> u64 effects [bogus.effect]> { value: u64 }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.static_type_priority
|
||||
fn unused<F: fn(Missing) -> u64 effects [bogus.effect]>() -> void effects [] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.static_unused
|
||||
fn unused<F: fn(u64) -> u64 effects [bogus.effect]>() -> void effects [] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §18
|
||||
module test.effects.static_valid
|
||||
fn worker() -> u64 effects [atomic.weak, atomic] { return 42; }
|
||||
fn apply<F: fn() -> u64 effects [atomic, atomic.weak]>() -> u64 effects [atomic, atomic.weak] { return F(); }
|
||||
fn main() -> u64 effects [atomic, atomic.weak] { return apply::<fn worker>(); }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.template_effect_priority
|
||||
fn unused<T>(x: Missing) -> T effects [bogus.effect] { trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.template_trusted
|
||||
fn unused<T>() -> void effects [bogus.effect] trusted "not allowed" {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.template_unused
|
||||
fn unused<T>(x: T) -> T effects [bogus.effect] { return x; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.template_used
|
||||
fn identity<T>(x: T) -> T effects [bogus.effect] { return x; }
|
||||
fn main() -> u64 effects [] { return identity::<u64>(42); }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §9, §18
|
||||
module test.effects.type_priority
|
||||
fn unused(x: Missing) -> void effects [bogus.effect] {}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -1,4 +1,4 @@
|
||||
// expect: reject E0006
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §15
|
||||
module demo.generic
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// expect: reject E0006
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §18
|
||||
module test.static_functions
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Effect registry errors are source diagnostics; AIR contracts remain intact."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
AJI = REPO / 'zig-out/bin/aji'
|
||||
CORPUS = REPO / 'tests/conformance/source/effect_names'
|
||||
checks = 0
|
||||
|
||||
|
||||
def cli(*args, code=0):
|
||||
global checks
|
||||
result = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True)
|
||||
assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr)
|
||||
checks += 1
|
||||
return result.stdout
|
||||
|
||||
|
||||
expected = {
|
||||
'ordinary_unused': ('unknown', 1), 'entry': ('bogus.effect', 1),
|
||||
'body_priority': ('bogus.effect', 1), 'other_body_priority': ('bogus.effect', 1),
|
||||
'template_unused': ('bogus.effect', 1), 'template_used': ('bogus.effect', 1),
|
||||
'template_effect_priority': ('bogus.effect', 1), 'ordinary_trusted': ('bogus.effect', 1),
|
||||
'static_unused': ('bogus.effect', 11), 'static_type': ('bogus.effect', 15),
|
||||
'keyword_atom': ('task.cancelled', 1), 'first_unknown': ('bogus.first', 1),
|
||||
}
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix='aji-effects-') as directory:
|
||||
root = Path(directory)
|
||||
for path in sorted(CORPUS.glob('*.aji')):
|
||||
source = path.read_text()
|
||||
formatted = root / path.name
|
||||
formatted.write_text(cli('fmt', path))
|
||||
cli('fmt', '--check', formatted)
|
||||
assert cli('fmt', formatted) == formatted.read_text()
|
||||
if '// expect: reject' in source:
|
||||
error = json.loads(cli('check', path, code=1))
|
||||
assert error['code'] == re.search(r'// expect: reject (E\d+)', source)[1], error
|
||||
if path.stem in expected:
|
||||
atom, col = expected[path.stem]
|
||||
assert (error['name'], error['effect']) == (atom, atom), error
|
||||
line = next(i for i, text in enumerate(source.splitlines(), 1)
|
||||
if 'effects [' in text and atom in text)
|
||||
assert (error['file'], error['line'], error['col']) == (str(path), line, col), error
|
||||
assert 'reason' not in error and 'air_code' not in error and 'air_line' not in error, error
|
||||
elif path.stem in ('type_priority', 'return_priority', 'static_type_priority', 'from_priority'):
|
||||
assert error['name'] == ('missing' if path.stem == 'from_priority' else 'Missing'), error
|
||||
assert 'effect' not in error, error
|
||||
elif path.stem in ('static_duplicate', 'template_trusted'):
|
||||
assert error['reason'] == ('invalid_static_function' if path.stem == 'static_duplicate' else 'trusted_unavailable'), error
|
||||
commands = ('lower', 'run', 'report', 'explore') if error['code'].startswith('E7') else ('run', 'report', 'explore')
|
||||
for command in commands:
|
||||
assert json.loads(cli(command, path, code=1)) == error
|
||||
if not error['code'].startswith('E7'):
|
||||
raw = root / (path.stem + '.air')
|
||||
raw.write_text(cli('lower', path))
|
||||
assert json.loads(cli('check', raw, code=1))['code'] == error['code']
|
||||
formatted_error = json.loads(cli('check', formatted, code=1))
|
||||
assert formatted_error['code'] == error['code']
|
||||
if error['code'] == 'E7002' and 'effect' in error:
|
||||
assert formatted_error['name'] == formatted_error['effect'] == error['effect']
|
||||
continue
|
||||
cli('check', path)
|
||||
lowered = cli('lower', path)
|
||||
assert cli('lower', formatted) == lowered
|
||||
air = root / (path.stem + '.air')
|
||||
air.write_text(lowered)
|
||||
cli('check', air)
|
||||
grants = [value for grant in re.findall(r'// grant: (.+)', source)
|
||||
for value in ('--grant', grant)]
|
||||
result = json.loads(cli('run', '--fuel', '100000', *grants, path))
|
||||
assert result['value'] == 42, result
|
||||
assert result == json.loads(cli('run', '--fuel', '100000', *grants, air))
|
||||
if path.stem == 'allocation':
|
||||
assert json.loads(cli('run', '--fuel', '100000', path, code=6))['status'] == 'not_instantiated'
|
||||
|
||||
# Imported unused ordinary/template/static signatures retain module provenance.
|
||||
entry, library, manifest = (root / name for name in ('main.aji', 'lib.aji', 'aji.toml'))
|
||||
manifest.write_text('[package]\nname = "effects"\nversion = "1"\nentry = "main.aji"\n'
|
||||
'[modules]\nlib.test = "lib.aji"\n')
|
||||
entry.write_text('module app\nimport lib.test;\nfn main() -> u64 effects [] { return 42; }\n')
|
||||
for declaration, col in (
|
||||
('fn unused() -> void effects [bogus.effect] {}', 1),
|
||||
('fn unused<T>(x: T) -> T effects [bogus.effect] { return x; }', 1),
|
||||
('fn unused<F: fn(u64) -> u64 effects [bogus.effect]>() -> void effects [] {}', 11),
|
||||
):
|
||||
library.write_text('module lib.test\n' + declaration + '\n')
|
||||
error = json.loads(cli('check', '--manifest', manifest, code=1))
|
||||
assert (error['code'], error['name'], error['effect']) == ('E7002', 'bogus.effect', 'bogus.effect'), error
|
||||
assert (error['file'], error['line'], error['col']) == ('lib.aji', 2, col), error
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert json.loads(cli(command, '--manifest', manifest, code=1)) == error
|
||||
|
||||
# Existing template validation still precedes ordinary signature lowering.
|
||||
entry.write_text('module app\nfn first() -> void effects [bogus.effect] {}\n'
|
||||
'fn unused<lowercase>() -> void effects [] {}\n'
|
||||
'fn main() -> u64 effects [] { return 42; }\n')
|
||||
error = json.loads(cli('check', entry, code=1))
|
||||
assert error['code'] == 'E7006' and error['reason'] == 'invalid_generic', error
|
||||
|
||||
# Text AIR independently keeps E0004; it does not become a source name error.
|
||||
raw = root / 'unknown.air'
|
||||
raw.write_text('module test\nair 0\nlang 0.1\nfeatures [effects]\n'
|
||||
'fn @main() -> u64\neffects [bogus.effect]\nentry:\n'
|
||||
' %x = const.u64 42\n ret %x\n')
|
||||
error = json.loads(cli('check', raw, code=1))
|
||||
assert error['code'] == 'E0004' and error['name'] == 'bogus.effect', error
|
||||
assert 'effect' not in error and 'air_code' not in error, error
|
||||
|
||||
print(f'source effect names: {checks} checks passed')
|
||||
Reference in new issue
Block a user