verifier: cache structural properties and nominal size queries
This commit is contained in:
1 parent
41f3afbf05
commit
48b9b42fed
31 files changed
+1399
-166
No files matched your search
@@ -34,6 +34,7 @@ jobs:
|
||||
- run: python3 tests/hosted/source_inferred_content.py
|
||||
- run: python3 tests/hosted/source_nonvalue_operands.py
|
||||
- run: python3 tests/hosted/source_store_modes.py
|
||||
- run: python3 tests/hosted/source_nominal_queries.py
|
||||
- run: python3 tests/hosted/examples.py --stress 200
|
||||
- run: python3 tests/hosted/source_static_functions.py
|
||||
- run: python3 tests/hosted/source_linear.py
|
||||
|
||||
@@ -30,6 +30,7 @@ python3 tests/hosted/source_array_literals.py # inferred elements, repetitions,
|
||||
python3 tests/hosted/source_inferred_content.py # constructor content, transfers, recovery and package provenance
|
||||
python3 tests/hosted/source_nonvalue_operands.py # never operands, divergent receivers, traps and package provenance
|
||||
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/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
|
||||
|
||||
@@ -327,6 +327,8 @@ Q-043 review identified a separate existing cost in `Lowerer.linearAt`: repeated
|
||||
|
||||
Audit the existing classification/layout ordering and shared-query cost with counted tests, preserving structural ownership classes, graph/iref boundaries, source E1003 provenance, accepted-source canonical AIR and frozen AIR behavior. Avoid wall-clock timeout tests. This is an implementation audit, not a new recursion or memory rule.
|
||||
|
||||
**Resolved:** lowering reads structural linearity from a resolved nominal-property table after finite-layout checks. AIR verification rebuilds the same table before type checking, with a monotone dependency worklist for the existing predicates, depth-64 guard and source depth-32 witness pruning. The earlier budget stage memoizes sizes by nominal index and depth, preserving cutoff, overflow and E5101 precedence exactly. Checked modules retain immutable caches for subsequent queries. Counted diamond/cycle tests and differential small-graph tests cover all predicates, witness order, depth boundaries, sizes and caller-supplied cache rejection. Source/AIR diagnostics, ownership classes, valid canonical AIR and runtime semantics are unchanged; standalone uncached helpers remain available for small test oracles.
|
||||
|
||||
## Q-045 — Source array literals with second-class elements
|
||||
|
||||
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.
|
||||
|
||||
@@ -91,6 +91,10 @@ These hold for the whole toolchain, not only deterministic mode:
|
||||
- `std.testing.allocator` in unit tests to catch leaks.
|
||||
- No global mutable state; pass allocators and `std.Io` explicitly.
|
||||
|
||||
Structural queries share a per-module table over resolved nominal declarations. A reverse-dependency worklist computes the existing boolean predicates, saturated traversal height and nearest forbidden source-element depth; named queries then read that immutable table. Existential properties start false, universal properties true, height increases and witness distance decreases to their existing depth limits. Cycles therefore terminate without a traversal timeout; existing layout/type checks still decide rejection. The verifier rebuilds the table rather than trusting one supplied by a caller. Source lowering builds it after finite-layout checking, preserves diagnostic order and uses the same declaration snapshot. The witness search retains field order and its depth-32 boundary, pruning subtrees with no reachable witness. Tests count evaluations and compare the cached predicates against uncached derivations on small acyclic modules. This changes implementation cost, not AIR meaning, ownership classes or runtime behavior.
|
||||
|
||||
The budget stage separately memoizes accounted sizes by nominal index and depth. Including depth preserves the previous cutoff and overflow diagnostics exactly, with at most V × (V + 2) nominal states; shared paths no longer expand exponentially. Verification returns a module carrying read-only caches for subsequent report/interpreter queries. Replacing a module's declarations invalidates its caches. Standalone uncached property/size helpers retain their recursive derivations for small differential tests.
|
||||
|
||||
## Zig conventions
|
||||
|
||||
- Zig 0.17.0, formatted with `zig fmt`.
|
||||
|
||||
@@ -285,3 +285,9 @@ Q-048/spec 15 §10 rejects stores through shared borrows, and checks explicit `m
|
||||
The preserved invariant is that explicit `mut` cannot create exclusive access from shared access. AIR independently enforces borrow/store modes, aliases, lifetimes and linear content/projection restrictions. No runtime state, allocation, cleanup, deterministic interpreter behavior, syntax, code/reason, feature or evaluation input changes. Positive source/AIR runs exercise scalar/field/index/range writes and owning content; rejected cases cover shared modes and retained verifier rules. Q-049 records the separate unresolved Copy-let frame-content policy. Bundle growth is recorded in docs/agent/README.md; P6-2 remains open.
|
||||
|
||||
Validation: full conformance passes 1,543/1,543; units and Zig formatting pass. The 46 new fixtures pass with collection before every instruction; CLI integration passes 348 checks, including exact fields/positions, diagnostic commands, formatting, imported generic templates and source/AIR/hosted execution. Existing array-argument/non-value/linear/borrow-return CLI suites pass 85/635/49/133 checks. Comparison on 1,211 preceding public sources (673 successful old lowerings) changes only the message of two rejected inputs; accepted AIR is byte-identical. All eleven new runtime fixtures also retain the previous compiler's AIR. The formatter corpus passes 5,289 checks on 1,257 public files (1,249 parsed, eight existing syntax errors, 686 identical AIR outputs); coverage remains 121/121. Independent read-only review by Claude approved the access-mode checks and confirmed the two diagnostic-message changes.
|
||||
|
||||
## P6-2 nominal query cost (2026-10-08)
|
||||
|
||||
Q-044 replaces repeated nominal walks with a shared property table and memoizes the earlier AIR accounted-size query by index/depth. The invariant is exact structural classification: existing tag rules, graph/iref boundaries, ownership classes, diagnostic ordering and depth guards remain. The verifier rebuilds caches rather than trusting callers; lowering classifies only after finite-layout checks. No verifier rule, AIR meaning, diagnostic/code/reason, source syntax, feature, interpreter state, allocation/cleanup behavior or bundle text changes. Nominal size states have the documented polynomial bound V × (V + 2), preserving the former depth-dependent calculation. Valid deep diamonds/phantom nodes and rejected cycles, oversized values, annotations and constraints have source/AIR fixtures; runtime allocation uses the checked cache.
|
||||
|
||||
Validation: units and Zig formatting pass; full conformance is 1,560/1,560, with all 17 new fixtures also passing collection before every instruction. Counted tests cover shared/cyclic queries, witness visits and layout rejection before classification; 256 small mixed graphs compare cached predicates, witnesses, depth guards and sizes against uncached derivations. CLI integration passes 110 checks, including source/AIR/hosted execution, actual allocation accounting, imported types and diagnostics. Existing generic/content/store-mode suites pass 32/302/348 checks. Old/new comparison changes zero outputs on 1,257 public sources (686 old lowerings) and 333 public AIR checks. Coverage remains 121/121. Claude independently ran units and approved review. P6-2 remains open; Q-049 is a separate owner-policy question.
|
||||
@@ -36,6 +36,7 @@ pub const WaitTarget = module.WaitTarget;
|
||||
pub const parse = @import("air/parse.zig");
|
||||
pub const print = @import("air/print.zig");
|
||||
pub const features = @import("air/features.zig");
|
||||
pub const properties = @import("air/properties.zig");
|
||||
pub const authority = module.authority;
|
||||
|
||||
test {
|
||||
@@ -43,5 +44,6 @@ test {
|
||||
_ = parse;
|
||||
_ = print;
|
||||
_ = features;
|
||||
_ = properties;
|
||||
_ = authority;
|
||||
}
|
||||
+26
-1
@@ -473,6 +473,27 @@ pub const Function = struct {
|
||||
values: []const ValueInfo,
|
||||
};
|
||||
|
||||
/// Implementation cache only; neither printed nor part of AIR format 0.
|
||||
pub const NominalProperties = packed struct(u32) {
|
||||
linear: bool = false,
|
||||
copy: bool = true,
|
||||
send: bool = true,
|
||||
share: bool = true,
|
||||
island_safe: bool = true,
|
||||
local: bool = false,
|
||||
forbidden: bool = false,
|
||||
endpoint: bool = false,
|
||||
zeroable: bool = true,
|
||||
/// Maximum visited-node count, saturated at depth limit + 1.
|
||||
height: u7 = 1,
|
||||
/// Nearest forbidden source-element leaf, saturated past depth 32.
|
||||
source_forbidden_depth: u6 = 34,
|
||||
padding: u10 = 0,
|
||||
};
|
||||
|
||||
pub const SizeKey = struct { index: u32, depth: usize };
|
||||
pub const SizeCache = std.AutoHashMapUnmanaged(SizeKey, ?u64);
|
||||
|
||||
pub const Module = struct {
|
||||
name: []const u8,
|
||||
format_version: u32,
|
||||
@@ -480,6 +501,10 @@ pub const Module = struct {
|
||||
features: []const []const u8,
|
||||
types: []const TypeDecl,
|
||||
functions: []const Function,
|
||||
/// Immutable implementation caches. Replacing types invalidates both;
|
||||
/// verification always rebuilds them, regardless of caller contents.
|
||||
nominal_properties: ?[]const NominalProperties = null,
|
||||
accounted_sizes: ?*const SizeCache = null,
|
||||
|
||||
pub fn declares(m: Module, feature: []const u8) bool {
|
||||
for (m.features) |f| if (std.mem.eql(u8, f, feature)) return true;
|
||||
@@ -491,7 +516,7 @@ pub const Module = struct {
|
||||
if (t.isLinear()) return true;
|
||||
return switch (t) {
|
||||
.array => |a| m.isLinearType(a.elem),
|
||||
.named => |i| switch (m.types[i].kind) {
|
||||
.named => |i| if (m.nominal_properties) |p| p[i].linear else switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (m.isLinearType(f.ty)) break true;
|
||||
} else false,
|
||||
|
||||
@@ -0,0 +1,347 @@
|
||||
//! Cached structural properties of resolved AIR declarations (spec 02/03/04).
|
||||
const std = @import("std");
|
||||
const air = @import("module.zig");
|
||||
const Type = air.Type;
|
||||
|
||||
pub const Stats = struct { evaluations: usize = 0, fields: usize = 0 };
|
||||
|
||||
/// Resolve shared nominal subgraphs once per changed fact, including cycles.
|
||||
/// All predicates are monotone: existential facts grow from false, universal
|
||||
/// facts shrink from true. Height grows to 65, preserving the depth-64 guard.
|
||||
/// No caller-supplied cache is trusted. Declarations are immutable thereafter.
|
||||
pub fn prepare(a: std.mem.Allocator, input: air.Module, stats: ?*Stats) !air.Module {
|
||||
const entries = try a.alloc(air.NominalProperties, input.types.len);
|
||||
@memset(entries, .{});
|
||||
var m = input;
|
||||
m.nominal_properties = entries;
|
||||
const reverse = try a.alloc(std.ArrayList(u32), input.types.len);
|
||||
@memset(reverse, .empty);
|
||||
for (m.types, 0..) |d, i| switch (d.kind) {
|
||||
.@"struct" => |fs| for (fs) |f| try dependencies(a, reverse, @intCast(i), f.ty),
|
||||
.@"enum" => |vs| for (vs) |v| for (v.payload) |t| try dependencies(a, reverse, @intCast(i), t),
|
||||
};
|
||||
const queue = try a.alloc(u32, m.types.len);
|
||||
const queued = try a.alloc(bool, m.types.len);
|
||||
@memset(queued, true);
|
||||
for (queue, 0..) |*slot, i| slot.* = @intCast(queue.len - 1 - i);
|
||||
var head: usize = 0;
|
||||
var tail: usize = 0;
|
||||
var count = queue.len;
|
||||
while (count != 0) {
|
||||
const i = queue[head];
|
||||
head = (head + 1) % queue.len;
|
||||
count -= 1;
|
||||
queued[i] = false;
|
||||
if (stats) |s| s.evaluations += 1;
|
||||
var next: air.NominalProperties = .{};
|
||||
switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| accumulate(m, &next, f.ty, stats),
|
||||
.@"enum" => |vs| {
|
||||
next.zeroable = false;
|
||||
for (vs) |v| for (v.payload) |t| accumulate(m, &next, t, stats);
|
||||
},
|
||||
}
|
||||
if (entries[i] == next) continue;
|
||||
entries[i] = next;
|
||||
for (reverse[i].items) |parent| {
|
||||
if (queued[parent]) continue;
|
||||
queue[tail] = parent;
|
||||
tail = (tail + 1) % queue.len;
|
||||
count += 1;
|
||||
queued[parent] = true;
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
// Include phantom edges for height. This is a dependency superset for the
|
||||
// boolean predicates, whose unchanged tag rules decide which inners matter.
|
||||
fn dependencies(a: std.mem.Allocator, reverse: []std.ArrayList(u32), parent: u32, t: Type) !void {
|
||||
if (t == .named) {
|
||||
try reverse[t.named].append(a, parent);
|
||||
} else if (t.inner()) |inner| try dependencies(a, reverse, parent, inner);
|
||||
}
|
||||
|
||||
fn accumulate(m: air.Module, out: *air.NominalProperties, t: Type, stats: ?*Stats) void {
|
||||
if (stats) |s| s.fields += 1;
|
||||
out.linear = out.linear or m.isLinearType(t);
|
||||
out.copy = out.copy and isCopy(m, t);
|
||||
out.send = out.send and isSend(m, t);
|
||||
out.share = out.share and isShare(m, t);
|
||||
out.island_safe = out.island_safe and isIslandSafe(m, t);
|
||||
out.local = out.local or isLocalType(m, t);
|
||||
out.forbidden = out.forbidden or contains(m, t, .forbidden);
|
||||
out.endpoint = out.endpoint or contains(m, t, .endpoint);
|
||||
out.zeroable = out.zeroable and isZeroable(m, t);
|
||||
out.height = @max(out.height, @min(65, @as(u8, height(m, t)) + 1));
|
||||
out.source_forbidden_depth = @min(out.source_forbidden_depth, @min(34, @as(u8, sourceForbiddenDepth(m, t)) + 1));
|
||||
}
|
||||
|
||||
/// Match the frontend's existing element edges and depth-32 witness guard.
|
||||
/// A nearest-leaf distance permits pruning without changing field order.
|
||||
pub fn sourceForbiddenDepth(m: air.Module, t: Type) u6 {
|
||||
return switch (t) {
|
||||
.ref, .mut, .slice, .slice_mut, .scope, .task, .shield, .guard => 0,
|
||||
.array, .own, .own_array, .buffer, .mutex => @intCast(@min(34, @as(u8, sourceForbiddenDepth(m, t.inner().?)) + 1)),
|
||||
.named => |i| m.nominal_properties.?[i].source_forbidden_depth,
|
||||
else => 34,
|
||||
};
|
||||
}
|
||||
|
||||
fn height(m: air.Module, t: Type) u7 {
|
||||
if (t == .named) return m.nominal_properties.?[t.named].height;
|
||||
return if (t.inner()) |inner| @intCast(@min(65, @as(u8, height(m, inner)) + 1)) else 1;
|
||||
}
|
||||
|
||||
/// The preceding depth guard, with cached nominal height and identical edges.
|
||||
pub fn bounded(m: air.Module, t: Type, depth: usize) bool {
|
||||
if (depth >= 64) return false;
|
||||
if (t == .named) {
|
||||
if (m.nominal_properties) |_| return height(m, t) <= 64 - depth;
|
||||
return switch (m.types[t.named].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (!bounded(m, f.ty, depth + 1)) break false;
|
||||
} else true,
|
||||
.@"enum" => |vs| blk: {
|
||||
for (vs) |v| for (v.payload) |p| if (!bounded(m, p, depth + 1)) break :blk false;
|
||||
break :blk true;
|
||||
},
|
||||
};
|
||||
}
|
||||
return if (t.inner()) |inner| bounded(m, inner, depth + 1) else true;
|
||||
}
|
||||
|
||||
pub fn isZeroable(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool => true,
|
||||
.array => |a| isZeroable(m, a.elem),
|
||||
.named => |i| if (m.nominal_properties) |p| p[i].zeroable else switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (!isZeroable(m, f.ty)) break false;
|
||||
} else true,
|
||||
.@"enum" => false,
|
||||
},
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn isCopy(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool, .builtin, .cap, .iref => true,
|
||||
.array => |a| isCopy(m, a.elem),
|
||||
.named => |i| if (m.nominal_properties) |p| p[i].copy else aggregateAll(m, i, isCopy),
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn isLocalType(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.local, .task, .scope, .shield, .guard => true,
|
||||
.ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .mutex => |inner| isLocalType(m, inner.*),
|
||||
.array => |a| isLocalType(m, a.elem),
|
||||
.named => |i| if (m.nominal_properties) |p| p[i].local else switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (isLocalType(m, f.ty)) break true;
|
||||
} else false,
|
||||
.@"enum" => |vs| blk: {
|
||||
for (vs) |v| for (v.payload) |p| if (isLocalType(m, p)) break :blk true;
|
||||
break :blk false;
|
||||
},
|
||||
},
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn isSend(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool, .builtin, .cap, .resource, .region, .sender, .receiver => true,
|
||||
// Graph contents are IslandSafe plain data (spec 03 §22–§24).
|
||||
.island, .frozen, .arc, .iref => true,
|
||||
// Every access to a cell is an atomic operation (spec 04 §23).
|
||||
.atomic => true,
|
||||
.own, .own_array, .buffer, .mutex => |inner| isSend(m, inner.*),
|
||||
.ref, .slice => |inner| isShare(m, inner.*),
|
||||
.mut, .slice_mut => |inner| isSend(m, inner.*),
|
||||
.array => |a| isSend(m, a.elem),
|
||||
.named => |i| if (m.nominal_properties) |p| p[i].send else aggregateAll(m, i, isSend),
|
||||
.scope, .task, .shield, .guard, .local, .void, .never => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn isShare(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool, .builtin, .cap => true,
|
||||
.frozen, .arc, .iref, .atomic => true,
|
||||
// Its owner may mutate it: freeze to share (spec 04 §35).
|
||||
.island => false,
|
||||
.resource, .region, .mut, .slice_mut, .scope, .task, .shield, .guard, .sender, .receiver, .local, .void, .never => false,
|
||||
.own, .own_array, .buffer, .ref, .slice => |inner| isShare(m, inner.*),
|
||||
// The lock synchronizes access (spec 04 §35, §40).
|
||||
.mutex => |inner| isSend(m, inner.*),
|
||||
.array => |a| isShare(m, a.elem),
|
||||
.named => |i| if (m.nominal_properties) |p| p[i].share else aggregateAll(m, i, isShare),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn isIslandSafe(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool, .builtin, .iref => true,
|
||||
.array => |a| isIslandSafe(m, a.elem),
|
||||
.named => |i| if (m.nominal_properties) |p| p[i].island_safe else aggregateAll(m, i, isIslandSafe),
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn aggregateAll(m: air.Module, i: u32, comptime pred: fn (air.Module, Type) bool) bool {
|
||||
return switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (!pred(m, f.ty)) break false;
|
||||
} else true,
|
||||
.@"enum" => |vs| {
|
||||
for (vs) |v| for (v.payload) |p| if (!pred(m, p)) return false;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn contains(m: air.Module, t: Type, comptime what: enum { endpoint, forbidden }) bool {
|
||||
const here = switch (what) {
|
||||
.endpoint => t.isEndpoint(),
|
||||
.forbidden => t.isBorrow() or t.isTaskBound() or t == .guard,
|
||||
};
|
||||
if (here) return true;
|
||||
// An `iref<T>` holds no `T`: types may recurse through it (spec 03 §22).
|
||||
if (t == .iref) return false;
|
||||
if (t.inner()) |inner| if (t != .ref and t != .mut and t != .slice and t != .slice_mut) return contains(m, inner, what);
|
||||
return switch (t) {
|
||||
.named => |i| if (m.nominal_properties) |p| @field(p[i], @tagName(what)) else switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (contains(m, f.ty, what)) break true;
|
||||
} else false,
|
||||
.@"enum" => |vs| for (vs) |v| {
|
||||
for (v.payload) |p| if (contains(m, p, what)) return true;
|
||||
} else false,
|
||||
},
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
test "shared nominal diamonds have counted bounded property queries" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const ds = try a.alloc(air.TypeDecl, 65);
|
||||
for (ds, 0..) |*d, i| {
|
||||
const fields = try a.alloc(air.Field, if (i == 64) 1 else 2);
|
||||
for (fields) |*f| f.* = .{ .name = "x", .ty = if (i == 64) .{ .int = .u64 } else .{ .named = @intCast(i + 1) } };
|
||||
d.* = .{ .name = "N", .span = .{ .line = 1, .col = 1 }, .kind = .{ .@"struct" = fields } };
|
||||
}
|
||||
const m: air.Module = .{ .name = "test", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = ds, .functions = &.{} };
|
||||
var stats: Stats = .{};
|
||||
const cached = try prepare(a, m, &stats);
|
||||
try std.testing.expectEqual(@as(usize, 65), stats.evaluations);
|
||||
try std.testing.expectEqual(@as(usize, 129), stats.fields);
|
||||
for (0..65) |i| {
|
||||
const t: Type = .{ .named = @intCast(i) };
|
||||
try std.testing.expect(!cached.isLinearType(t));
|
||||
try std.testing.expect(isCopy(cached, t) and isSend(cached, t) and isShare(cached, t) and isIslandSafe(cached, t) and isZeroable(cached, t));
|
||||
try std.testing.expect(!isLocalType(cached, t) and !contains(cached, t, .endpoint) and !contains(cached, t, .forbidden));
|
||||
}
|
||||
try std.testing.expect(!bounded(cached, .{ .named = 0 }, 0));
|
||||
try std.testing.expect(!bounded(cached, .{ .named = 1 }, 0));
|
||||
try std.testing.expect(bounded(cached, .{ .named = 2 }, 0));
|
||||
}
|
||||
|
||||
test "cyclic property work terminates and phantom handles stay Copy" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const self: Type = .{ .named = 0 };
|
||||
const phantom: Type = .{ .iref = &self };
|
||||
const m: air.Module = .{ .name = "test", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = &.{.{ .name = "Node", .span = .{ .line = 1, .col = 1 }, .kind = .{ .@"struct" = &.{.{ .name = "next", .ty = phantom }} } }}, .functions = &.{} };
|
||||
var stats: Stats = .{};
|
||||
const cached = try prepare(a, m, &stats);
|
||||
try std.testing.expect(stats.evaluations <= 65);
|
||||
try std.testing.expect(isCopy(cached, self) and isIslandSafe(cached, self));
|
||||
try std.testing.expect(!cached.isLinearType(self) and !contains(cached, self, .forbidden));
|
||||
try std.testing.expect(!bounded(cached, self, 0));
|
||||
}
|
||||
|
||||
test "cached predicates match uncached derivations on mixed acyclic graphs" {
|
||||
for (0..256) |seed| {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const ds = try a.alloc(air.TypeDecl, 4);
|
||||
for (ds, 0..) |*d, i| {
|
||||
const child = try a.create(Type);
|
||||
child.* = if (i == 3) .{ .int = .u64 } else .{ .named = @intCast(i + 1) };
|
||||
const array = try a.create(Type.Array);
|
||||
array.* = .{ .elem = child.*, .len = 2 };
|
||||
const choices = [_]Type{ child.*, .bool, .void, .region, .scope, .{ .own = child }, .{ .mut = child }, .{ .ref = child }, .{ .mutex = child }, .{ .iref = child }, .{ .task = child }, .{ .sender = child }, .{ .array = array }, .{ .island = child }, .{ .arc = child }, .{ .buffer = child } };
|
||||
const x = choices[(seed + i * 7) % choices.len];
|
||||
const y = choices[(seed / choices.len + i * 3) % choices.len];
|
||||
const fields = try a.dupe(air.Field, &.{ .{ .name = "a", .ty = x }, .{ .name = "b", .ty = y } });
|
||||
const vs = try a.alloc(air.Variant, 2);
|
||||
vs[0] = .{ .name = "A", .payload = try a.dupe(Type, &.{x}) };
|
||||
vs[1] = .{ .name = "B", .payload = try a.dupe(Type, &.{y}) };
|
||||
d.* = .{ .name = "N", .span = .{ .line = 1, .col = 1 }, .kind = if ((seed + i) % 3 == 0) .{ .@"enum" = vs } else .{ .@"struct" = fields } };
|
||||
}
|
||||
const m: air.Module = .{ .name = "test", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = ds, .functions = &.{} };
|
||||
const cached = try prepare(a, m, null);
|
||||
for (0..4) |i| {
|
||||
const t: Type = .{ .named = @intCast(i) };
|
||||
try std.testing.expectEqual(m.isLinearType(t), cached.isLinearType(t));
|
||||
inline for (.{ isCopy, isSend, isShare, isIslandSafe, isLocalType, isZeroable }) |pred| try std.testing.expectEqual(pred(m, t), pred(cached, t));
|
||||
inline for (.{ .endpoint, .forbidden }) |what| try std.testing.expectEqual(contains(m, t, what), contains(cached, t, what));
|
||||
for ([_]usize{ 0, 31, 63, 64 }) |depth| try std.testing.expectEqual(bounded(m, t, depth), bounded(cached, t, depth));
|
||||
for ([_]u32{ 0, 30, 31, 32, 33 }) |depth| {
|
||||
const before = witness(m, t, depth, false);
|
||||
const after = witness(cached, t, depth, true);
|
||||
try std.testing.expectEqual(before == null, after == null);
|
||||
if (before) |b| try std.testing.expect(b.eql(after.?));
|
||||
}
|
||||
var memo: @import("../verifier/budget.zig").SizeMemo = .{ .arena = a };
|
||||
for ([_]usize{ 0, 1, 5, 6 }) |depth| try std.testing.expectEqual(@import("../verifier/budget.zig").accountedSize(m, t, depth), try memo.size(m, t, depth));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The preceding frontend witness rule, independently applied to AIR types.
|
||||
fn witness(m: air.Module, t: Type, depth: u32, cached: bool) ?Type {
|
||||
if (depth > 32) return null;
|
||||
if (cached and t == .named and sourceForbiddenDepth(m, t) > 32 - depth) return null;
|
||||
return switch (t) {
|
||||
.ref, .mut, .slice, .slice_mut, .scope, .task, .shield, .guard => t,
|
||||
.array, .own, .own_array, .buffer, .mutex => witness(m, t.inner().?, depth + 1, cached),
|
||||
.named => |i| switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (witness(m, f.ty, depth + 1, cached)) |bad| break bad;
|
||||
} else null,
|
||||
.@"enum" => |vs| blk: {
|
||||
for (vs) |v| for (v.payload) |p| if (witness(m, p, depth + 1, cached)) |bad| break :blk bad;
|
||||
break :blk null;
|
||||
},
|
||||
},
|
||||
else => null,
|
||||
};
|
||||
}
|
||||
|
||||
test "cyclic existential facts reach all predecessors without a false cache" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const u: Type = .{ .int = .u64 };
|
||||
const m: air.Module = .{ .name = "test", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = &.{
|
||||
.{ .name = "A", .span = .{ .line = 1, .col = 1 }, .kind = .{ .@"struct" = &.{.{ .name = "b", .ty = .{ .named = 1 } }} } },
|
||||
.{ .name = "B", .span = .{ .line = 2, .col = 1 }, .kind = .{ .@"struct" = &.{ .{ .name = "a", .ty = .{ .named = 0 } }, .{ .name = "owner", .ty = .{ .own = &u } }, .{ .name = "borrow", .ty = .{ .mut = &u } } } } },
|
||||
}, .functions = &.{} };
|
||||
var stats: Stats = .{};
|
||||
const cached = try prepare(a, m, &stats);
|
||||
try std.testing.expect(stats.evaluations < 150);
|
||||
for (0..2) |i| {
|
||||
const t: Type = .{ .named = @intCast(i) };
|
||||
try std.testing.expect(cached.isLinearType(t) and contains(cached, t, .forbidden));
|
||||
try std.testing.expect(!isCopy(cached, t) and !isShare(cached, t));
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -91,9 +91,9 @@ pub fn checkAir(arena: std.mem.Allocator, file_name: []const u8, source: []const
|
||||
const parsed = try air.parse.parse(arena, file_name, source);
|
||||
if (parsed.diagnostics.len != 0) return .{ .status = .rejected, .diagnostics = parsed.diagnostics };
|
||||
const module = parsed.module.?;
|
||||
const ds = try verifier.verify(arena, file_name, module);
|
||||
if (ds.len != 0) return .{ .status = .rejected, .diagnostics = ds };
|
||||
return .{ .status = .accepted, .diagnostics = &.{}, .module = module };
|
||||
const verified = try verifier.verifyModule(arena, file_name, module);
|
||||
if (verified.diagnostics.len != 0) return .{ .status = .rejected, .diagnostics = verified.diagnostics };
|
||||
return .{ .status = .accepted, .diagnostics = &.{}, .module = verified.module };
|
||||
}
|
||||
|
||||
test "malformed lowered AIR is an internal compiler error" {
|
||||
|
||||
+51
-42
@@ -30,6 +30,7 @@ const parse_mod = @import("parse.zig");
|
||||
const authority = @import("../air/authority.zig");
|
||||
const features_mod = @import("../air/features.zig");
|
||||
const air_module = @import("../air/module.zig");
|
||||
const properties = @import("../air/properties.zig");
|
||||
const verifier_types = @import("../verifier/types.zig");
|
||||
const type_positions = @import("type_positions.zig");
|
||||
const type_properties = @import("type_properties.zig");
|
||||
@@ -328,12 +329,9 @@ const Lowerer = struct {
|
||||
linear_enabled: bool = false,
|
||||
/// Complete declaration snapshot, with finite layouts checked before bodies.
|
||||
property_module: ?air_module.Module = null,
|
||||
/// Count witness visits in unit tests, never used to accept/reject source.
|
||||
property_visits: usize = 0,
|
||||
|
||||
fn probeType(l: *Lowerer, t: ast.Type) ?Ty {
|
||||
const previous = l.problem;
|
||||
defer l.problem = previous;
|
||||
return l.typeOf(t) catch null;
|
||||
}
|
||||
fn needsLinearType(l: *Lowerer, t: Ty, depth: usize) bool {
|
||||
if (depth > l.m.types.len + 32) return false;
|
||||
if (t == .named) return l.isLinear(t);
|
||||
@@ -344,23 +342,12 @@ const Lowerer = struct {
|
||||
return false;
|
||||
}
|
||||
fn isLinear(l: *Lowerer, t: Ty) bool {
|
||||
return l.linearAt(t, 0);
|
||||
}
|
||||
|
||||
fn linearAt(l: *Lowerer, t: Ty, depth: usize) bool {
|
||||
// Signatures/declarations resolve before checkRequirements; all
|
||||
// structural ownership queries run after its immutable snapshot.
|
||||
if (t.isLinear()) return true;
|
||||
if (depth > l.m.types.len + 32) return false;
|
||||
return switch (t) {
|
||||
.array => |a| l.linearAt(a.elem, depth + 1),
|
||||
.named => |i| switch (l.m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (l.probeType(f.ty)) |ty| if (l.linearAt(ty, depth + 1)) break true;
|
||||
} else false,
|
||||
.@"enum" => |vs| blk: {
|
||||
for (vs) |v| for (v.payload) |p| if (l.probeType(p)) |ty| if (l.linearAt(ty, depth + 1)) break :blk true;
|
||||
break :blk false;
|
||||
},
|
||||
},
|
||||
.array => |a| l.isLinear(a.elem),
|
||||
.named => |i| l.property_module.?.nominal_properties.?[i].linear,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
@@ -553,9 +540,6 @@ const Lowerer = struct {
|
||||
},
|
||||
}
|
||||
}
|
||||
for (l.m.types, 0..) |_, i| if (l.isLinear(.{ .named = @intCast(i) })) {
|
||||
l.linear_enabled = true;
|
||||
};
|
||||
const m: air_module.Module = .{ .name = l.m.name, .format_version = 0, .lang = .{ 0, 1 }, .features = &.{"linear_aggregates"}, .types = types, .functions = &.{} };
|
||||
var layout_context: @import("../verifier.zig").Context = .{ .arena = l.arena, .file = "<generic>", .module = m };
|
||||
try verifier_types.checkFiniteLayouts(&layout_context);
|
||||
@@ -563,18 +547,22 @@ const Lowerer = struct {
|
||||
const d = l.m.types[layout_context.diags.items[0].span.?.line - 1];
|
||||
return l.fail("E1003", d.span, "aggregate type contains itself by value", &.{.{ .name = "type", .value = d.display_name orelse d.name }});
|
||||
}
|
||||
l.property_module = m;
|
||||
l.property_module = try properties.prepare(l.arena, m, null);
|
||||
for (l.m.types, 0..) |_, i| if (l.isLinear(.{ .named = @intCast(i) })) {
|
||||
l.linear_enabled = true;
|
||||
};
|
||||
for (l.m.requirements) |r| {
|
||||
const ty = try l.typeOf(r.ty);
|
||||
const t = try l.airType(ty);
|
||||
if (!boundedType(m, t, 0)) return l.invalid(.implementation_limit, r.span, "constraint type traversal is cyclic or exceeds depth 64", &.{});
|
||||
if (!properties.bounded(l.property_module.?, t, 0)) return l.invalid(.implementation_limit, r.span, "constraint type traversal is cyclic or exceeds depth 64", &.{});
|
||||
if (r.property.len == 0) {
|
||||
var context: @import("../verifier.zig").Context = .{ .arena = l.arena, .file = "<generic>", .module = m };
|
||||
var context: @import("../verifier.zig").Context = .{ .arena = l.arena, .file = "<generic>", .module = l.property_module.? };
|
||||
try verifier_types.checkTypeArgument(&context, .{ .line = 1, .col = 1 }, t);
|
||||
if (context.diags.items.len != 0) return l.fail("E7005", r.span, "generic argument is not a well-formed concrete type", &.{ .{ .name = "parameter", .value = r.parameter }, .{ .name = "found", .value = l.diagnosticTyText(ty) } });
|
||||
continue;
|
||||
}
|
||||
const ok = if (std.mem.eql(u8, r.property, "Copy")) verifier_types.isCopy(m, t) else if (std.mem.eql(u8, r.property, "Send")) verifier_types.isSend(m, t) else if (std.mem.eql(u8, r.property, "Share")) verifier_types.isShare(m, t) else if (std.mem.eql(u8, r.property, "Freeze")) verifier_types.isIslandSafe(m, t) else verifier_types.isLocalType(m, t);
|
||||
const cached = l.property_module.?;
|
||||
const ok = if (std.mem.eql(u8, r.property, "Copy")) verifier_types.isCopy(cached, t) else if (std.mem.eql(u8, r.property, "Send")) verifier_types.isSend(cached, t) else if (std.mem.eql(u8, r.property, "Share")) verifier_types.isShare(cached, t) else if (std.mem.eql(u8, r.property, "Freeze")) verifier_types.isIslandSafe(cached, t) else verifier_types.isLocalType(cached, t);
|
||||
if (!ok) return l.fail("E7005", r.span, "generic argument does not satisfy structural constraint", &.{
|
||||
.{ .name = "parameter", .value = r.parameter },
|
||||
.{ .name = "constraint", .value = r.property },
|
||||
@@ -3123,7 +3111,9 @@ const Lowerer = struct {
|
||||
}
|
||||
|
||||
fn forbiddenIn(l: *Lowerer, t: Ty, depth: u32) Error!?Ty {
|
||||
if (@import("builtin").is_test) l.property_visits += 1;
|
||||
if (depth > 32) return null;
|
||||
if (t == .named and properties.sourceForbiddenDepth(l.property_module.?, .{ .named = t.named }) > 32 - depth) return null;
|
||||
return switch (t) {
|
||||
.ref, .mut, .slice, .slice_mut, .scope, .task, .shield, .guard => t,
|
||||
.array => |a| l.forbiddenIn(a.elem, depth + 1),
|
||||
@@ -4026,21 +4016,6 @@ fn expressionPath(arena: Allocator, e: ast.Expr) Allocator.Error!?[]const u8 {
|
||||
};
|
||||
}
|
||||
|
||||
// Bound property queries before invoking recursive verifier derivations.
|
||||
fn boundedType(m: air_module.Module, t: air_module.Type, depth: usize) bool {
|
||||
if (depth >= 64) return false;
|
||||
if (t == .named) return switch (m.types[t.named].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (!boundedType(m, f.ty, depth + 1)) break false;
|
||||
} else true,
|
||||
.@"enum" => |vs| blk: {
|
||||
for (vs) |v| for (v.payload) |p| if (!boundedType(m, p, depth + 1)) break :blk false;
|
||||
break :blk true;
|
||||
},
|
||||
};
|
||||
return if (t.inner()) |inner| boundedType(m, inner, depth + 1) else true;
|
||||
}
|
||||
|
||||
test "terminated blocks reject further emission with a source diagnostic" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
@@ -4055,3 +4030,37 @@ test "terminated blocks reject further emission with a source diagnostic" {
|
||||
try std.testing.expectEqual(@as(usize, 1), l.blocks.items[0].insts.items.len);
|
||||
try std.testing.expect(l.blocks.items[0].terminated);
|
||||
}
|
||||
|
||||
test "source property queries prune deep diamonds without changing witnesses" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
var text: std.ArrayList(u8) = .empty;
|
||||
try text.appendSlice(a, "module t\n");
|
||||
for (0..41) |i| try text.print(a, "struct N{d} {{ a: N{d}, b: N{d} }}\n", .{ i, i + 1, i + 1 });
|
||||
try text.appendSlice(a, "struct N41 { a: ref<u64>, b: task<u64> }\nfn main() -> void effects [] {}\n");
|
||||
var l: Lowerer = .{ .arena = a, .m = (try parse_mod.parse(a, text.items)).ok };
|
||||
try l.checkRequirements();
|
||||
try std.testing.expect(l.isLinear(.{ .named = 0 }));
|
||||
try std.testing.expectEqual(@as(?Ty, null), try l.forbiddenIn(.{ .named = 0 }, 0));
|
||||
try std.testing.expectEqual(@as(usize, 1), l.property_visits);
|
||||
l.property_visits = 0;
|
||||
const bad = (try l.forbiddenIn(.{ .named = 10 }, 0)).?;
|
||||
try std.testing.expect(bad == .ref and bad.inner().? == .int);
|
||||
try std.testing.expect(l.property_visits <= 33);
|
||||
}
|
||||
|
||||
test "cyclic source diamonds reject before property construction" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
var text: std.ArrayList(u8) = .empty;
|
||||
try text.appendSlice(a, "module t\n");
|
||||
for (0..41) |i| try text.print(a, "struct N{d} {{ a: N{d}, b: N{d} }}\n", .{ i, (i + 1) % 41, (i + 1) % 41 });
|
||||
try text.appendSlice(a, "fn main() -> void effects [] {}\n");
|
||||
var l: Lowerer = .{ .arena = a, .m = (try parse_mod.parse(a, text.items)).ok };
|
||||
try std.testing.expectError(error.Lower, l.checkRequirements());
|
||||
try std.testing.expectEqualStrings("E1003", l.problem.?.code);
|
||||
try std.testing.expectEqual(@as(u32, 2), l.problem.?.span.start.line);
|
||||
try std.testing.expect(l.property_module == null);
|
||||
}
|
||||
+33
-2
@@ -73,16 +73,26 @@ pub const Context = struct {
|
||||
/// Runs all verifier stages. Returns the diagnostics of the first failing
|
||||
/// stage, or an empty slice if the module verifies.
|
||||
pub fn verify(arena: std.mem.Allocator, file: []const u8, module: air.Module) std.mem.Allocator.Error![]const diag.Diagnostic {
|
||||
return (try verifyModule(arena, file, module)).diagnostics;
|
||||
}
|
||||
|
||||
pub const Result = struct { diagnostics: []const diag.Diagnostic, module: air.Module };
|
||||
|
||||
/// Retain implementation caches in the checked module without trusting caches
|
||||
/// supplied by a caller. Neither cache enters AIR text or changes a stage.
|
||||
pub fn verifyModule(arena: std.mem.Allocator, file: []const u8, module: air.Module) std.mem.Allocator.Error!Result {
|
||||
var c: Context = .{ .arena = arena, .file = file, .module = module };
|
||||
c.module.nominal_properties = null;
|
||||
c.module.accounted_sizes = null;
|
||||
const stages = .{ budget.check, cfg.check, ssa.check, types.check, effects.check, unsafe_.check, init.check, borrow.check, bounds.check };
|
||||
inline for (stages) |stage| {
|
||||
try stage(&c);
|
||||
if (c.diags.items.len != 0) {
|
||||
std.mem.sort(diag.Diagnostic, c.diags.items, {}, bySpan);
|
||||
return c.diags.items;
|
||||
return .{ .diagnostics = c.diags.items, .module = c.module };
|
||||
}
|
||||
}
|
||||
return &.{};
|
||||
return .{ .diagnostics = &.{}, .module = c.module };
|
||||
}
|
||||
|
||||
fn bySpan(_: void, a: diag.Diagnostic, b: diag.Diagnostic) bool {
|
||||
@@ -127,3 +137,24 @@ pub fn expectCodes(src: []const u8, codes: []const []const u8) !void {
|
||||
}
|
||||
|
||||
pub const test_header = "module t\nair 0\nlang 0.1\nfeatures []\n";
|
||||
|
||||
test "verification rebuilds caller-supplied property and size caches" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const source = test_header ++ "type @P = struct { x: u64 }\nfn @f(%p: @P) -> @P\neffects []\nentry:\n %q = copy %p\n ret %q\n";
|
||||
var m = (try air.parse.parse(a, "t.air", source)).module.?;
|
||||
const fake = try a.alloc(@import("air/module.zig").NominalProperties, 1);
|
||||
fake[0] = .{ .linear = true, .copy = false };
|
||||
m.nominal_properties = fake;
|
||||
const result = try verifyModule(a, "t.air", m);
|
||||
try std.testing.expectEqual(@as(usize, 0), result.diagnostics.len);
|
||||
try std.testing.expect(!result.module.isLinearType(.{ .named = 0 }));
|
||||
try std.testing.expect(result.module.accounted_sizes != null);
|
||||
var large = (try air.parse.parse(a, "t.air", test_header ++ "type @P = struct { x: array<u8, 1048577> }\nfn @f() -> void\neffects []\nentry:\n ret\n")).module.?;
|
||||
var sizes: @import("air/module.zig").SizeCache = .{};
|
||||
try sizes.put(a, .{ .index = 0, .depth = 0 }, 0);
|
||||
large.accounted_sizes = &sizes;
|
||||
const rejected = try verifyModule(a, "t.air", large);
|
||||
try std.testing.expectEqualStrings("E5101", rejected.diagnostics[0].code.id);
|
||||
}
|
||||
+72
-10
@@ -5,6 +5,7 @@
|
||||
|
||||
const std = @import("std");
|
||||
const air = @import("../air.zig");
|
||||
const air_module = @import("../air/module.zig");
|
||||
const verifier = @import("../verifier.zig");
|
||||
|
||||
pub const Limits = struct {
|
||||
@@ -24,30 +25,63 @@ pub const Limits = struct {
|
||||
/// reported later (E1003) and count as 0 here; `void`, `never` and storage
|
||||
/// types are not materializable and count as 0.
|
||||
pub fn accountedSize(m: air.Module, t: air.Type, depth: usize) ?u64 {
|
||||
// Read-only cache lookup never allocates; the uncached path remains an oracle.
|
||||
return sizeQuery(m, t, depth, null) catch unreachable;
|
||||
}
|
||||
|
||||
pub const SizeMemo = struct {
|
||||
arena: std.mem.Allocator,
|
||||
values: air_module.SizeCache = .{},
|
||||
evaluations: usize = 0,
|
||||
|
||||
// Preserve the legacy depth cutoff exactly: at most V * (V + 2)
|
||||
// nominal/depth states, rather than exponentially many shared paths.
|
||||
|
||||
pub fn size(cache: *SizeMemo, m: air.Module, t: air.Type, depth: usize) std.mem.Allocator.Error!?u64 {
|
||||
return sizeQuery(m, t, depth, cache);
|
||||
}
|
||||
};
|
||||
|
||||
fn sizeQuery(m: air.Module, t: air.Type, depth: usize, memo: ?*SizeMemo) std.mem.Allocator.Error!?u64 {
|
||||
if (depth > m.types.len + 1) return 0;
|
||||
const key: air_module.SizeKey = .{ .index = if (t == .named) t.named else 0, .depth = depth };
|
||||
if (t == .named) {
|
||||
if (memo) |cache| {
|
||||
if (cache.values.get(key)) |value| return value;
|
||||
cache.evaluations += 1;
|
||||
} else if (m.accounted_sizes) |cache| {
|
||||
if (cache.get(key)) |value| return value;
|
||||
}
|
||||
}
|
||||
const result = try sizeValue(m, t, depth, memo);
|
||||
if (t == .named) if (memo) |cache| try cache.values.put(cache.arena, key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
fn sizeValue(m: air.Module, t: air.Type, depth: usize, memo: ?*SizeMemo) std.mem.Allocator.Error!?u64 {
|
||||
return switch (t) {
|
||||
.int => |it| it.bits() / 8,
|
||||
.bool => 1,
|
||||
.ref, .mut, .cap, .resource, .own, .region, .scope, .task, .shield, .sender, .receiver, .guard, .island, .frozen, .arc => 8,
|
||||
.iref => 16,
|
||||
.atomic => |inner| accountedSize(m, inner.*, depth + 1),
|
||||
.mutex => |inner| std.math.add(u64, 8, accountedSize(m, inner.*, depth + 1) orelse return null) catch null,
|
||||
.atomic => |inner| (try sizeQuery(m, inner.*, depth + 1, memo)),
|
||||
.mutex => |inner| std.math.add(u64, 8, (try sizeQuery(m, inner.*, depth + 1, memo)) orelse return null) catch null,
|
||||
.own_array => 16,
|
||||
.buffer => 24,
|
||||
.slice, .slice_mut => 16,
|
||||
.builtin => |b| tagSize(b.variants().len),
|
||||
.array => |a| std.math.mul(u64, a.len, accountedSize(m, a.elem, depth + 1) orelse return null) catch null,
|
||||
.array => |a| std.math.mul(u64, a.len, (try sizeQuery(m, a.elem, depth + 1, memo)) orelse return null) catch null,
|
||||
.named => |i| switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| blk: {
|
||||
var sum: u64 = 0;
|
||||
for (fs) |f| sum = std.math.add(u64, sum, accountedSize(m, f.ty, depth + 1) orelse return null) catch return null;
|
||||
for (fs) |f| sum = std.math.add(u64, sum, (try sizeQuery(m, f.ty, depth + 1, memo)) orelse return null) catch return null;
|
||||
break :blk sum;
|
||||
},
|
||||
.@"enum" => |vs| blk: {
|
||||
var max: u64 = 0;
|
||||
for (vs) |v| {
|
||||
var sum: u64 = 0;
|
||||
for (v.payload) |p| sum = std.math.add(u64, sum, accountedSize(m, p, depth + 1) orelse return null) catch return null;
|
||||
for (v.payload) |p| sum = std.math.add(u64, sum, (try sizeQuery(m, p, depth + 1, memo)) orelse return null) catch return null;
|
||||
max = @max(max, sum);
|
||||
}
|
||||
break :blk std.math.add(u64, tagSize(vs.len), max) catch null;
|
||||
@@ -66,7 +100,9 @@ fn tagSize(variants: usize) u64 {
|
||||
}
|
||||
|
||||
pub fn check(c: *verifier.Context) !void {
|
||||
try checkValueSizes(c);
|
||||
c.module.accounted_sizes = null;
|
||||
var memo: SizeMemo = .{ .arena = c.arena };
|
||||
try checkValueSizes(c, &memo);
|
||||
const m = c.module;
|
||||
const origin: air.Span = .{ .line = 1, .col = 1 };
|
||||
try limit(c, origin, "functions per module", Limits.functions, m.functions.len);
|
||||
@@ -97,11 +133,14 @@ pub fn check(c: *verifier.Context) !void {
|
||||
try limit(c, f.span, "instructions per function", Limits.insts, n);
|
||||
var frame: ?u64 = 0;
|
||||
for (f.blocks) |b| for (b.insts) |inst| if (inst.op == .local_alloc) {
|
||||
const size = accountedSize(m, inst.op.local_alloc, 0);
|
||||
const size = try memo.size(m, inst.op.local_alloc, 0);
|
||||
frame = if (frame != null and size != null) std.math.add(u64, frame.?, size.?) catch null else null;
|
||||
};
|
||||
try limit(c, f.span, "local frame bytes", Limits.local_frame, frame);
|
||||
}
|
||||
const cached = try c.arena.create(air_module.SizeCache);
|
||||
cached.* = memo.values;
|
||||
c.module.accounted_sizes = cached;
|
||||
}
|
||||
|
||||
/// `found == null` means the size computation overflowed.
|
||||
@@ -119,12 +158,13 @@ fn limit(c: *verifier.Context, span: air.Span, name: []const u8, max: u64, found
|
||||
/// first occurrence.
|
||||
const ValueSizes = struct {
|
||||
c: *verifier.Context,
|
||||
memo: *SizeMemo,
|
||||
reported: std.StringHashMapUnmanaged(void) = .empty,
|
||||
|
||||
fn visit(v: *ValueSizes, span: air.Span, t: air.Type) !void {
|
||||
const m = v.c.module;
|
||||
if (t != .local and t != .void and t != .never) {
|
||||
const size = accountedSize(m, t, 0);
|
||||
const size = try v.memo.size(m, t, 0);
|
||||
if (size == null or size.? > Limits.value_size) {
|
||||
const name = try v.c.typeName(t);
|
||||
const gop = try v.reported.getOrPut(v.c.arena, name);
|
||||
@@ -141,8 +181,8 @@ const ValueSizes = struct {
|
||||
}
|
||||
};
|
||||
|
||||
fn checkValueSizes(c: *verifier.Context) !void {
|
||||
var v: ValueSizes = .{ .c = c };
|
||||
fn checkValueSizes(c: *verifier.Context, memo: *SizeMemo) !void {
|
||||
var v: ValueSizes = .{ .c = c, .memo = memo };
|
||||
const m = c.module;
|
||||
for (m.types, 0..) |d, i| try v.visit(d.span, .{ .named = @intCast(i) });
|
||||
for (m.functions) |f| {
|
||||
@@ -168,6 +208,28 @@ test "too many parameters" {
|
||||
try verifier.expectCodes(src.items, &.{"E5101"});
|
||||
}
|
||||
|
||||
test "accounted sizes memoize shared diamonds and cyclic depth states" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const ds = try a.alloc(air.TypeDecl, 65);
|
||||
for (ds, 0..) |*d, i| d.* = .{ .name = "N", .span = .{ .line = 1, .col = 1 }, .kind = .{ .@"struct" = if (i == 64) &.{} else try a.dupe(air_module.Field, &.{ .{ .name = "a", .ty = .{ .named = @intCast(i + 1) } }, .{ .name = "b", .ty = .{ .named = @intCast(i + 1) } } }) } };
|
||||
var m: air.Module = .{ .name = "test", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = ds, .functions = &.{} };
|
||||
var memo: SizeMemo = .{ .arena = a };
|
||||
for (0..65) |i| try std.testing.expectEqual(@as(?u64, 0), try memo.size(m, .{ .named = @intCast(i) }, 0));
|
||||
try std.testing.expect(memo.evaluations <= 65 * 67);
|
||||
const before = memo.evaluations;
|
||||
m.accounted_sizes = &memo.values;
|
||||
for (0..65) |i| try std.testing.expectEqual(@as(?u64, 0), accountedSize(m, .{ .named = @intCast(i) }, 0));
|
||||
try std.testing.expectEqual(before, memo.evaluations);
|
||||
// A cyclic, branching size query keeps the legacy depth cutoff exactly.
|
||||
ds[64].kind = .{ .@"struct" = try a.dupe(air_module.Field, &.{ .{ .name = "a", .ty = .{ .named = 0 } }, .{ .name = "b", .ty = .{ .named = 0 } } }) };
|
||||
m.accounted_sizes = null;
|
||||
var cyclic: SizeMemo = .{ .arena = a };
|
||||
try std.testing.expectEqual(@as(?u64, 0), try cyclic.size(m, .{ .named = 0 }, 0));
|
||||
try std.testing.expect(cyclic.evaluations <= 65 * 67);
|
||||
}
|
||||
|
||||
test "local frame limit" {
|
||||
const h = "module t\nair 0\nlang 0.1\nfeatures [arrays, ownership]\n";
|
||||
try verifier.expectCodes(h ++ "fn @f() -> void\neffects []\nentry:\n %a = local.alloc array<u8, 1048576>\n ret\n", &.{});
|
||||
|
||||
+8
-108
@@ -12,6 +12,7 @@ const Context = verifier.Context;
|
||||
const Type = air.Type;
|
||||
|
||||
pub fn check(c: *Context) !void {
|
||||
c.module = try air.properties.prepare(c.arena, c.module, null);
|
||||
try checkDeclarations(c);
|
||||
if (c.diags.items.len != 0) return;
|
||||
const all = try c.arena.alloc([]const Type, c.module.functions.len);
|
||||
@@ -157,19 +158,7 @@ fn argumentLengths(c: *Context, span: air.Span, t: Type) !void {
|
||||
}
|
||||
|
||||
/// `local.alloc` results are checked separately: their own type is storage.
|
||||
fn zeroable(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool => true,
|
||||
.array => |a| zeroable(m, a.elem),
|
||||
.named => |i| switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (!zeroable(m, f.ty)) break false;
|
||||
} else true,
|
||||
.@"enum" => false,
|
||||
},
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
const zeroable = air.properties.isZeroable;
|
||||
|
||||
// ---------------------------------------------------------------- functions
|
||||
|
||||
@@ -379,66 +368,16 @@ fn checkIntrinsic(fc: *FnCtx, inst: air.Inst, x: @FieldType(air.Op, "intrinsic")
|
||||
}
|
||||
|
||||
/// Structural Copy query for source constraints; borrows remain second-class.
|
||||
pub fn isCopy(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool, .builtin, .cap, .iref => true,
|
||||
.array => |a| isCopy(m, a.elem),
|
||||
.named => |i| aggregateAll(m, i, isCopy),
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
pub const isCopy = air.properties.isCopy;
|
||||
|
||||
/// Local is context-bound state, not the complement of Send (spec 15 §15).
|
||||
pub fn isLocalType(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.local, .task, .scope, .shield, .guard => true,
|
||||
.ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .mutex => |inner| isLocalType(m, inner.*),
|
||||
.array => |a| isLocalType(m, a.elem),
|
||||
.named => |i| switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (isLocalType(m, f.ty)) break true;
|
||||
} else false,
|
||||
.@"enum" => |vs| blk: {
|
||||
for (vs) |v| for (v.payload) |p| if (isLocalType(m, p)) break :blk true;
|
||||
break :blk false;
|
||||
},
|
||||
},
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
pub const isLocalType = air.properties.isLocalType;
|
||||
|
||||
/// `Send` (spec 04 §35): may move to another task.
|
||||
pub fn isSend(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool, .builtin, .cap, .resource, .region, .sender, .receiver => true,
|
||||
// Graph contents are IslandSafe plain data (spec 03 §22–§24).
|
||||
.island, .frozen, .arc, .iref => true,
|
||||
// Every access to a cell is an atomic operation (spec 04 §23).
|
||||
.atomic => true,
|
||||
.own, .own_array, .buffer, .mutex => |inner| isSend(m, inner.*),
|
||||
.ref, .slice => |inner| isShare(m, inner.*),
|
||||
.mut, .slice_mut => |inner| isSend(m, inner.*),
|
||||
.array => |a| isSend(m, a.elem),
|
||||
.named => |i| aggregateAll(m, i, isSend),
|
||||
.scope, .task, .shield, .guard, .local, .void, .never => false,
|
||||
};
|
||||
}
|
||||
pub const isSend = air.properties.isSend;
|
||||
|
||||
/// `Share` (spec 04 §35): may be observed concurrently through shared borrows.
|
||||
pub fn isShare(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool, .builtin, .cap => true,
|
||||
.frozen, .arc, .iref, .atomic => true,
|
||||
// Its owner may mutate it: freeze to share (spec 04 §35).
|
||||
.island => false,
|
||||
.resource, .region, .mut, .slice_mut, .scope, .task, .shield, .guard, .sender, .receiver, .local, .void, .never => false,
|
||||
.own, .own_array, .buffer, .ref, .slice => |inner| isShare(m, inner.*),
|
||||
// The lock synchronizes access (spec 04 §35, §40).
|
||||
.mutex => |inner| isSend(m, inner.*),
|
||||
.array => |a| isShare(m, a.elem),
|
||||
.named => |i| aggregateAll(m, i, isShare),
|
||||
};
|
||||
}
|
||||
pub const isShare = air.properties.isShare;
|
||||
|
||||
/// A borrow whose pointee is an atomic cell: reached only atomically.
|
||||
fn atomicPointee(t: Type) bool {
|
||||
@@ -479,26 +418,7 @@ pub fn isAtomicScalar(t: Type) bool {
|
||||
|
||||
/// `IslandSafe` (spec 02 §6): plain data and `iref` handles, at any depth.
|
||||
/// `ArcSafe` is the same set in format 0.
|
||||
pub fn isIslandSafe(m: air.Module, t: Type) bool {
|
||||
return switch (t) {
|
||||
.int, .bool, .builtin, .iref => true,
|
||||
.array => |a| isIslandSafe(m, a.elem),
|
||||
.named => |i| aggregateAll(m, i, isIslandSafe),
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
fn aggregateAll(m: air.Module, i: u32, comptime pred: fn (air.Module, Type) bool) bool {
|
||||
return switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (!pred(m, f.ty)) break false;
|
||||
} else true,
|
||||
.@"enum" => |vs| {
|
||||
for (vs) |v| for (v.payload) |p| if (!pred(m, p)) return false;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
pub const isIslandSafe = air.properties.isIslandSafe;
|
||||
|
||||
/// `task.spawn` (spec 04 §33.2, §35): arguments like a call, Send/Share
|
||||
/// rules per argument, and a borrow-free, Send result.
|
||||
@@ -558,27 +478,7 @@ fn checkElement(fc: *FnCtx, span: air.Span, t: Type) !void {
|
||||
|
||||
/// Whether `t` transitively contains an endpoint, or a borrow or
|
||||
/// function-bound value.
|
||||
fn contains(m: air.Module, t: Type, comptime what: enum { endpoint, forbidden }) bool {
|
||||
const here = switch (what) {
|
||||
.endpoint => t.isEndpoint(),
|
||||
.forbidden => t.isBorrow() or t.isTaskBound() or t == .guard,
|
||||
};
|
||||
if (here) return true;
|
||||
// An `iref<T>` holds no `T`: types may recurse through it (spec 03 §22).
|
||||
if (t == .iref) return false;
|
||||
if (t.inner()) |inner| if (t != .ref and t != .mut and t != .slice and t != .slice_mut) return contains(m, inner, what);
|
||||
return switch (t) {
|
||||
.named => |i| switch (m.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| {
|
||||
if (contains(m, f.ty, what)) break true;
|
||||
} else false,
|
||||
.@"enum" => |vs| for (vs) |v| {
|
||||
for (v.payload) |p| if (contains(m, p, what)) return true;
|
||||
} else false,
|
||||
},
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
const contains = air.properties.contains;
|
||||
|
||||
/// `select` (spec 04 §39): each arm is a channel operation; each target
|
||||
/// takes its own parameters, then the send values not sent on its edge.
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
; expect: reject E1003
|
||||
; phase: 6
|
||||
; spec: docs/spec/03-memory-model.md §25
|
||||
module test.nominal_queries
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
type @N0 = struct { a: @N1, b: @N1 }
|
||||
type @N1 = struct { a: @N2, b: @N2 }
|
||||
type @N2 = struct { a: @N3, b: @N3 }
|
||||
type @N3 = struct { a: @N4, b: @N4 }
|
||||
type @N4 = struct { a: @N5, b: @N5 }
|
||||
type @N5 = struct { a: @N6, b: @N6 }
|
||||
type @N6 = struct { a: @N7, b: @N7 }
|
||||
type @N7 = struct { a: @N8, b: @N8 }
|
||||
type @N8 = struct { a: @N9, b: @N9 }
|
||||
type @N9 = struct { a: @N10, b: @N10 }
|
||||
type @N10 = struct { a: @N11, b: @N11 }
|
||||
type @N11 = struct { a: @N12, b: @N12 }
|
||||
type @N12 = struct { a: @N13, b: @N13 }
|
||||
type @N13 = struct { a: @N14, b: @N14 }
|
||||
type @N14 = struct { a: @N15, b: @N15 }
|
||||
type @N15 = struct { a: @N16, b: @N16 }
|
||||
type @N16 = struct { a: @N17, b: @N17 }
|
||||
type @N17 = struct { a: @N18, b: @N18 }
|
||||
type @N18 = struct { a: @N19, b: @N19 }
|
||||
type @N19 = struct { a: @N20, b: @N20 }
|
||||
type @N20 = struct { a: @N21, b: @N21 }
|
||||
type @N21 = struct { a: @N22, b: @N22 }
|
||||
type @N22 = struct { a: @N23, b: @N23 }
|
||||
type @N23 = struct { a: @N24, b: @N24 }
|
||||
type @N24 = struct { a: @N25, b: @N25 }
|
||||
type @N25 = struct { a: @N26, b: @N26 }
|
||||
type @N26 = struct { a: @N27, b: @N27 }
|
||||
type @N27 = struct { a: @N28, b: @N28 }
|
||||
type @N28 = struct { a: @N29, b: @N29 }
|
||||
type @N29 = struct { a: @N30, b: @N30 }
|
||||
type @N30 = struct { a: @N31, b: @N31 }
|
||||
type @N31 = struct { a: @N32, b: @N32 }
|
||||
type @N32 = struct { a: @N33, b: @N33 }
|
||||
type @N33 = struct { a: @N34, b: @N34 }
|
||||
type @N34 = struct { a: @N35, b: @N35 }
|
||||
type @N35 = struct { a: @N36, b: @N36 }
|
||||
type @N36 = struct { a: @N37, b: @N37 }
|
||||
type @N37 = struct { a: @N38, b: @N38 }
|
||||
type @N38 = struct { a: @N39, b: @N39 }
|
||||
type @N39 = struct { a: @N40, b: @N40 }
|
||||
type @N40 = struct { a: @N0, b: @N0 }
|
||||
fn @main() -> void
|
||||
effects []
|
||||
entry:
|
||||
ret
|
||||
@@ -0,0 +1,34 @@
|
||||
; expect: run
|
||||
; result: 42
|
||||
; phase: 6
|
||||
; spec: docs/spec/08-verifier.md §7
|
||||
module test.nominal_queries
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
type @N0 = struct { a: @N1, b: @N1 }
|
||||
type @N1 = struct { a: @N2, b: @N2 }
|
||||
type @N2 = struct { a: @N3, b: @N3 }
|
||||
type @N3 = struct { a: @N4, b: @N4 }
|
||||
type @N4 = struct { a: @N5, b: @N5 }
|
||||
type @N5 = struct { a: @N6, b: @N6 }
|
||||
type @N6 = struct { a: @N7, b: @N7 }
|
||||
type @N7 = struct { a: @N8, b: @N8 }
|
||||
type @N8 = struct { a: @N9, b: @N9 }
|
||||
type @N9 = struct { a: @N10, b: @N10 }
|
||||
type @N10 = struct { a: @N11, b: @N11 }
|
||||
type @N11 = struct { a: @N12, b: @N12 }
|
||||
type @N12 = struct { a: @N13, b: @N13 }
|
||||
type @N13 = struct { a: @N14, b: @N14 }
|
||||
type @N14 = struct { a: @N15, b: @N15 }
|
||||
type @N15 = struct { a: @N16, b: @N16 }
|
||||
type @N16 = struct { x: u64 }
|
||||
fn @echo(%p: @N0) -> @N0
|
||||
effects []
|
||||
entry:
|
||||
ret %p
|
||||
fn @main() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%answer = const.u64 42
|
||||
ret %answer
|
||||
@@ -0,0 +1,38 @@
|
||||
; expect: reject E5101 E5101 E5101 E5101
|
||||
; phase: 6
|
||||
; spec: docs/spec/08-verifier.md §7
|
||||
module test.nominal_queries
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
type @N0 = struct { a: @N1, b: @N1 }
|
||||
type @N1 = struct { a: @N2, b: @N2 }
|
||||
type @N2 = struct { a: @N3, b: @N3 }
|
||||
type @N3 = struct { a: @N4, b: @N4 }
|
||||
type @N4 = struct { a: @N5, b: @N5 }
|
||||
type @N5 = struct { a: @N6, b: @N6 }
|
||||
type @N6 = struct { a: @N7, b: @N7 }
|
||||
type @N7 = struct { a: @N8, b: @N8 }
|
||||
type @N8 = struct { a: @N9, b: @N9 }
|
||||
type @N9 = struct { a: @N10, b: @N10 }
|
||||
type @N10 = struct { a: @N11, b: @N11 }
|
||||
type @N11 = struct { a: @N12, b: @N12 }
|
||||
type @N12 = struct { a: @N13, b: @N13 }
|
||||
type @N13 = struct { a: @N14, b: @N14 }
|
||||
type @N14 = struct { a: @N15, b: @N15 }
|
||||
type @N15 = struct { a: @N16, b: @N16 }
|
||||
type @N16 = struct { a: @N17, b: @N17 }
|
||||
type @N17 = struct { a: @N18, b: @N18 }
|
||||
type @N18 = struct { a: @N19, b: @N19 }
|
||||
type @N19 = struct { a: @N20, b: @N20 }
|
||||
type @N20 = struct { a: @N21, b: @N21 }
|
||||
type @N21 = struct { x: u64 }
|
||||
fn @echo(%p: @N0) -> @N0
|
||||
effects []
|
||||
entry:
|
||||
ret %p
|
||||
fn @main() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%answer = const.u64 42
|
||||
ret %answer
|
||||
@@ -0,0 +1,82 @@
|
||||
; expect: run
|
||||
; result: 42
|
||||
; phase: 6
|
||||
; spec: docs/spec/08-verifier.md §7
|
||||
module test.nominal_queries
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
type @N0 = struct { a: @N1, b: @N1 }
|
||||
type @N1 = struct { a: @N2, b: @N2 }
|
||||
type @N2 = struct { a: @N3, b: @N3 }
|
||||
type @N3 = struct { a: @N4, b: @N4 }
|
||||
type @N4 = struct { a: @N5, b: @N5 }
|
||||
type @N5 = struct { a: @N6, b: @N6 }
|
||||
type @N6 = struct { a: @N7, b: @N7 }
|
||||
type @N7 = struct { a: @N8, b: @N8 }
|
||||
type @N8 = struct { a: @N9, b: @N9 }
|
||||
type @N9 = struct { a: @N10, b: @N10 }
|
||||
type @N10 = struct { a: @N11, b: @N11 }
|
||||
type @N11 = struct { a: @N12, b: @N12 }
|
||||
type @N12 = struct { a: @N13, b: @N13 }
|
||||
type @N13 = struct { a: @N14, b: @N14 }
|
||||
type @N14 = struct { a: @N15, b: @N15 }
|
||||
type @N15 = struct { a: @N16, b: @N16 }
|
||||
type @N16 = struct { a: @N17, b: @N17 }
|
||||
type @N17 = struct { a: @N18, b: @N18 }
|
||||
type @N18 = struct { a: @N19, b: @N19 }
|
||||
type @N19 = struct { a: @N20, b: @N20 }
|
||||
type @N20 = struct { a: @N21, b: @N21 }
|
||||
type @N21 = struct { a: @N22, b: @N22 }
|
||||
type @N22 = struct { a: @N23, b: @N23 }
|
||||
type @N23 = struct { a: @N24, b: @N24 }
|
||||
type @N24 = struct { a: @N25, b: @N25 }
|
||||
type @N25 = struct { a: @N26, b: @N26 }
|
||||
type @N26 = struct { a: @N27, b: @N27 }
|
||||
type @N27 = struct { a: @N28, b: @N28 }
|
||||
type @N28 = struct { a: @N29, b: @N29 }
|
||||
type @N29 = struct { a: @N30, b: @N30 }
|
||||
type @N30 = struct { a: @N31, b: @N31 }
|
||||
type @N31 = struct { a: @N32, b: @N32 }
|
||||
type @N32 = struct { a: @N33, b: @N33 }
|
||||
type @N33 = struct { a: @N34, b: @N34 }
|
||||
type @N34 = struct { a: @N35, b: @N35 }
|
||||
type @N35 = struct { a: @N36, b: @N36 }
|
||||
type @N36 = struct { a: @N37, b: @N37 }
|
||||
type @N37 = struct { a: @N38, b: @N38 }
|
||||
type @N38 = struct { a: @N39, b: @N39 }
|
||||
type @N39 = struct { a: @N40, b: @N40 }
|
||||
type @N40 = struct { a: @N41, b: @N41 }
|
||||
type @N41 = struct { a: @N42, b: @N42 }
|
||||
type @N42 = struct { a: @N43, b: @N43 }
|
||||
type @N43 = struct { a: @N44, b: @N44 }
|
||||
type @N44 = struct { a: @N45, b: @N45 }
|
||||
type @N45 = struct { a: @N46, b: @N46 }
|
||||
type @N46 = struct { a: @N47, b: @N47 }
|
||||
type @N47 = struct { a: @N48, b: @N48 }
|
||||
type @N48 = struct { a: @N49, b: @N49 }
|
||||
type @N49 = struct { a: @N50, b: @N50 }
|
||||
type @N50 = struct { a: @N51, b: @N51 }
|
||||
type @N51 = struct { a: @N52, b: @N52 }
|
||||
type @N52 = struct { a: @N53, b: @N53 }
|
||||
type @N53 = struct { a: @N54, b: @N54 }
|
||||
type @N54 = struct { a: @N55, b: @N55 }
|
||||
type @N55 = struct { a: @N56, b: @N56 }
|
||||
type @N56 = struct { a: @N57, b: @N57 }
|
||||
type @N57 = struct { a: @N58, b: @N58 }
|
||||
type @N58 = struct { a: @N59, b: @N59 }
|
||||
type @N59 = struct { a: @N60, b: @N60 }
|
||||
type @N60 = struct { a: @N61, b: @N61 }
|
||||
type @N61 = struct { a: @N62, b: @N62 }
|
||||
type @N62 = struct { a: @N63, b: @N63 }
|
||||
type @N63 = struct { a: @N64, b: @N64 }
|
||||
type @N64 = struct {}
|
||||
fn @echo(%p: @N0) -> @N0
|
||||
effects []
|
||||
entry:
|
||||
ret %p
|
||||
fn @main() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%answer = const.u64 42
|
||||
ret %answer
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: 42
|
||||
; phase: 6
|
||||
; spec: docs/spec/03-memory-model.md §22
|
||||
module test.nominal_queries
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, heap, islands, ownership, resources]
|
||||
type @N0 = struct { next: iref<@N0> }
|
||||
fn @main() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%n = const.u64 42
|
||||
ret %n
|
||||
@@ -0,0 +1,47 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §5/§15
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1 }
|
||||
struct N1 { a: N2 }
|
||||
struct N2 { a: N3 }
|
||||
struct N3 { a: N4 }
|
||||
struct N4 { a: N5 }
|
||||
struct N5 { a: N6 }
|
||||
struct N6 { a: N7 }
|
||||
struct N7 { a: N8 }
|
||||
struct N8 { a: N9 }
|
||||
struct N9 { a: N10 }
|
||||
struct N10 { a: N11 }
|
||||
struct N11 { a: N12 }
|
||||
struct N12 { a: N13 }
|
||||
struct N13 { a: N14 }
|
||||
struct N14 { a: N15 }
|
||||
struct N15 { a: N16 }
|
||||
struct N16 { a: N17 }
|
||||
struct N17 { a: N18 }
|
||||
struct N18 { a: N19 }
|
||||
struct N19 { a: N20 }
|
||||
struct N20 { a: N21 }
|
||||
struct N21 { a: N22 }
|
||||
struct N22 { a: N23 }
|
||||
struct N23 { a: N24 }
|
||||
struct N24 { a: N25 }
|
||||
struct N25 { a: N26 }
|
||||
struct N26 { a: N27 }
|
||||
struct N27 { a: N28 }
|
||||
struct N28 { a: N29 }
|
||||
struct N29 { a: N30 }
|
||||
struct N30 { a: N31 }
|
||||
struct N31 { a: N32 }
|
||||
struct N32 { a: N33 }
|
||||
struct N33 { a: N34 }
|
||||
struct N34 { a: N35 }
|
||||
struct N35 { a: N36 }
|
||||
struct N36 { a: N37 }
|
||||
struct N37 { a: N38 }
|
||||
struct N38 { a: N39 }
|
||||
struct N39 { a: N40 }
|
||||
struct N40 { x: ref<u64> }
|
||||
fn echo(p: N0) -> N0 effects [] { return move p; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,71 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §5/§15
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1 }
|
||||
struct N1 { a: N2 }
|
||||
struct N2 { a: N3 }
|
||||
struct N3 { a: N4 }
|
||||
struct N4 { a: N5 }
|
||||
struct N5 { a: N6 }
|
||||
struct N6 { a: N7 }
|
||||
struct N7 { a: N8 }
|
||||
struct N8 { a: N9 }
|
||||
struct N9 { a: N10 }
|
||||
struct N10 { a: N11 }
|
||||
struct N11 { a: N12 }
|
||||
struct N12 { a: N13 }
|
||||
struct N13 { a: N14 }
|
||||
struct N14 { a: N15 }
|
||||
struct N15 { a: N16 }
|
||||
struct N16 { a: N17 }
|
||||
struct N17 { a: N18 }
|
||||
struct N18 { a: N19 }
|
||||
struct N19 { a: N20 }
|
||||
struct N20 { a: N21 }
|
||||
struct N21 { a: N22 }
|
||||
struct N22 { a: N23 }
|
||||
struct N23 { a: N24 }
|
||||
struct N24 { a: N25 }
|
||||
struct N25 { a: N26 }
|
||||
struct N26 { a: N27 }
|
||||
struct N27 { a: N28 }
|
||||
struct N28 { a: N29 }
|
||||
struct N29 { a: N30 }
|
||||
struct N30 { a: N31 }
|
||||
struct N31 { a: N32 }
|
||||
struct N32 { a: N33 }
|
||||
struct N33 { a: N34 }
|
||||
struct N34 { a: N35 }
|
||||
struct N35 { a: N36 }
|
||||
struct N36 { a: N37 }
|
||||
struct N37 { a: N38 }
|
||||
struct N38 { a: N39 }
|
||||
struct N39 { a: N40 }
|
||||
struct N40 { a: N41 }
|
||||
struct N41 { a: N42 }
|
||||
struct N42 { a: N43 }
|
||||
struct N43 { a: N44 }
|
||||
struct N44 { a: N45 }
|
||||
struct N45 { a: N46 }
|
||||
struct N46 { a: N47 }
|
||||
struct N47 { a: N48 }
|
||||
struct N48 { a: N49 }
|
||||
struct N49 { a: N50 }
|
||||
struct N50 { a: N51 }
|
||||
struct N51 { a: N52 }
|
||||
struct N52 { a: N53 }
|
||||
struct N53 { a: N54 }
|
||||
struct N54 { a: N55 }
|
||||
struct N55 { a: N56 }
|
||||
struct N56 { a: N57 }
|
||||
struct N57 { a: N58 }
|
||||
struct N58 { a: N59 }
|
||||
struct N59 { a: N60 }
|
||||
struct N60 { a: N61 }
|
||||
struct N61 { a: N62 }
|
||||
struct N62 { a: N63 }
|
||||
struct N63 { a: N64 }
|
||||
struct N64 { x: u64 }
|
||||
fn marker<T: Copy>() -> u64 effects [] { return 42; }
|
||||
fn main() -> u64 effects [] { return marker::<N0>(); }
|
||||
@@ -0,0 +1,46 @@
|
||||
// expect: reject E1003
|
||||
// phase: 6
|
||||
// spec: docs/spec/03-memory-model.md §22/§25
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1, b: N1 }
|
||||
struct N1 { a: N2, b: N2 }
|
||||
struct N2 { a: N3, b: N3 }
|
||||
struct N3 { a: N4, b: N4 }
|
||||
struct N4 { a: N5, b: N5 }
|
||||
struct N5 { a: N6, b: N6 }
|
||||
struct N6 { a: N7, b: N7 }
|
||||
struct N7 { a: N8, b: N8 }
|
||||
struct N8 { a: N9, b: N9 }
|
||||
struct N9 { a: N10, b: N10 }
|
||||
struct N10 { a: N11, b: N11 }
|
||||
struct N11 { a: N12, b: N12 }
|
||||
struct N12 { a: N13, b: N13 }
|
||||
struct N13 { a: N14, b: N14 }
|
||||
struct N14 { a: N15, b: N15 }
|
||||
struct N15 { a: N16, b: N16 }
|
||||
struct N16 { a: N17, b: N17 }
|
||||
struct N17 { a: N18, b: N18 }
|
||||
struct N18 { a: N19, b: N19 }
|
||||
struct N19 { a: N20, b: N20 }
|
||||
struct N20 { a: N21, b: N21 }
|
||||
struct N21 { a: N22, b: N22 }
|
||||
struct N22 { a: N23, b: N23 }
|
||||
struct N23 { a: N24, b: N24 }
|
||||
struct N24 { a: N25, b: N25 }
|
||||
struct N25 { a: N26, b: N26 }
|
||||
struct N26 { a: N27, b: N27 }
|
||||
struct N27 { a: N28, b: N28 }
|
||||
struct N28 { a: N29, b: N29 }
|
||||
struct N29 { a: N30, b: N30 }
|
||||
struct N30 { a: N31, b: N31 }
|
||||
struct N31 { a: N32, b: N32 }
|
||||
struct N32 { a: N33, b: N33 }
|
||||
struct N33 { a: N34, b: N34 }
|
||||
struct N34 { a: N35, b: N35 }
|
||||
struct N35 { a: N36, b: N36 }
|
||||
struct N36 { a: N37, b: N37 }
|
||||
struct N37 { a: N38, b: N38 }
|
||||
struct N38 { a: N39, b: N39 }
|
||||
struct N39 { a: N40, b: N40 }
|
||||
struct N40 { a: N0, b: N0 }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,24 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/08-verifier.md §7; docs/spec/15-source-language.md §10
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1, b: N1 }
|
||||
struct N1 { a: N2, b: N2 }
|
||||
struct N2 { a: N3, b: N3 }
|
||||
struct N3 { a: N4, b: N4 }
|
||||
struct N4 { a: N5, b: N5 }
|
||||
struct N5 { a: N6, b: N6 }
|
||||
struct N6 { a: N7, b: N7 }
|
||||
struct N7 { a: N8, b: N8 }
|
||||
struct N8 { a: N9, b: N9 }
|
||||
struct N9 { a: N10, b: N10 }
|
||||
struct N10 { a: N11, b: N11 }
|
||||
struct N11 { a: N12, b: N12 }
|
||||
struct N12 { a: N13, b: N13 }
|
||||
struct N13 { a: N14, b: N14 }
|
||||
struct N14 { a: N15, b: N15 }
|
||||
struct N15 { a: N16, b: N16 }
|
||||
struct N16 { x: u64 }
|
||||
fn echo(p: N0) -> N0 effects [] { return p; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,28 @@
|
||||
// expect: reject E5101 E5101 E5101 E5101
|
||||
// phase: 6
|
||||
// spec: docs/spec/08-verifier.md §7; docs/spec/15-source-language.md §10
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1, b: N1 }
|
||||
struct N1 { a: N2, b: N2 }
|
||||
struct N2 { a: N3, b: N3 }
|
||||
struct N3 { a: N4, b: N4 }
|
||||
struct N4 { a: N5, b: N5 }
|
||||
struct N5 { a: N6, b: N6 }
|
||||
struct N6 { a: N7, b: N7 }
|
||||
struct N7 { a: N8, b: N8 }
|
||||
struct N8 { a: N9, b: N9 }
|
||||
struct N9 { a: N10, b: N10 }
|
||||
struct N10 { a: N11, b: N11 }
|
||||
struct N11 { a: N12, b: N12 }
|
||||
struct N12 { a: N13, b: N13 }
|
||||
struct N13 { a: N14, b: N14 }
|
||||
struct N14 { a: N15, b: N15 }
|
||||
struct N15 { a: N16, b: N16 }
|
||||
struct N16 { a: N17, b: N17 }
|
||||
struct N17 { a: N18, b: N18 }
|
||||
struct N18 { a: N19, b: N19 }
|
||||
struct N19 { a: N20, b: N20 }
|
||||
struct N20 { a: N21, b: N21 }
|
||||
struct N21 { x: u64 }
|
||||
fn echo(p: N0) -> N0 effects [] { return p; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,72 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/08-verifier.md §7; docs/spec/15-source-language.md §10
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1, b: N1 }
|
||||
struct N1 { a: N2, b: N2 }
|
||||
struct N2 { a: N3, b: N3 }
|
||||
struct N3 { a: N4, b: N4 }
|
||||
struct N4 { a: N5, b: N5 }
|
||||
struct N5 { a: N6, b: N6 }
|
||||
struct N6 { a: N7, b: N7 }
|
||||
struct N7 { a: N8, b: N8 }
|
||||
struct N8 { a: N9, b: N9 }
|
||||
struct N9 { a: N10, b: N10 }
|
||||
struct N10 { a: N11, b: N11 }
|
||||
struct N11 { a: N12, b: N12 }
|
||||
struct N12 { a: N13, b: N13 }
|
||||
struct N13 { a: N14, b: N14 }
|
||||
struct N14 { a: N15, b: N15 }
|
||||
struct N15 { a: N16, b: N16 }
|
||||
struct N16 { a: N17, b: N17 }
|
||||
struct N17 { a: N18, b: N18 }
|
||||
struct N18 { a: N19, b: N19 }
|
||||
struct N19 { a: N20, b: N20 }
|
||||
struct N20 { a: N21, b: N21 }
|
||||
struct N21 { a: N22, b: N22 }
|
||||
struct N22 { a: N23, b: N23 }
|
||||
struct N23 { a: N24, b: N24 }
|
||||
struct N24 { a: N25, b: N25 }
|
||||
struct N25 { a: N26, b: N26 }
|
||||
struct N26 { a: N27, b: N27 }
|
||||
struct N27 { a: N28, b: N28 }
|
||||
struct N28 { a: N29, b: N29 }
|
||||
struct N29 { a: N30, b: N30 }
|
||||
struct N30 { a: N31, b: N31 }
|
||||
struct N31 { a: N32, b: N32 }
|
||||
struct N32 { a: N33, b: N33 }
|
||||
struct N33 { a: N34, b: N34 }
|
||||
struct N34 { a: N35, b: N35 }
|
||||
struct N35 { a: N36, b: N36 }
|
||||
struct N36 { a: N37, b: N37 }
|
||||
struct N37 { a: N38, b: N38 }
|
||||
struct N38 { a: N39, b: N39 }
|
||||
struct N39 { a: N40, b: N40 }
|
||||
struct N40 { a: N41, b: N41 }
|
||||
struct N41 { a: N42, b: N42 }
|
||||
struct N42 { a: N43, b: N43 }
|
||||
struct N43 { a: N44, b: N44 }
|
||||
struct N44 { a: N45, b: N45 }
|
||||
struct N45 { a: N46, b: N46 }
|
||||
struct N46 { a: N47, b: N47 }
|
||||
struct N47 { a: N48, b: N48 }
|
||||
struct N48 { a: N49, b: N49 }
|
||||
struct N49 { a: N50, b: N50 }
|
||||
struct N50 { a: N51, b: N51 }
|
||||
struct N51 { a: N52, b: N52 }
|
||||
struct N52 { a: N53, b: N53 }
|
||||
struct N53 { a: N54, b: N54 }
|
||||
struct N54 { a: N55, b: N55 }
|
||||
struct N55 { a: N56, b: N56 }
|
||||
struct N56 { a: N57, b: N57 }
|
||||
struct N57 { a: N58, b: N58 }
|
||||
struct N58 { a: N59, b: N59 }
|
||||
struct N59 { a: N60, b: N60 }
|
||||
struct N60 { a: N61, b: N61 }
|
||||
struct N61 { a: N62, b: N62 }
|
||||
struct N62 { a: N63, b: N63 }
|
||||
struct N63 { a: N64, b: N64 }
|
||||
struct N64 {}
|
||||
fn echo(p: N0) -> N0 effects [] { return p; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,48 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §15
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1 }
|
||||
struct N1 { a: N2 }
|
||||
struct N2 { a: N3 }
|
||||
struct N3 { a: N4 }
|
||||
struct N4 { a: N5 }
|
||||
struct N5 { a: N6 }
|
||||
struct N6 { a: N7 }
|
||||
struct N7 { a: N8 }
|
||||
struct N8 { a: N9 }
|
||||
struct N9 { a: N10 }
|
||||
struct N10 { a: N11 }
|
||||
struct N11 { a: N12 }
|
||||
struct N12 { a: N13 }
|
||||
struct N13 { a: N14 }
|
||||
struct N14 { a: N15 }
|
||||
struct N15 { a: N16 }
|
||||
struct N16 { a: N17 }
|
||||
struct N17 { a: N18 }
|
||||
struct N18 { a: N19 }
|
||||
struct N19 { a: N20 }
|
||||
struct N20 { a: N21 }
|
||||
struct N21 { a: N22 }
|
||||
struct N22 { a: N23 }
|
||||
struct N23 { a: N24 }
|
||||
struct N24 { a: N25 }
|
||||
struct N25 { a: N26 }
|
||||
struct N26 { a: N27 }
|
||||
struct N27 { a: N28 }
|
||||
struct N28 { a: N29 }
|
||||
struct N29 { a: N30 }
|
||||
struct N30 { a: N31 }
|
||||
struct N31 { a: N32 }
|
||||
struct N32 { a: N33 }
|
||||
struct N33 { a: N34 }
|
||||
struct N34 { a: N35 }
|
||||
struct N35 { a: N36 }
|
||||
struct N36 { a: N37 }
|
||||
struct N37 { a: N38 }
|
||||
struct N38 { a: N39 }
|
||||
struct N39 { a: N40 }
|
||||
struct N40 { x: u64 }
|
||||
fn marker<T: Copy>() -> u64 effects [] { return 42; }
|
||||
fn main() -> u64 effects [] { return marker::<N0>(); }
|
||||
@@ -0,0 +1,48 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §15
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1 }
|
||||
struct N1 { a: N2 }
|
||||
struct N2 { a: N3 }
|
||||
struct N3 { a: N4 }
|
||||
struct N4 { a: N5 }
|
||||
struct N5 { a: N6 }
|
||||
struct N6 { a: N7 }
|
||||
struct N7 { a: N8 }
|
||||
struct N8 { a: N9 }
|
||||
struct N9 { a: N10 }
|
||||
struct N10 { a: N11 }
|
||||
struct N11 { a: N12 }
|
||||
struct N12 { a: N13 }
|
||||
struct N13 { a: N14 }
|
||||
struct N14 { a: N15 }
|
||||
struct N15 { a: N16 }
|
||||
struct N16 { a: N17 }
|
||||
struct N17 { a: N18 }
|
||||
struct N18 { a: N19 }
|
||||
struct N19 { a: N20 }
|
||||
struct N20 { a: N21 }
|
||||
struct N21 { a: N22 }
|
||||
struct N22 { a: N23 }
|
||||
struct N23 { a: N24 }
|
||||
struct N24 { a: N25 }
|
||||
struct N25 { a: N26 }
|
||||
struct N26 { a: N27 }
|
||||
struct N27 { a: N28 }
|
||||
struct N28 { a: N29 }
|
||||
struct N29 { a: N30 }
|
||||
struct N30 { a: N31 }
|
||||
struct N31 { a: N32 }
|
||||
struct N32 { a: N33 }
|
||||
struct N33 { a: N34 }
|
||||
struct N34 { a: N35 }
|
||||
struct N35 { a: N36 }
|
||||
struct N36 { a: N37 }
|
||||
struct N37 { a: N38 }
|
||||
struct N38 { a: N39 }
|
||||
struct N39 { a: N40 }
|
||||
struct N40 { x: u64 }
|
||||
fn marker<T: Freeze>() -> u64 effects [] { return 42; }
|
||||
fn main() -> u64 effects [] { return marker::<N0>(); }
|
||||
@@ -0,0 +1,48 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §15
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1 }
|
||||
struct N1 { a: N2 }
|
||||
struct N2 { a: N3 }
|
||||
struct N3 { a: N4 }
|
||||
struct N4 { a: N5 }
|
||||
struct N5 { a: N6 }
|
||||
struct N6 { a: N7 }
|
||||
struct N7 { a: N8 }
|
||||
struct N8 { a: N9 }
|
||||
struct N9 { a: N10 }
|
||||
struct N10 { a: N11 }
|
||||
struct N11 { a: N12 }
|
||||
struct N12 { a: N13 }
|
||||
struct N13 { a: N14 }
|
||||
struct N14 { a: N15 }
|
||||
struct N15 { a: N16 }
|
||||
struct N16 { a: N17 }
|
||||
struct N17 { a: N18 }
|
||||
struct N18 { a: N19 }
|
||||
struct N19 { a: N20 }
|
||||
struct N20 { a: N21 }
|
||||
struct N21 { a: N22 }
|
||||
struct N22 { a: N23 }
|
||||
struct N23 { a: N24 }
|
||||
struct N24 { a: N25 }
|
||||
struct N25 { a: N26 }
|
||||
struct N26 { a: N27 }
|
||||
struct N27 { a: N28 }
|
||||
struct N28 { a: N29 }
|
||||
struct N29 { a: N30 }
|
||||
struct N30 { a: N31 }
|
||||
struct N31 { a: N32 }
|
||||
struct N32 { a: N33 }
|
||||
struct N33 { a: N34 }
|
||||
struct N34 { a: N35 }
|
||||
struct N35 { a: N36 }
|
||||
struct N36 { a: N37 }
|
||||
struct N37 { a: N38 }
|
||||
struct N38 { a: N39 }
|
||||
struct N39 { a: N40 }
|
||||
struct N40 { x: u64 }
|
||||
fn marker<T: Send>() -> u64 effects [] { return 42; }
|
||||
fn main() -> u64 effects [] { return marker::<N0>(); }
|
||||
@@ -0,0 +1,48 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §15
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1 }
|
||||
struct N1 { a: N2 }
|
||||
struct N2 { a: N3 }
|
||||
struct N3 { a: N4 }
|
||||
struct N4 { a: N5 }
|
||||
struct N5 { a: N6 }
|
||||
struct N6 { a: N7 }
|
||||
struct N7 { a: N8 }
|
||||
struct N8 { a: N9 }
|
||||
struct N9 { a: N10 }
|
||||
struct N10 { a: N11 }
|
||||
struct N11 { a: N12 }
|
||||
struct N12 { a: N13 }
|
||||
struct N13 { a: N14 }
|
||||
struct N14 { a: N15 }
|
||||
struct N15 { a: N16 }
|
||||
struct N16 { a: N17 }
|
||||
struct N17 { a: N18 }
|
||||
struct N18 { a: N19 }
|
||||
struct N19 { a: N20 }
|
||||
struct N20 { a: N21 }
|
||||
struct N21 { a: N22 }
|
||||
struct N22 { a: N23 }
|
||||
struct N23 { a: N24 }
|
||||
struct N24 { a: N25 }
|
||||
struct N25 { a: N26 }
|
||||
struct N26 { a: N27 }
|
||||
struct N27 { a: N28 }
|
||||
struct N28 { a: N29 }
|
||||
struct N29 { a: N30 }
|
||||
struct N30 { a: N31 }
|
||||
struct N31 { a: N32 }
|
||||
struct N32 { a: N33 }
|
||||
struct N33 { a: N34 }
|
||||
struct N34 { a: N35 }
|
||||
struct N35 { a: N36 }
|
||||
struct N36 { a: N37 }
|
||||
struct N37 { a: N38 }
|
||||
struct N38 { a: N39 }
|
||||
struct N39 { a: N40 }
|
||||
struct N40 { x: u64 }
|
||||
fn marker<T: Share>() -> u64 effects [] { return 42; }
|
||||
fn main() -> u64 effects [] { return marker::<N0>(); }
|
||||
@@ -0,0 +1,48 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §5/§15
|
||||
module test.nominal_queries
|
||||
struct N0 { a: N1 }
|
||||
struct N1 { a: N2 }
|
||||
struct N2 { a: N3 }
|
||||
struct N3 { a: N4 }
|
||||
struct N4 { a: N5 }
|
||||
struct N5 { a: N6 }
|
||||
struct N6 { a: N7 }
|
||||
struct N7 { a: N8 }
|
||||
struct N8 { a: N9 }
|
||||
struct N9 { a: N10 }
|
||||
struct N10 { a: N11 }
|
||||
struct N11 { a: N12 }
|
||||
struct N12 { a: N13 }
|
||||
struct N13 { a: N14 }
|
||||
struct N14 { a: N15 }
|
||||
struct N15 { a: N16 }
|
||||
struct N16 { a: N17 }
|
||||
struct N17 { a: N18 }
|
||||
struct N18 { a: N19 }
|
||||
struct N19 { a: N20 }
|
||||
struct N20 { a: N21 }
|
||||
struct N21 { a: N22 }
|
||||
struct N22 { a: N23 }
|
||||
struct N23 { a: N24 }
|
||||
struct N24 { a: N25 }
|
||||
struct N25 { a: N26 }
|
||||
struct N26 { a: N27 }
|
||||
struct N27 { a: N28 }
|
||||
struct N28 { a: N29 }
|
||||
struct N29 { a: N30 }
|
||||
struct N30 { a: N31 }
|
||||
struct N31 { a: N32 }
|
||||
struct N32 { a: N33 }
|
||||
struct N33 { a: N34 }
|
||||
struct N34 { a: N35 }
|
||||
struct N35 { a: N36 }
|
||||
struct N36 { a: N37 }
|
||||
struct N37 { a: N38 }
|
||||
struct N38 { a: N39 }
|
||||
struct N39 { a: N40 }
|
||||
struct N40 { x: own<u64> }
|
||||
fn echo(p: N0) -> N0 effects [] { return move p; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/03-memory-model.md §22/§25
|
||||
module test.nominal_queries
|
||||
struct N0 { next: iref<N0> }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Deep shared types: CLI/format/profile parity and imported cache indices."""
|
||||
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/nominal_queries'
|
||||
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
|
||||
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix='aji-nominal-queries-') as directory:
|
||||
root = Path(directory)
|
||||
for source in sorted(CORPUS.glob('*.aji')):
|
||||
formatted = root / source.name
|
||||
formatted.write_text(cli('fmt', source))
|
||||
cli('fmt', '--check', formatted)
|
||||
assert cli('fmt', formatted) == formatted.read_text()
|
||||
if '// expect: reject' in source.read_text():
|
||||
diagnostics = cli('check', source, code=1)
|
||||
for command in ('run', 'report', 'explore'):
|
||||
assert cli(command, source, code=1) == diagnostics
|
||||
records = [json.loads(line) for line in diagnostics.splitlines()]
|
||||
assert all(d['file'] == str(source) for d in records), records
|
||||
if source.stem == 'cycle':
|
||||
assert (records[0]['code'], records[0]['type'], records[0]['line']) == ('E1003', 'N0', 5)
|
||||
elif source.stem == 'constraint_depth':
|
||||
assert records[0]['reason'] == 'implementation_limit'
|
||||
elif source.stem == 'diamond_21_u64':
|
||||
assert [d['found'] for d in records] == [16777216, 8388608, 4194304, 2097152]
|
||||
# Lowering emits AIR; the subsequent budget stage rejects it.
|
||||
raw = root / 'oversized.air'
|
||||
raw.write_text(cli('lower', source))
|
||||
raw_records = [json.loads(line) for line in cli('check', raw, code=1).splitlines()]
|
||||
assert [(d['code'], d['found']) for d in raw_records] == [(d['code'], d['found']) for d in records]
|
||||
if source.stem != 'diamond_21_u64':
|
||||
assert cli('lower', source, code=1) == diagnostics
|
||||
continue
|
||||
air = cli('lower', source)
|
||||
assert cli('lower', formatted) == air
|
||||
raw = root / f'{source.stem}.air'
|
||||
raw.write_text(air)
|
||||
cli('check', raw)
|
||||
expected = json.loads(cli('run', '--fuel', '100000', source))
|
||||
assert expected['value'] == 42, expected
|
||||
assert json.loads(cli('run', '--fuel', '100000', raw)) == expected
|
||||
result = root / f'{source.stem}.json'
|
||||
cli('run', '--profile', 'hosted', '--fuel', '100000', '--result-file', result, source)
|
||||
assert json.loads(result.read_text())['value'] == 42
|
||||
|
||||
library, entry, manifest = (root / name for name in ('nodes.aji', 'main.aji', 'aji.toml'))
|
||||
library.write_text('module lib.nodes\n' + '\n'.join(
|
||||
f'struct N{i} {{ a: N{i + 1} }}' for i in range(40)) + '\nstruct N40 { x: u64 }\n')
|
||||
entry.write_text('module app\nimport lib.nodes;\n'
|
||||
'fn marker<T: Copy + Send + Share + Freeze>() -> u64 effects [] { return 42; }\n'
|
||||
'fn main() -> u64 effects [] { return marker::<lib.nodes.N0>(); }\n')
|
||||
manifest.write_text('[package]\nname = "nodes"\nversion = "1"\nentry = "main.aji"\n'
|
||||
'[modules]\nlib.nodes = "nodes.aji"\n')
|
||||
assert json.loads(cli('run', '--manifest', manifest))['value'] == 42
|
||||
# Actual allocation accounting reads a verified nominal cache at runtime.
|
||||
allocated = root / 'allocated.aji'
|
||||
declarations = library.read_text().replace('module lib.nodes', 'module app')
|
||||
bindings = 'let n40 = N40 { x: 42u64 };\n' + '\n'.join(
|
||||
f'let n{i} = N{i} {{ a: n{i + 1} }};' for i in reversed(range(40)))
|
||||
allocated.write_text(declarations + '\nfn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {\n' +
|
||||
bindings + '\nlet p = own.new(n0, heap) or trap; let n = own.take(move p);\nreturn n' + '.a' * 40 + '.x; }\n')
|
||||
raw = root / 'allocated.air'
|
||||
raw.write_text(cli('lower', allocated))
|
||||
grants = ['--grant', 'heap=mem.alloc:8']
|
||||
result = json.loads(cli('run', '--fuel', '100000', *grants, allocated))
|
||||
assert result['value'] == 42, result
|
||||
assert json.loads(cli('run', '--fuel', '100000', *grants, raw)) == result
|
||||
library.write_text(library.read_text().replace('struct N40 { x: u64 }', 'struct N40 { x: N0 }'))
|
||||
record = json.loads(cli('check', '--manifest', manifest, code=1))
|
||||
assert (record['code'], record['file'], record['line']) == ('E1003', 'nodes.aji', 2), record
|
||||
assert record['type'].endswith('N0'), record
|
||||
|
||||
print(f'nominal query CLI integration passed ({checks} checks)')
|
||||
Reference in new issue
Block a user