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:
1 parent
89c63c306b
commit
1eaf968f4f
56 files changed
+823
-4
No files matched your search
@@ -31,6 +31,7 @@ pub const registry = [_]Feature{
|
||||
.{ .name = "channel_transfer", .depends = &.{ "cancellation", "capabilities", "channels", "effects", "heap", "ownership", "resources", "tasks" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "channels", .depends = &.{ "cancellation", "capabilities", "effects", "heap", "ownership", "resources", "tasks" }, .status = .published, .phase = 3 },
|
||||
.{ .name = "effects", .depends = &.{}, .status = .published, .phase = 2 },
|
||||
.{ .name = "error_values", .depends = &.{ "capabilities", "effects", "heap", "ownership", "resources" }, .status = .published, .phase = 6 },
|
||||
.{ .name = "guard_transfer", .depends = &.{ "cancellation", "effects", "ownership", "sync", "tasks" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "heap", .depends = &.{ "capabilities", "effects", "ownership", "resources" }, .status = .published, .phase = 2 },
|
||||
.{ .name = "islands", .depends = &.{ "capabilities", "effects", "heap", "ownership", "resources" }, .status = .published, .phase = 4 },
|
||||
@@ -50,7 +51,7 @@ pub const registry = [_]Feature{
|
||||
};
|
||||
|
||||
/// Features implemented by this toolchain, sorted.
|
||||
pub const supported = [_][]const u8{ "arc", "arrays", "atomics", "cancellation", "capabilities", "channels", "effects", "heap", "islands", "linear_aggregates", "linear_buffers", "ownership", "regions", "resources", "sync", "tasks", "unsafe" };
|
||||
pub const supported = [_][]const u8{ "arc", "arrays", "atomics", "cancellation", "capabilities", "channels", "effects", "error_values", "heap", "islands", "linear_aggregates", "linear_buffers", "ownership", "regions", "resources", "sync", "tasks", "unsafe" };
|
||||
|
||||
pub const Reason = enum {
|
||||
unknown_feature,
|
||||
|
||||
+3
-1
@@ -306,6 +306,8 @@ pub const Op = union(enum) {
|
||||
assume: ValueId,
|
||||
|
||||
@"const": struct { ty: Type, bits: u128 },
|
||||
/// Pure built-in error data (feature error_values, spec 05 §14).
|
||||
error_const: struct { which: authority.Builtin, variant: u32 },
|
||||
copy: ValueId,
|
||||
arith: struct { op: ArithOp, mode: ArithMode, ty: IntType, a: ValueId, b: ValueId },
|
||||
bit: struct { op: BitOp, ty: Type, a: ValueId, b: ValueId },
|
||||
@@ -559,7 +561,7 @@ pub fn forEachUse(op: Op, ctx: anytype, comptime f: fn (@TypeOf(ctx), ValueId) v
|
||||
},
|
||||
inline .buffer_pop, .buffer_free => |x| f(ctx, x.value),
|
||||
.buffer_len, .buffer_capacity, .buffer_view => |v| f(ctx, v),
|
||||
.@"const", .trap => {},
|
||||
.@"const", .error_const, .trap => {},
|
||||
.copy, .assert => |v| f(ctx, v),
|
||||
.arith => |x| {
|
||||
f(ctx, x.a);
|
||||
|
||||
+15
-1
@@ -873,6 +873,20 @@ const Parser = struct {
|
||||
const head = parts[0];
|
||||
|
||||
const op: air.Op = op: {
|
||||
if (eql(op_tok.text, "error.const")) {
|
||||
try p.requireFeature("error_values", op_tok.span, op_tok.text);
|
||||
const t = try p.expect(.word, "built-in error family and variant");
|
||||
const dot = std.mem.indexOfScalar(u8, t.text, '.') orelse return p.fail(t, "`B.variant`");
|
||||
const b = std.meta.stringToEnum(authority.Builtin, t.text[0..dot]) orelse {
|
||||
try p.report("E0004", t.span, "unknown built-in error family", &.{.{ .name = "name", .value = .{ .str = t.text[0..dot] } }});
|
||||
return error.SyntaxError;
|
||||
};
|
||||
const variant = b.variantIndex(t.text[dot + 1 ..]) orelse {
|
||||
try p.report("E0004", t.span, "unknown built-in error variant", &.{.{ .name = "name", .value = .{ .str = t.text[dot + 1 ..] } }});
|
||||
return error.SyntaxError;
|
||||
};
|
||||
break :op .{ .error_const = .{ .which = b, .variant = variant } };
|
||||
}
|
||||
if (eql(head, "const") and parts.len == 2) {
|
||||
if (eql(parts[1], "bool")) {
|
||||
const lit = try p.expect(.word, "`true` or `false`");
|
||||
@@ -1110,7 +1124,7 @@ const Parser = struct {
|
||||
.task_shield_begin, .channel_dup, .mutex_make, .mutex_take, .mutex_borrow => true,
|
||||
.island_root, .island_borrow, .island_freeze, .frozen_root, .frozen_borrow, .arc_from_frozen, .arc_clone, .arc_root, .arc_borrow, .iref_eq => true,
|
||||
.atomic_new, .atomic_take, .atomic_load, .atomic_rmw, .atomic_cmpxchg => true,
|
||||
.@"const", .copy, .arith, .bit, .cmp, .cast, .struct_make, .struct_get, .enum_make => true,
|
||||
.@"const", .error_const, .copy, .arith, .bit, .cmp, .cast, .struct_make, .struct_get, .enum_make => true,
|
||||
.local_alloc, .local_load, .borrow_ref, .borrow_mut, .borrow_field, .load => true,
|
||||
.buffer_len, .buffer_capacity, .buffer_view, .array_splat, .array_make, .value_swap, .borrow_index, .slice_make, .slice_len, .slice_sub, .slice_split => true,
|
||||
else => false,
|
||||
|
||||
@@ -179,6 +179,7 @@ fn printOp(m: air.Module, f: air.Function, op: air.Op, w: *Writer) Writer.Error!
|
||||
},
|
||||
else => unreachable,
|
||||
},
|
||||
.error_const => |x| try w.print("error.const {s}.{s}", .{ @tagName(x.which), x.which.variants()[x.variant] }),
|
||||
.copy => |v| {
|
||||
try w.writeAll("copy ");
|
||||
try value(f, v, w);
|
||||
@@ -717,6 +718,22 @@ test "round-trip whole-value linear operations" {
|
||||
);
|
||||
}
|
||||
|
||||
test "round-trip explicit error values" {
|
||||
try roundTrip(
|
||||
\\module test.errors
|
||||
\\air 0
|
||||
\\lang 0.1
|
||||
\\features [resources, ownership, heap, error_values, effects, capabilities]
|
||||
\\fn @main() -> alloc_error
|
||||
\\effects []
|
||||
\\entry:
|
||||
\\ %io = error.const io_error.invalid_input
|
||||
\\ %cap = error.const cap_error.not_subset
|
||||
\\ %e = error.const alloc_error.budget_exceeded
|
||||
\\ ret %e
|
||||
);
|
||||
}
|
||||
|
||||
test "round-trip initialized buffers" {
|
||||
try roundTrip(
|
||||
\\module test.buffers
|
||||
|
||||
Reference in new issue
Block a user