Phase 2: effects and capabilities (RFC 0006)
- air: cap<K> and built-in enums (cap_error) as types; enum.switch over built-in enums; cap.narrow terminator with ok/err targets; intrinsic syntax (registry still empty: E0004); registries for effects, capability kinds and built-in enums, synced with reference docs - verifier: effect stage (E3101, flat, direct callees); cap.narrow form check (E3202) and ok/err parameter rules (E5002, E1001); capabilities are copyable, not zeroable, not comparable; sizes cap 8, built-in tag - interp: host authority table; @main instantiation from grants by parameter name with not_instantiated reasons; capabilities render as opaque - CLI: --grant P=KIND[:SCOPE], exit code 6; runner: grant: and not_instantiated: headers, pending only for unsupported features - conformance: 18 Phase 2 tests; 4000 mutants without a crash
This commit is contained in:
1 parent
fb4338cea6
commit
9c29a80b72
41 files changed
+908
-58
No files matched your search
@@ -0,0 +1,49 @@
|
||||
//! Effect checking (spec 05 §9.3). Reports E3101.
|
||||
//!
|
||||
//! Applies to modules that declare the feature `effects`. Effects are flat
|
||||
//! atoms: a call needs every effect of its callee in the caller's list.
|
||||
//! Checking each function against its direct callees makes the rule hold
|
||||
//! transitively, including through recursion.
|
||||
|
||||
const std = @import("std");
|
||||
const air = @import("../air.zig");
|
||||
const verifier = @import("../verifier.zig");
|
||||
|
||||
const Context = verifier.Context;
|
||||
|
||||
pub fn check(c: *Context) !void {
|
||||
const m = c.module;
|
||||
if (!m.declares("effects")) return;
|
||||
for (m.functions) |f| {
|
||||
for (f.blocks) |b| for (b.insts) |inst| switch (inst.op) {
|
||||
.call => |x| {
|
||||
const callee = m.functions[x.callee];
|
||||
for (callee.effects) |e| if (!contains(f.effects, e)) {
|
||||
try c.report("E3101", inst.span, "callee effect not declared by the caller", &.{
|
||||
.{ .name = "function", .value = .{ .str = f.name } },
|
||||
.{ .name = "callee", .value = .{ .str = callee.name } },
|
||||
.{ .name = "effect", .value = .{ .str = e } },
|
||||
});
|
||||
};
|
||||
},
|
||||
else => {},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn contains(list: []const []const u8, name: []const u8) bool {
|
||||
for (list) |x| if (std.mem.eql(u8, x, name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
const h = "module t\nair 0\nlang 0.1\nfeatures [effects]\n";
|
||||
|
||||
test "callee effects must be declared" {
|
||||
const g = "fn @g() -> void\neffects [io.write]\nentry:\n ret\n";
|
||||
try verifier.expectCodes(h ++ "fn @f() -> void\neffects [io.write]\nentry:\n call @g()\n ret\n" ++ g, &.{});
|
||||
try verifier.expectCodes(h ++ "fn @f() -> void\neffects []\nentry:\n call @g()\n ret\n" ++ g, &.{"E3101"});
|
||||
// Flat: atomic does not cover atomic.weak.
|
||||
try verifier.expectCodes(h ++ "fn @f() -> void\neffects [atomic]\nentry:\n call @w()\n ret\nfn @w() -> void\neffects [atomic.weak]\nentry:\n ret\n", &.{"E3101"});
|
||||
// Without the feature, lists are recorded but not checked.
|
||||
try verifier.expectCodes("module t\nair 0\nlang 0.1\nfeatures []\nfn @f() -> void\neffects []\nentry:\n call @g()\n ret\n" ++ g, &.{});
|
||||
}
|
||||
Reference in new issue
Block a user