cli: add explicit built-in error values

Add the error_values feature and error.const through specification, AIR,
verification, interpretation and source lowering. Error values are Copy data
with no allocation, effects or authority. Keep enum.make semantics frozen.

Cover all registered tags, feature negotiation, payload/type errors and
authority rejection in AIR/source; verify canonical and hosted CLI behavior.
Record reference-bundle costs and the map preflight-validation prerequisite.
This commit is contained in:
dev committed 2026-10-07 08:09:49 +03:00
1 parent 89c63c306b
commit 1eaf968f4f
56 files changed
+823 -4

No files matched your search

+8 -1
View File
@@ -581,6 +581,7 @@ const Lowerer = struct {
.{ "arrays", &.{ "array<", "slice", "array.splat", "borrow.index" } },
.{ "ownership", &.{ "local.", "borrow.", " load ", "= load ", "store ", "ref<", "mut<" } },
.{ "linear_buffers", &.{ "buffer<", "buffer." } },
.{ "error_values", &.{"error.const "} },
.{ "linear_aggregates", &.{ "array.make ", "struct.unpack ", "array.unpack ", "enum.take ", "value.swap ", "own.pack " } },
.{ "heap", &.{ "own.", "own<", "own_array<", "alloc_error" } },
.{ "regions", &.{"region"} },
@@ -1401,7 +1402,7 @@ const Lowerer = struct {
fn typeOfNoFail(l: *Lowerer, t: ast.Type) ?Ty {
return switch (t.kind) {
.name => |n| if (isIntName(n)) Ty{ .int = n } else if (std.mem.eql(u8, n, "bool")) .bool else l.enumOrStruct(n, t.span),
.name => |n| if (isIntName(n)) Ty{ .int = n } else if (std.mem.eql(u8, n, "bool")) .bool else if (std.meta.stringToEnum(authority.Builtin, n)) |b| Ty{ .builtin = b } else l.enumOrStruct(n, t.span),
else => null,
};
}
@@ -1413,6 +1414,7 @@ const Lowerer = struct {
}
fn enumType(l: *Lowerer, n: []const u8, span: Span) ?Ty {
if (std.meta.stringToEnum(authority.Builtin, n)) |b| return .{ .builtin = b };
const t = l.enumOrStruct(n, span) orelse return null;
return if (l.m.types[t.named].kind == .@"enum") t else null;
}
@@ -1751,6 +1753,11 @@ const Lowerer = struct {
fn variantValue(l: *Lowerer, e: ast.Expr, enum_name: []const u8, variant: []const u8, args: []const ast.Expr) Error!Value {
const t = l.enumType(enum_name, e.span) orelse return l.fail("E7002", e.span, "unknown enum", &.{.{ .name = "name", .value = enum_name }});
if (t == .builtin) {
_ = t.builtin.variantIndex(variant) orelse return l.fail("E7002", e.span, "no such variant", &.{ .{ .name = "enum", .value = enum_name }, .{ .name = "variant", .value = variant } });
if (args.len != 0) return l.fail("E7005", e.span, "built-in error variants have no payload", &.{.{ .name = "variant", .value = variant }});
return l.def("e", t, try l.fmt("error.const {s}.{s}", .{ enum_name, variant }), e.span);
}
const vs = l.m.types[t.named].kind.@"enum";
const v = for (vs) |x| {
if (std.mem.eql(u8, x.name, variant)) break x;