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:
dev committed 2026-10-04 13:42:35 +03:00
1 parent fb4338cea6
commit 9c29a80b72
41 files changed
+908 -58

No files matched your search

+17 -3
View File
@@ -418,16 +418,30 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void {
try fc.expectTarget(span, x.default);
},
.enum_switch => |x| {
try fc.expectValue(span, x.value, .{ .named = x.decl });
const variants = m.types[x.decl].kind.@"enum";
try fc.expectValue(span, x.value, x.ty);
for (x.arms) |arm| {
const params = f.blocks[arm.block].params;
for (params, variants[arm.variant].payload) |p, t| {
for (params, m.variantPayload(x.ty, arm.variant)) |p, t| {
if (!p.ty.eql(t)) try fc.mismatch(arm.span, try fc.c.valueName(f, p.value), t, p.ty);
}
}
if (x.default) |d| try fc.expectTarget(span, d);
},
.cap_narrow => |x| {
const t = fc.typeOf(x.cap);
if (t != .cap) return fc.kindError(span, x.cap, "cap<K>");
// No form of any kind widens; an unregistered form is reported as
// an attempt to widen (spec 05 §10.4).
if (!air.authority.hasForm(t.cap, x.form)) try fc.c.report("E3202", span, "narrowing form not defined for this capability kind", &.{
.{ .name = "function", .value = .{ .str = f.name } },
.{ .name = "kind", .value = .{ .str = air.authority.kinds[t.cap].name } },
.{ .name = "form", .value = .{ .str = x.form } },
});
const ok = f.blocks[x.ok].params[0];
if (!ok.ty.eql(t)) try fc.mismatch(span, try fc.c.valueName(f, ok.value), t, ok.ty);
const err = f.blocks[x.err].params[0];
if (!err.ty.eql(.{ .builtin = .cap_error })) try fc.mismatch(span, try fc.c.valueName(f, err.value), .{ .builtin = .cap_error }, err.ty);
},
.ret => |v| switch (f.ret) {
.never => try fc.c.report("E1001", span, "`ret` in a function returning never", &.{
.{ .name = "function", .value = .{ .str = f.name } },