cli: check inferred array elements before AIR

This commit is contained in:
dev committed 2026-10-08 09:26:33 +03:00
1 parent cfbe01a16f
commit 1bbfed24a8
40 files changed
+337 -9

No files matched your search

+1
View File
@@ -30,6 +30,7 @@ jobs:
- run: python3 tests/hosted/source_array_arguments.py
- run: python3 tests/hosted/source_type_positions.py
- run: python3 tests/hosted/source_own_array_content.py
- run: python3 tests/hosted/source_array_literals.py
- run: python3 tests/hosted/examples.py --stress 200
- run: python3 tests/hosted/source_static_functions.py
- run: python3 tests/hosted/source_linear.py
+1
View File
@@ -26,6 +26,7 @@ python3 tests/hosted/source_lifetimes.py # AIR rejection twins and exact lifetim
python3 tests/hosted/source_array_arguments.py # array argument shape, cleanup, AIR and package parity
python3 tests/hosted/source_type_positions.py # structural type errors at annotations, templates and packages
python3 tests/hosted/source_own_array_content.py # Copy content, nominal/generic types and repeated allocations
python3 tests/hosted/source_array_literals.py # inferred elements, repetitions, explicit moves and packages
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
+2
View File
@@ -158,3 +158,5 @@ Q-023 whole-array arguments (DD-021, cl100k): Quick Reference 8,889 → 8,948 (+
Q-042 structural type positions (cl100k): Quick Reference stays 8,948; other source docs 66,669 → 66,761 (+92), full source 75,617 → 75,709 (+0.12%). o200k groups are 8,984 / 66,965 / 75,949; Qwen2.5 9,226 / 68,398 / 77,624. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing type-position predicates now reject invalid source annotations before AIR, including known unused generic headers, with structured E7005 fields at the constructor. No new concept, syntax, code, feature or verifier/runtime state is added. Earlier source diagnostic codes/fields may change; graph properties retain verifier diagnostics. No empirical MCC benefit is claimed.
Q-043 dynamic owning-array content (cl100k): Quick Reference stays 8,948; other source docs 66,761 → 66,827 (+66), full source 75,709 → 75,775 (+0.09%). o200k groups are 8,984 / 67,031 / 76,015; Qwen2.5 9,226 / 68,466 / 77,692. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing Copy-content rules now reject annotations and repeated allocation values with structured E7005 before AIR, including known unused generic/static contracts and nominal contents. Unknown parameters defer to substitution; iref remains phantom. No new concept, syntax, code, feature or verifier/runtime state is added. Earlier invalid-source diagnostics and priority may change; graph-root properties retain verifier diagnostics. No empirical MCC benefit is claimed.
Q-045 inferred array literals (cl100k): Quick Reference stays 8,948; other source docs 66,827 → 66,906 (+79), full source 75,775 → 75,854 (+0.10%). o200k groups are 8,984 / 67,110 / 76,094; Qwen2.5 9,226 / 68,550 / 77,776. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing member-position and Copy-repetition rules now reject invalid inferred elements before AIR, at the offending value. Lists retain explicit linear transfers; repeated borrows retain E7006 invalid_literal. No new concept, syntax, code, reason, feature or verifier/runtime state is added. Invalid-source diagnostic codes/priority may change; accepted canonical AIR is preserved. No empirical MCC benefit is claimed.
+7 -1
View File
@@ -331,4 +331,10 @@ Audit the existing classification/layout ordering and shared-query cost with cou
Q-043 review reproduced `fn unused(p: ref<u64>) -> void effects [] { let a = [p, p]; }`: the source array literal reaches AIR type checking with E1001 because borrows cannot be stored as array elements. Q-042 validates annotations; an inferred literal has none. Q-043 now rejects that array as a repeated `own.array` value, but constructing it without that operation remains a separate source validation gap.
Audit inferred list/repeat literals against existing member-position and Copy-duplication rules, including nested arrays and nominal values. Add source positives/rejections with E7005 at the offending source value while preserving explicit moves in fixed linear arrays, borrow provenance and frozen AIR semantics. Scope beyond this reproduced literal remains unverified.
**Resolved (spec 15 §5/§10):** each inferred list/repeat element is checked before array construction. Borrows retain E7006 `invalid_literal`; forbidden member constructors (including void/never/task) report E7005 with `position` and `type_constructor`. Repeated elements use the verifier's exact Copy predicate and report E7005 with `constraint: Copy` and `type_constructor: array`. Lists preserve explicit linear moves, E7003 for missing moves and verifier E2002 for duplicates. Element validity precedes expected-type agreement with or without an annotation; an invalid annotation itself still rejects first. Thus some earlier mismatches/ownership-wrapper errors are replaced by a diagnostic at the first invalid element. The Q-043 `own.array` check remains a second line of defense. AIR acceptance, verifier/runtime rules and valid-source canonical output are unchanged. Wrapper construction from inferred values is separate (Q-046).
## Q-046 — Inferred content types in ownership and graph constructors
Q-045 review reproduced `fn unused(heap: cap<mem.alloc>, p: ref<u64>) -> void effects [mem.alloc] { let a = own.new(p, heap) or trap; trap; }`: the inferred `own<ref<u64>>` reaches AIR E1001 in member position. Existing source annotations reject this under Q-042, but the constructor infers its content type from a value. Review identified analogous call paths in `own.pack`, `mutex.make` and graph allocation; those additional cases remain unverified.
Audit each constructor against its own existing content/position/property rules and diagnostic precedence before changing it. In particular, distinguish Copy-only construction, explicit linear transfer and graph-content E2111. Add source positives/rejections and stable E7xxx at fully source-decided errors, preserving provenance, effects/capabilities, outcomes and frozen AIR behavior. Do not apply one broad Copy restriction to every wrapper.
+8
View File
@@ -253,3 +253,11 @@ Q-043/spec 15 §10 enforces the existing Copy-content requirement for source `ow
The preserved invariant is that repeated dynamic heap arrays contain Copy values, so bulk release cannot destroy nested resources. AIR independently retains the same type/operation checks; allocation budgets, initialization, owner transfer, explicit release and deterministic interpreter behavior are unchanged. Valid Copy allocations run with explicit release; rejected annotations and repeated linear values report E7005 with `constraint` and `type_constructor`. Existing invalid-source codes/priority may change, including Copy violations preceding simultaneous layout errors. No syntax, code, feature, verifier/runtime state or evaluation input changes. Source bundle growth is recorded in docs/agent/README.md; P6-2 remains open.
Validation: full conformance 1,335/1,335; all 32 new fixtures also pass with per-instruction collection. Unit tests pass 128/128, including counted acyclic/cyclic diamond queries; the cyclic case failed before the cache correction. CLI integration passes 119 checks with exact annotations/value positions, nested package imports and source/AIR/hosted parity. Formatter passes 4,563 checks over 1,047 public files (1,039 parsed, eight existing syntax errors, 638 identical AIR outputs); source coverage remains 121/121. Comparison of all 1,017 preceding public sources preserves every check/lower result and all 631 successful canonical lowerings. No AIR verifier/runtime files change. Independent Claude review passes after checking shadowing, generic rotations, cache invalidation and the complete declaration snapshot used by the shared Copy predicate.
## P6-2 inferred array literals (2026-10-08)
Q-045/spec 15 §5/§10 applies the existing member-position rule to each inferred array element before construction and the exact verifier Copy predicate to repetitions. Borrow elements reject E7006 invalid_literal; forbidden constructors and non-Copy repeats reject E7005 at the value with structured fields. Element validity precedes expected-type agreement; annotation errors still reject first. Existing linear lists preserve explicit moves and complete-value transfer, including missing-move and duplicate-owner diagnostics.
The invariants are that second-class borrows cannot become stored members and repetition cannot duplicate a linear value. AIR still independently checks the same rules. No allocation, lifetime, task transfer, cleanup, deterministic interpreter behavior, syntax, code/reason, feature, verifier/runtime state or evaluation input changes. Valid linear lists explicitly unpack/release their owners; Copy and temporary-slice programs run unchanged. Invalid-source errors formerly reaching E1001/E0006/E7900 now stop earlier; the preceding own.array borrow-array fixture now rejects at its literal. New source tests and CLI/package/profile checks cover the changes. Source bundle growth is recorded in docs/agent/README.md; Q-046 records the separate inferred-wrapper audit, and P6-2 remains open.
Validation: full conformance 1,364/1,364; all 29 new fixtures pass with per-instruction collection. Unit tests pass 128/128. CLI integration passes 152 checks covering exact positions/fields, all diagnostic commands, never-valued calls, generic package provenance, source/AIR/hosted parity and formatter idempotence; the preceding own.array suite remains 119/119. Formatter passes 4,664 checks over 1,078 public files (1,070 parsed, eight existing syntax errors, 642 identical AIR outputs); source coverage remains 121/121. Comparison of 1,049 preceding public sources finds only two expected invalid-program diagnostic changes, with unchanged acceptance and every other canonical lowering identical. No AIR verifier/runtime files change. Independent Claude review passes.
+2 -1
View File
@@ -205,7 +205,7 @@ The value is evaluated first, then the place is borrowed for the store and the b
**Arrays and byte strings.**
- `[e; N]` evaluates `e` once and copies the value N times (`array.splat`). The element must be copyable; a linear element rejects (E1001 for the §16 surface).
- `[e; N]` evaluates `e` once and copies the value N times (`array.splat`). The element must be Copy; a non-Copy value rejects E7005 at `e`, with `constraint: Copy` and `type_constructor: array`. A borrowed element retains E7006 `invalid_literal`.
- `b"…"` is an immutable `[u8; N]` value held in frame storage, written there byte by byte, with no heap. The escapes are exactly `\n \r \t \\ \" \0 \xNN`.
- Used where a `slice<u8>` is expected, it is borrowed for the operation.
@@ -404,6 +404,7 @@ A byte string or array used where a `slice<u8>` is expected is materialized in f
- slice element types of `slice.copy`;
- the element rules of channels and mutexes (no borrow, scope, task, shield or guard).
- Copy content of `own_array<T>` and the repeated value of `own.array`; an invalid content type is E7005 at that annotation/value, with `constraint: Copy` and `type_constructor: own_array`. Known linear content in unused generic signatures and static contracts MUST reject; unknown type parameters are checked after substitution.
- Inferred array literal elements MUST satisfy the existing member-position rules. Borrowed elements reject E7006 `invalid_literal`; other invalid constructors reject E7005 at the element with `position: member` and `type_constructor`. Lists preserve explicit linear transfers; repetitions MUST satisfy Copy.
Source type annotations MUST satisfy the existing AIR type-position rules (spec 07 §8.3/§8.8), including nested constructors. An invalid constructor is E7005 at its annotation, with `position` and `type_constructor` fields. Known constructors in unused generic signatures and static function contracts MUST be checked; restrictions depending on a type parameter are checked after substitution. Graph-content properties and feature gates for otherwise correctly positioned types retain their verifier diagnostics.
+15 -1
View File
@@ -762,6 +762,19 @@ const Lowerer = struct {
// ------------------------------------------------------------ functions
fn arrayElement(l: *Lowerer, span: Span, ty: Ty, repeated: bool) Error!void {
if (ty.isBorrow()) return l.invalid(.invalid_literal, span, "an array element cannot be a borrow", &.{});
const t = try l.airType(ty);
if (!verifier_types.allowedPosition(std.meta.activeTag(t), .member, true)) return l.fail("E7005", span, "type constructor not allowed in this position", &.{
.{ .name = "position", .value = "member" },
.{ .name = "type_constructor", .value = @tagName(t) },
});
if (repeated and !verifier_types.isCopy(l.property_module.?, t)) return l.fail("E7005", span, "an array repetition requires Copy content", &.{
.{ .name = "constraint", .value = "Copy" },
.{ .name = "type_constructor", .value = "array" },
});
}
fn function(l: *Lowerer, f: ast.FnDecl) Error!FnOut {
l.blocks = .empty;
l.bindings = .empty;
@@ -1576,6 +1589,7 @@ const Lowerer = struct {
var names: std.ArrayList(u8) = .empty;
for (xs, 0..) |x, i| {
const v = try l.consuming(x, ty);
try l.arrayElement(x.span, v.ty, false);
if (ty) |t| try l.checkTy(x.span, v.ty, t) else ty = v.ty;
try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name }));
}
@@ -1586,7 +1600,7 @@ const Lowerer = struct {
if (x.len == 0 or x.len > (@as(u64, 1) << 32)) return l.fail("E7005", e.span, "array length must be between 1 and 2^32", &.{});
const want_elem: ?Ty = if (want) |w| (if (w == .array) w.array.elem else null) else null;
const v = try l.expr(x.e.*, want_elem);
if (v.ty.isBorrow()) return l.invalid(.invalid_literal, x.e.span, "an array element cannot be a borrow", &.{});
try l.arrayElement(x.e.span, v.ty, true);
const at = try l.arrayOf(v.ty, x.len);
return l.def("arr", at, try l.fmt("array.splat {s} %{s}", .{ l.tyText(at), v.name }), e.span);
},
@@ -0,0 +1,6 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
fn unused(p: ref<u64>) -> void effects [] { let a: [u64; 2] = [p, p]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
fn unused(p: ref<u64>) -> void effects [] { let a: [ref<u64>; 2] = [p, p]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
fn unused(p: own<u64>) -> void effects [] { let a: [own<u64>; 2] = [move p; 2]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
fn unused() -> void effects [] { let a: [void; 2] = [assert(true); 2]; }
fn main() -> void effects [] {}
@@ -0,0 +1,7 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
fn read(p: slice<u64>) -> u64 effects [] { return p[0]; }
fn unused(p: ref<u64>) -> void effects [] { let x = read([p, p]); }
fn main() -> void effects [] {}
@@ -0,0 +1,7 @@
// expect: accept
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
struct Node { value: own<u64> }
fn unused(a: iref<Node>, b: iref<Node>, cap: cap<mem.alloc>) -> void effects [] { let refs = [a, b]; let repeated = [a; 2]; let caps = [cap; 2]; }
fn main() -> void effects [] {}
@@ -0,0 +1,7 @@
// expect: run
// result: 42
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
struct Item { value: u64 }
fn main() -> u64 effects [] { let values = [[Item { value: 21u64 }; 2]; 3]; ref r = values; return r[0][0].value + r[2][1].value; }
@@ -0,0 +1,7 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
fn bad<T>(x: T) -> void effects [] { let a = [x, x]; }
fn use(p: ref<u64>) -> void effects [] { bad::<ref<u64>>(p); }
fn main() -> void effects [] {}
@@ -0,0 +1,16 @@
// expect: run
// result: 42
// grant: heap=mem.alloc:64
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
struct Item { value: own<u64> }
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
let left = own.new(20u64, heap) or trap;
let right = own.new(22u64, heap) or trap;
let data = [Item { value: move left }, Item { value: move right }];
let (a, b) = array.unpack(move data);
let (x,) = struct.unpack(move a);
let (y,) = struct.unpack(move b);
return own.take(move x) + own.take(move y);
}
@@ -0,0 +1,6 @@
// expect: reject E2002
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: own<u64>) -> void effects [] { let a = [move p, move p]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7003
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: own<u64>) -> void effects [] { let a = [p]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
fn unused(p: ref<u64>) -> void effects [] { let a = [1u64, p]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: ref<u64>) -> void effects [] { let a = [p, 1u64]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: ref<u64>) -> void effects [] { let a = [[p, p], [p, p]]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: ref<u64>) -> void effects [] { let a = [p, p]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: slice<u64>) -> void effects [] { let a = [p, p]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: task<u64>) -> void effects [] { let a = [move p]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused() -> void effects [] { let a = [1u64, true]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused() -> void effects [] { let a = [assert(true), assert(true)]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: own<u64>) -> void effects [] { let a = [[move p]; 2]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,7 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
struct Item { value: own<u64> }
fn unused(p: Item) -> void effects [] { let a = [move p; 2]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: own<u64>) -> void effects [] { let a = [move p; 2]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: own_array<u64>) -> void effects [] { let a = [move p; 2]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: own<u64>) -> void effects [] { let a = [p; 1]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: ref<u64>) -> void effects [] { let a = [p; 2]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: slice<u64>) -> void effects [] { let a = [p; 2]; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused(p: task<u64>) -> void effects [] { let a = [move p; 2]; trap; }
fn main() -> void effects [] {}
@@ -0,0 +1,6 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10; docs/spec/07-air.md §8.8
module test.array_literals
fn unused() -> void effects [] { let a = [assert(true); 2]; }
fn main() -> void effects [] {}
@@ -0,0 +1,7 @@
// expect: run
// result: 42
// phase: 6
// spec: docs/spec/15-source-language.md §5/§10
module test.array_literals
fn first(p: slice<u64>) -> u64 effects [] { return p[0]; }
fn main() -> u64 effects [] { let a = [21u64, 21u64]; let b = [21u64; 2]; return first(ref a) + first(ref b); }
@@ -1,4 +1,4 @@
// expect: reject E1001
// expect: reject E7005
// grant: heap=mem.alloc:64
// phase: 6
// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16
@@ -1,4 +1,4 @@
// expect: reject E7005
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md §10
module test.own_array_content
+101
View File
@@ -0,0 +1,101 @@
#!/usr/bin/env python3
"""Inferred array element diagnostics, ownership and package/profile parity."""
import json
from pathlib import Path
import subprocess
import tempfile
REPO = Path(__file__).resolve().parents[2]
AJI = REPO / 'zig-out/bin/aji'
CORPUS = REPO / 'tests/conformance/source/array_literals'
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
def reject(path, token, code, fields, *args, line=5, expected_file=None):
error = json.loads(cli('check', *args, code=1))
assert error['code'] == code, error
for key, value in fields.items():
assert error[key] == value, error
text = path.read_text().splitlines()[line - 1]
assert (error['file'], error['line'], error['col']) == (
expected_file or str(path), line, text.index(token) + 1), error
assert 'air_line' not in error and 'air_col' not in error, error
for command in ('lower', 'run', 'report', 'explore'):
assert json.loads(cli(command, *args, code=1)) == error
for name, token in (
('list_ref', 'p, p'), ('list_nested_ref', 'p, p'),
('list_slice', 'p, p'), ('list_mixed_ref', 'p, 1u64'),
('list_mixed_later_ref', 'p]'), ('rep_ref', 'p; 2'),
('rep_slice', 'p; 2'), ('generic_ref', 'x, x'),
('annotated_expected_ref', 'p, p'),
):
path = CORPUS / f'{name}.aji'
reject(path, token, 'E7006', {'reason': 'invalid_literal'}, path)
for name, token, constructor in (
('list_void', 'assert(true)', 'void'),
('rep_void', 'assert(true)', 'void'),
('list_task', 'move p', 'task'), ('rep_task', 'move p', 'task'),
('annotated_ref', 'ref<u64>; 2', 'ref'),
('annotated_void', 'void; 2', 'void'),
):
path = CORPUS / f'{name}.aji'
reject(path, token, 'E7005', {'position': 'member', 'type_constructor': constructor}, path)
for name, token, line in (
('rep_owner', 'move p', 5), ('rep_owner_name', 'p; 1', 5),
('rep_owner_array', 'move p', 5), ('rep_nominal', 'move p', 6),
('rep_nested_linear', '[move p]', 5), ('annotated_repeat_owner', 'move p', 5),
):
path = CORPUS / f'{name}.aji'
reject(path, token, 'E7005', {'constraint': 'Copy', 'type_constructor': 'array'}, path, line=line)
with tempfile.TemporaryDirectory(prefix='aji-array-literals-') as directory:
root = Path(directory)
for name, literal in (('never_list', '[stop()]'), ('never_repeat', '[stop(); 2]')):
path = root / f'{name}.aji'
path.write_text('module test.never\nfn stop() -> never effects [] { trap; }\n'
f'fn unused() -> void effects [] {{ let a = {literal}; }}\n'
'fn main() -> void effects [] {}\n')
reject(path, 'stop()', 'E7005', {'position': 'member', 'type_constructor': 'never'}, path, line=3)
for name in ('linear_list', 'copy_nested', 'slice_materialization'):
source = CORPUS / f'{name}.aji'
raw = root / f'{name}.air'
air = cli('lower', source)
assert cli('lower', source) == air
raw.write_text(air)
cli('check', raw)
grants = ['--grant', 'heap=mem.alloc:64'] if name == 'linear_list' else []
expected = json.loads(cli('run', '--fuel', '100000', *grants, source))
assert expected['value'] == 42
assert json.loads(cli('run', '--fuel', '100000', *grants, raw)) == expected
result = root / f'{name}.json'
cli('run', '--profile', 'hosted', '--fuel', '100000', *grants, '--result-file', result, source)
assert json.loads(result.read_text())['value'] == 42
formatted = root / f'{name}.aji'
formatted.write_text(cli('fmt', source))
cli('fmt', '--check', formatted)
assert cli('fmt', formatted) == formatted.read_text()
assert cli('lower', formatted) == air
entry, library, manifest = (root / name for name in ('main.aji', 'literals.aji', 'aji.toml'))
entry.write_text('module app\nimport lib.literals;\nfn use(p: ref<u64>) -> void effects [] { lib.literals.bad::<ref<u64>>(p); }\nfn main() -> u64 effects [] { return 42; }\n')
library.write_text('module lib.literals\nfn bad<T>(x: T) -> void effects [] { let a = [x, x]; }\n')
manifest.write_text('[package]\nname = "literals"\nversion = "1"\nentry = "main.aji"\n[modules]\nlib.literals = "literals.aji"\n')
reject(library, 'x, x', 'E7006', {'reason': 'invalid_literal'}, '--manifest', manifest,
line=2, expected_file='literals.aji')
library.write_text('module lib.literals\nfn bad<T>(x: T) -> void effects [] { let a = [21u64; 2]; }\n')
assert json.loads(cli('run', '--manifest', manifest))['value'] == 42
entry.write_text('module app\nfn main() -> u64 effects [] { return 42; }\n')
library.write_text('module lib.literals\nfn bad<T>(x: T) -> void effects [] { let a = [x, x]; }\n')
assert json.loads(cli('run', '--manifest', manifest))['value'] == 42
print(f'array literal CLI integration passed ({checks} checks)')
+8 -4
View File
@@ -19,10 +19,13 @@ def cli(*args, code=0):
return result.stdout
def rejection(path, token, *args, expected_file=None, line=5):
def rejection(path, token, *args, expected_file=None, line=5, borrow_literal=False):
error = json.loads(cli('check', *args, code=1))
assert error['code'] == 'E7005', error
assert error['constraint'] == 'Copy' and error['type_constructor'] == 'own_array', error
if borrow_literal:
assert error['code'] == 'E7006' and error['reason'] == 'invalid_literal', error
else:
assert error['code'] == 'E7005', error
assert error['constraint'] == 'Copy' and error['type_constructor'] == 'own_array', error
text = path.read_text().splitlines()[line - 1]
assert (error['file'], error['line'], error['col']) == (
expected_file or str(path), line, text.index(token) + 1), error
@@ -43,11 +46,12 @@ for name, token in (
('operation_ref', 'p, heap'),
('operation_slice', 'p, heap'),
('operation_void', 'assert(true)'),
('operation_array_ref', 'a, heap'),
('iref_nested', 'own<u64>'),
):
path = CORPUS / f'{name}.aji'
rejection(path, token, path)
borrow_array = CORPUS / 'operation_array_ref.aji'
rejection(borrow_array, 'p, p', borrow_array, borrow_literal=True)
for name, token in (('specialized', 'own<u64>'), ('forward', '[Linear; 2]'),
('enum', 'Linear>'), ('generic_nominal', 'Linear<T>'),
('nested_generic', 'Pair<Pair<own<T>>>'), ('graph_owner', 'island<Node>')):