cli: add recoverable endian APIs and qualified std enums
This commit is contained in:
45 files changed
+1205
-89
No files matched your search
+66
-57
@@ -327,14 +327,22 @@ const Lowerer = struct {
|
||||
}
|
||||
|
||||
fn tyText(l: *Lowerer, t: Ty) []const u8 {
|
||||
return l.typeText(t, false);
|
||||
}
|
||||
|
||||
fn diagnosticTyText(l: *Lowerer, t: Ty) []const u8 {
|
||||
return l.typeText(t, true);
|
||||
}
|
||||
|
||||
fn typeText(l: *Lowerer, t: Ty, source_names: bool) []const u8 {
|
||||
return switch (t) {
|
||||
.int => |x| x,
|
||||
.bool => "bool",
|
||||
.void => "void",
|
||||
.never => "never",
|
||||
.named => |i| l.typeNames[i],
|
||||
.array => |a| std.fmt.allocPrint(l.arena, "array<{s}, {d}>", .{ l.tyText(a.elem), a.len }) catch "array",
|
||||
.ref, .mut, .slice, .slice_mut, .own, .own_array, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| std.fmt.allocPrint(l.arena, "{s}<{s}>", .{ @tagName(t), l.tyText(x.*) }) catch "borrow",
|
||||
.named => |i| if (source_names and l.m.types[i].air_name != null) l.m.types[i].name else l.typeNames[i],
|
||||
.array => |a| std.fmt.allocPrint(l.arena, "array<{s}, {d}>", .{ l.typeText(a.elem, source_names), a.len }) catch "array",
|
||||
.ref, .mut, .slice, .slice_mut, .own, .own_array, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| std.fmt.allocPrint(l.arena, "{s}<{s}>", .{ @tagName(t), l.typeText(x.*, source_names) }) catch "borrow",
|
||||
.scope => "scope",
|
||||
.shield => "shield",
|
||||
.region => "region",
|
||||
@@ -396,7 +404,7 @@ const Lowerer = struct {
|
||||
const names = try l.arena.alloc([]const u8, l.m.types.len);
|
||||
for (l.m.types, names, 0..) |t, *n, i| {
|
||||
for (l.m.types[0..i]) |prev| if (std.mem.eql(u8, prev.name, t.name)) return l.fail("E7006", t.span, "type defined twice", &.{.{ .name = "name", .value = t.name }});
|
||||
n.* = try l.fmt("@{s}", .{t.name});
|
||||
n.* = try l.fmt("@{s}", .{t.air_name orelse t.name});
|
||||
}
|
||||
l.typeNames = names;
|
||||
for (l.m.functions) |f| {
|
||||
@@ -479,7 +487,7 @@ const Lowerer = struct {
|
||||
/// `type @T = struct { … }` / `enum { … }` in canonical form.
|
||||
fn typeDeclText(l: *Lowerer, t: ast.TypeDecl) Error![]const u8 {
|
||||
var w: std.ArrayList(u8) = .empty;
|
||||
try w.appendSlice(l.arena, try l.fmt("type @{s} = ", .{t.name}));
|
||||
try w.appendSlice(l.arena, try l.fmt("type @{s} = ", .{t.air_name orelse t.name}));
|
||||
switch (t.kind) {
|
||||
.@"struct" => |fields| {
|
||||
try w.appendSlice(l.arena, "struct {");
|
||||
@@ -549,7 +557,7 @@ const Lowerer = struct {
|
||||
.frozen => l.wrap(.frozen, in),
|
||||
.arc => l.wrap(.arc, in),
|
||||
.iref => l.wrap(.iref, in),
|
||||
.atomic => if (atomicScalar(in)) l.wrap(.atomic, in) else l.fail("E7005", t.span, "atomic<T> needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.tyText(in) }}),
|
||||
.atomic => if (atomicScalar(in)) l.wrap(.atomic, in) else l.fail("E7005", t.span, "atomic<T> needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.diagnosticTyText(in) }}),
|
||||
};
|
||||
},
|
||||
.cap => |k| {
|
||||
@@ -969,7 +977,7 @@ const Lowerer = struct {
|
||||
try l.term(try l.retText(v), s.span);
|
||||
}
|
||||
} else {
|
||||
if (l.ret != .void) return l.fail("E7005", s.span, "`return` without a value in a function that returns one", &.{.{ .name = "expected", .value = l.tyText(l.ret) }});
|
||||
if (l.ret != .void) return l.fail("E7005", s.span, "`return` without a value in a function that returns one", &.{.{ .name = "expected", .value = l.diagnosticTyText(l.ret) }});
|
||||
try l.endScopes(0, s.span);
|
||||
try l.term("ret", s.span);
|
||||
}
|
||||
@@ -1016,7 +1024,7 @@ const Lowerer = struct {
|
||||
|
||||
fn checkTy(l: *Lowerer, span: Span, found: Ty, want: Ty) Error!void {
|
||||
if (found == .never or found.eql(want)) return;
|
||||
return l.fail("E7005", span, "type mismatch", &.{ .{ .name = "expected", .value = l.tyText(want) }, .{ .name = "found", .value = l.tyText(found) } });
|
||||
return l.fail("E7005", span, "type mismatch", &.{ .{ .name = "expected", .value = l.diagnosticTyText(want) }, .{ .name = "found", .value = l.diagnosticTyText(found) } });
|
||||
}
|
||||
|
||||
/// `while cond { body }` (cond null: `loop { body }`). Carried state:
|
||||
@@ -1071,7 +1079,7 @@ const Lowerer = struct {
|
||||
const depth = l.bindings.items.len;
|
||||
defer l.bindings.shrinkRetainingCapacity(depth);
|
||||
const ty = l.peekType(lo) orelse l.peekType(hi) orelse return l.fail("E7007", lo.span, "the type of the range cannot be determined; add a suffix such as `0usize`", &.{});
|
||||
if (ty != .int) return l.fail("E7005", lo.span, "a range needs an integer type", &.{.{ .name = "found", .value = l.tyText(ty) }});
|
||||
if (ty != .int) return l.fail("E7005", lo.span, "a range needs an integer type", &.{.{ .name = "found", .value = l.diagnosticTyText(ty) }});
|
||||
const a = try l.expr(lo, ty);
|
||||
try l.checkTy(lo.span, a.ty, ty);
|
||||
const b = try l.expr(hi, ty);
|
||||
@@ -1244,7 +1252,7 @@ const Lowerer = struct {
|
||||
.int => |x| {
|
||||
const ty: Ty = if (parse_mod.intSuffix(x.text)) |s| .{ .int = s } else want orelse
|
||||
return l.fail("E7007", e.span, "the type of this integer literal cannot be determined; add a suffix such as `0u64` or a type annotation", &.{});
|
||||
if (ty != .int) return l.fail("E7005", e.span, "an integer literal where another type is expected", &.{.{ .name = "expected", .value = l.tyText(ty) }});
|
||||
if (ty != .int) return l.fail("E7005", e.span, "an integer literal where another type is expected", &.{.{ .name = "expected", .value = l.diagnosticTyText(ty) }});
|
||||
const v = parse_mod.parseIntText(x.text) orelse return l.fail("E7001", e.span, "malformed integer literal", &.{});
|
||||
const n = ty.int;
|
||||
const bits = intBits(n);
|
||||
@@ -1260,7 +1268,7 @@ const Lowerer = struct {
|
||||
},
|
||||
.deref => |x| {
|
||||
const r = try l.expr(x.*, null);
|
||||
const in = r.ty.inner() orelse return l.fail("E7005", e.span, "`*` reads through a borrow", &.{.{ .name = "found", .value = l.tyText(r.ty) }});
|
||||
const in = r.ty.inner() orelse return l.fail("E7005", e.span, "`*` reads through a borrow", &.{.{ .name = "found", .value = l.diagnosticTyText(r.ty) }});
|
||||
if (r.ty == .slice or r.ty == .slice_mut or in == .array) return l.fail("E7006", e.span, "read slice and array elements with `s[i]`, not `*`", &.{});
|
||||
// The verifier's code (spec 15 §1 rule 2, spec 04 §28).
|
||||
if (in == .atomic) return l.fail("E4202", e.span, "an atomic cell is read only by atomic operations: use `atomic.load(r, ordering)`", &.{});
|
||||
@@ -1310,7 +1318,7 @@ const Lowerer = struct {
|
||||
if (to != .int) return l.fail("E7005", x.ty.span, "casts convert between integer types", &.{});
|
||||
const from = l.peekType(x.e.*) orelse to;
|
||||
const v = try l.expr(x.e.*, from);
|
||||
if (v.ty != .int) return l.fail("E7005", x.e.span, "casts convert between integer types", &.{.{ .name = "found", .value = l.tyText(v.ty) }});
|
||||
if (v.ty != .int) return l.fail("E7005", x.e.span, "casts convert between integer types", &.{.{ .name = "found", .value = l.diagnosticTyText(v.ty) }});
|
||||
// `as` widens without loss, by the verifier's own rule (spec 02 §2).
|
||||
if (x.mode == .widen) {
|
||||
const a = std.meta.stringToEnum(air_module.IntType, v.ty.int).?;
|
||||
@@ -1341,7 +1349,7 @@ const Lowerer = struct {
|
||||
.or_trap => |x| return l.orTrap(e, x.*),
|
||||
.move => |n| {
|
||||
const b = l.lookup(n) orelse return l.unknown(e.span, n);
|
||||
if (!b.ty.isLinear()) return l.fail("E7006", e.span, "`move` applies to linear values; copyable values are passed plainly", &.{ .{ .name = "name", .value = n }, .{ .name = "type", .value = l.tyText(b.ty) } });
|
||||
if (!b.ty.isLinear()) return l.fail("E7006", e.span, "`move` applies to linear values; copyable values are passed plainly", &.{ .{ .name = "name", .value = n }, .{ .name = "type", .value = l.diagnosticTyText(b.ty) } });
|
||||
return .{ .name = b.value, .ty = b.ty };
|
||||
},
|
||||
}
|
||||
@@ -1434,21 +1442,21 @@ const Lowerer = struct {
|
||||
if (std.mem.eql(u8, p, "own.take")) {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "`own.take` takes one owner", &.{});
|
||||
const o = try l.consuming(args[0], null);
|
||||
if (o.ty != .own) return l.fail("E7005", args[0].span, "`own.take` takes an `own<T>`", &.{.{ .name = "found", .value = l.tyText(o.ty) }});
|
||||
if (o.ty != .own) return l.fail("E7005", args[0].span, "`own.take` takes an `own<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(o.ty) }});
|
||||
return l.def("v", o.ty.own.*, try l.fmt("own.take %{s}", .{o.name}), e.span);
|
||||
}
|
||||
if (std.mem.eql(u8, p, "own.free") or std.mem.eql(u8, p, "region.destroy")) {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "this operation takes one linear value", &.{});
|
||||
const o = try l.consuming(args[0], null);
|
||||
const ok = if (std.mem.eql(u8, p, "own.free")) (o.ty == .own or o.ty == .own_array) else o.ty == .region;
|
||||
if (!ok) return l.fail("E7005", args[0].span, if (std.mem.eql(u8, p, "own.free")) "`own.free` takes an `own<T>` or `own_array<T>`" else "`region.destroy` takes a region", &.{.{ .name = "found", .value = l.tyText(o.ty) }});
|
||||
if (!ok) return l.fail("E7005", args[0].span, if (std.mem.eql(u8, p, "own.free")) "`own.free` takes an `own<T>` or `own_array<T>`" else "`region.destroy` takes a region", &.{.{ .name = "found", .value = l.diagnosticTyText(o.ty) }});
|
||||
try l.emit(try l.fmt("{s} %{s}", .{ p, o.name }), e.span);
|
||||
return .{ .name = "", .ty = .void };
|
||||
}
|
||||
if (std.mem.eql(u8, p, "region.reset")) {
|
||||
if (args.len != 1 or args[0].kind != .name) return l.fail("E7005", e.span, "`region.reset` takes the region by name", &.{});
|
||||
const r = l.lookup(args[0].kind.name) orelse return l.unknown(args[0].span, args[0].kind.name);
|
||||
if (r.ty != .region) return l.fail("E7005", args[0].span, "`region.reset` takes a region", &.{.{ .name = "found", .value = l.tyText(r.ty) }});
|
||||
if (r.ty != .region) return l.fail("E7005", args[0].span, "`region.reset` takes a region", &.{.{ .name = "found", .value = l.diagnosticTyText(r.ty) }});
|
||||
try l.emit(try l.fmt("region.reset %{s}", .{r.value}), e.span);
|
||||
return .{ .name = "", .ty = .void };
|
||||
}
|
||||
@@ -1535,7 +1543,7 @@ const Lowerer = struct {
|
||||
try l.checkTy(fi.e.span, v.ty, ft);
|
||||
try args.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name }));
|
||||
}
|
||||
return l.def("s", t, try l.fmt("struct.make @{s}({s})", .{ name, args.items }), e.span);
|
||||
return l.def("s", t, try l.fmt("struct.make {s}({s})", .{ l.tyText(t), args.items }), e.span);
|
||||
}
|
||||
|
||||
fn variantValue(l: *Lowerer, e: ast.Expr, enum_name: []const u8, variant: []const u8, args: []const ast.Expr) Error!Value {
|
||||
@@ -1552,14 +1560,14 @@ const Lowerer = struct {
|
||||
try l.checkTy(a.span, av.ty, ty);
|
||||
try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", av.name }));
|
||||
}
|
||||
return l.def("e", t, try l.fmt("enum.make @{s}.{s}({s})", .{ enum_name, variant, names.items }), e.span);
|
||||
return l.def("e", t, try l.fmt("enum.make {s}.{s}({s})", .{ l.tyText(t), variant, names.items }), e.span);
|
||||
}
|
||||
|
||||
/// `v.f` on a struct value: `struct.get` (borrows come in layer 4).
|
||||
fn fieldValue(l: *Lowerer, e: ast.Expr, base: ast.Expr, name: []const u8) Error!Value {
|
||||
var bt = l.peekType(base) orelse return l.fail("E7007", base.span, "the type of this expression cannot be determined", &.{});
|
||||
if (bt.isBorrow()) bt = bt.inner().?;
|
||||
const d = l.decl(bt) orelse return l.fail("E7005", e.span, "field access on a value that is not a struct", &.{.{ .name = "found", .value = l.tyText(bt) }});
|
||||
const d = l.decl(bt) orelse return l.fail("E7005", e.span, "field access on a value that is not a struct", &.{.{ .name = "found", .value = l.diagnosticTyText(bt) }});
|
||||
if (d.kind != .@"struct") return l.fail("E7005", e.span, "field access on an enum; use `match`", &.{.{ .name = "type", .value = d.name }});
|
||||
const f = for (d.kind.@"struct") |x| {
|
||||
if (std.mem.eql(u8, x.name, name)) break x;
|
||||
@@ -1588,7 +1596,7 @@ const Lowerer = struct {
|
||||
const vt: Ty = if (a.value) |v| v.ty else .void;
|
||||
if (vt == .never) continue;
|
||||
if (result_ty) |prev| {
|
||||
if (!prev.eql(vt)) return l.fail("E7005", a.span, try l.fmt("the branches of this `{s}` have different types", .{what}), &.{ .{ .name = "expected", .value = l.tyText(prev) }, .{ .name = "found", .value = l.tyText(vt) } });
|
||||
if (!prev.eql(vt)) return l.fail("E7005", a.span, try l.fmt("the branches of this `{s}` have different types", .{what}), &.{ .{ .name = "expected", .value = l.diagnosticTyText(prev) }, .{ .name = "found", .value = l.diagnosticTyText(vt) } });
|
||||
} else result_ty = vt;
|
||||
};
|
||||
if (result_ty == null) {
|
||||
@@ -1633,11 +1641,12 @@ const Lowerer = struct {
|
||||
const vs = d.kind.@"enum";
|
||||
const blocks = try l.arena.alloc(usize, m.arms.len);
|
||||
var head: std.ArrayList(u8) = .empty;
|
||||
try head.appendSlice(l.arena, try l.fmt("enum.switch @{s} %{s}", .{ d.name, sv.name }));
|
||||
try head.appendSlice(l.arena, try l.fmt("enum.switch {s} %{s}", .{ l.tyText(st), sv.name }));
|
||||
for (m.arms, blocks, 0..) |arm, *blk, i| {
|
||||
if (arm.pattern.kind != .ctor or arm.pattern.kind.ctor.qualifier == null)
|
||||
return l.fail("E7006", arm.pattern.span, "an arm of a `match` over an enum names one variant as `Enum::Variant`; `_` is not allowed", &.{.{ .name = "enum", .value = d.name }});
|
||||
const c = arm.pattern.kind.ctor;
|
||||
if (std.mem.startsWith(u8, c.qualifier.?, "std.") and l.enumType(c.qualifier.?) == null) return l.unknown(arm.pattern.span, c.qualifier.?);
|
||||
if (!std.mem.eql(u8, c.qualifier.?, d.name)) return l.fail("E7005", arm.pattern.span, "variant of a different enum", &.{ .{ .name = "expected", .value = d.name }, .{ .name = "found", .value = c.qualifier.? } });
|
||||
const vi = for (vs, 0..) |v, k| {
|
||||
if (std.mem.eql(u8, v.name, c.name)) break k;
|
||||
@@ -1675,7 +1684,7 @@ const Lowerer = struct {
|
||||
return l.mergeArms(m.span, "match", ends.items, vars, before, "endmatch");
|
||||
}
|
||||
|
||||
if (st != .int) return l.fail("E7005", m.scrutinee.span, "`match` needs an enum or integer value; use `if` for booleans", &.{.{ .name = "found", .value = l.tyText(st) }});
|
||||
if (st != .int) return l.fail("E7005", m.scrutinee.span, "`match` needs an enum or integer value; use `if` for booleans", &.{.{ .name = "found", .value = l.diagnosticTyText(st) }});
|
||||
var head: std.ArrayList(u8) = .empty;
|
||||
try head.appendSlice(l.arena, try l.fmt("switch.{s} %{s}, ", .{ st.int, sv.name }));
|
||||
const blocks = try l.arena.alloc(usize, m.arms.len);
|
||||
@@ -1964,7 +1973,7 @@ const Lowerer = struct {
|
||||
.field => |f| {
|
||||
const base = try l.placeRaw(f.e.*, mutable, span);
|
||||
const st = base.v.ty.inner() orelse return l.fail("E7005", place.span, "field of a value that is not a struct", &.{});
|
||||
const d = l.decl(st) orelse return l.fail("E7005", place.span, "field of a value that is not a struct", &.{.{ .name = "found", .value = l.tyText(st) }});
|
||||
const d = l.decl(st) orelse return l.fail("E7005", place.span, "field of a value that is not a struct", &.{.{ .name = "found", .value = l.diagnosticTyText(st) }});
|
||||
if (d.kind != .@"struct") return l.fail("E7005", place.span, "field of an enum; use `match`", &.{});
|
||||
const fd = for (d.kind.@"struct") |x| {
|
||||
if (std.mem.eql(u8, x.name, f.name)) break x;
|
||||
@@ -1979,7 +1988,7 @@ const Lowerer = struct {
|
||||
const base = try l.placeRaw(x.e.*, mutable, span);
|
||||
l.unchecked = outer_unchecked;
|
||||
const bt = base.v.ty;
|
||||
const elem = elemOf(bt) orelse return l.fail("E7005", place.span, "indexing needs an array or a slice", &.{.{ .name = "found", .value = l.tyText(bt) }});
|
||||
const elem = elemOf(bt) orelse return l.fail("E7005", place.span, "indexing needs an array or a slice", &.{.{ .name = "found", .value = l.diagnosticTyText(bt) }});
|
||||
if (x.hi) |hi| {
|
||||
// `s[a..b]`: slice.sub with start a and length b - a (checked).
|
||||
var sl = base.v;
|
||||
@@ -2056,7 +2065,7 @@ const Lowerer = struct {
|
||||
else => null,
|
||||
};
|
||||
if (arr) |n| return l.def("len", .{ .int = "usize" }, try l.fmt("const.usize {d}", .{n}), e.span);
|
||||
if (bt != .slice and bt != .slice_mut) return l.fail("E7005", e.span, "`.len` needs an array or a slice", &.{.{ .name = "found", .value = l.tyText(bt) }});
|
||||
if (bt != .slice and bt != .slice_mut) return l.fail("E7005", e.span, "`.len` needs an array or a slice", &.{.{ .name = "found", .value = l.diagnosticTyText(bt) }});
|
||||
const s_ = try l.expr(base, bt);
|
||||
return l.def("len", .{ .int = "usize" }, try l.fmt("slice.len %{s}", .{s_.name}), e.span);
|
||||
}
|
||||
@@ -2070,7 +2079,7 @@ const Lowerer = struct {
|
||||
const rb = l.rootBinding(base) orelse return l.fail("E7002", base.span, "unknown name", &.{});
|
||||
const mutable = rb.ty.isMutBorrow() or rb.kind == .storage and rb.mutable;
|
||||
const p = try l.placeBorrow(base, mutable, true, s.span);
|
||||
if (p.v.ty != .slice and p.v.ty != .slice_mut) return l.fail("E7005", base.span, "`split_at` splits a slice", &.{.{ .name = "found", .value = l.tyText(p.v.ty) }});
|
||||
if (p.v.ty != .slice and p.v.ty != .slice_mut) return l.fail("E7005", base.span, "`split_at` splits a slice", &.{.{ .name = "found", .value = l.diagnosticTyText(p.v.ty) }});
|
||||
const k = try l.expr(e.kind.call.args[0], .{ .int = "usize" });
|
||||
try l.checkTy(e.kind.call.args[0].span, k.ty, .{ .int = "usize" });
|
||||
const left = try l.freshName(names[0]);
|
||||
@@ -2088,9 +2097,9 @@ const Lowerer = struct {
|
||||
var temps: std.ArrayList([]const u8) = .empty;
|
||||
const d = try l.argument(args[0], null, &temps);
|
||||
const src = try l.argument(args[1], null, &temps);
|
||||
if (d.ty != .slice_mut) return l.fail("E7005", args[0].span, "`slice.copy` writes to `mut dst` (a `slice_mut<T>`)", &.{.{ .name = "found", .value = l.tyText(d.ty) }});
|
||||
if (src.ty != .slice and src.ty != .slice_mut) return l.fail("E7005", args[1].span, "`slice.copy` reads from `ref src` (a `slice<T>`)", &.{.{ .name = "found", .value = l.tyText(src.ty) }});
|
||||
if (!d.ty.inner().?.eql(src.ty.inner().?)) return l.fail("E7005", args[1].span, "`slice.copy` copies between slices of the same element type", &.{ .{ .name = "expected", .value = l.tyText(d.ty.inner().?) }, .{ .name = "found", .value = l.tyText(src.ty.inner().?) } });
|
||||
if (d.ty != .slice_mut) return l.fail("E7005", args[0].span, "`slice.copy` writes to `mut dst` (a `slice_mut<T>`)", &.{.{ .name = "found", .value = l.diagnosticTyText(d.ty) }});
|
||||
if (src.ty != .slice and src.ty != .slice_mut) return l.fail("E7005", args[1].span, "`slice.copy` reads from `ref src` (a `slice<T>`)", &.{.{ .name = "found", .value = l.diagnosticTyText(src.ty) }});
|
||||
if (!d.ty.inner().?.eql(src.ty.inner().?)) return l.fail("E7005", args[1].span, "`slice.copy` copies between slices of the same element type", &.{ .{ .name = "expected", .value = l.diagnosticTyText(d.ty.inner().?) }, .{ .name = "found", .value = l.diagnosticTyText(src.ty.inner().?) } });
|
||||
try l.emit(try l.fmt("slice.copy %{s}, %{s}", .{ d.name, src.name }), e.span);
|
||||
try l.endNow(temps.items, e.span);
|
||||
return .{ .name = "", .ty = .void };
|
||||
@@ -2223,7 +2232,7 @@ const Lowerer = struct {
|
||||
const br = a.kind.borrow;
|
||||
if (br.mutable) return l.fail("E7005", a.span, "atomic operations take `ref` of the cell, never `mut`", &.{});
|
||||
const b = try l.bindingOf(br.place.*, "an atomic cell");
|
||||
if (b.ty != .atomic) return l.fail("E7005", a.span, "an atomic operation takes `ref` of an `atomic<T>`", &.{.{ .name = "found", .value = l.tyText(b.ty) }});
|
||||
if (b.ty != .atomic) return l.fail("E7005", a.span, "an atomic operation takes `ref` of an `atomic<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }});
|
||||
const r = try l.def(br.place.kind.name, try l.wrap(.ref, b.ty), try l.fmt("borrow.ref %{s}", .{b.value}), a.span);
|
||||
try temps.append(l.arena, r.name);
|
||||
return r;
|
||||
@@ -2231,7 +2240,7 @@ const Lowerer = struct {
|
||||
const b = try l.bindingOf(a, "an atomic cell");
|
||||
if (b.ty == .atomic) return l.fail("E7005", a.span, "pass the cell as `ref a` (or a `ref` binding of it): atomic operations go through a shared borrow", &.{.{ .name = "suggestion", .value = try l.fmt("ref {s}", .{a.kind.name}) }});
|
||||
if (b.ty == .ref and b.ty.inner().? == .atomic) return .{ .name = b.value, .ty = b.ty };
|
||||
return l.fail("E7005", a.span, "an atomic operation takes a `ref<atomic<T>>`", &.{.{ .name = "found", .value = l.tyText(b.ty) }});
|
||||
return l.fail("E7005", a.span, "an atomic operation takes a `ref<atomic<T>>`", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }});
|
||||
}
|
||||
|
||||
fn atomicCall(l: *Lowerer, e: ast.Expr, p: []const u8, args: []const ast.Expr) Error!Value {
|
||||
@@ -2239,13 +2248,13 @@ const Lowerer = struct {
|
||||
if (eq(u8, p, "atomic.new")) {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "`atomic.new` takes the initial value", &.{});
|
||||
const v = try l.expr(args[0], null);
|
||||
if (!atomicScalar(v.ty)) return l.fail("E7005", args[0].span, "atomic<T> needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.tyText(v.ty) }});
|
||||
if (!atomicScalar(v.ty)) return l.fail("E7005", args[0].span, "atomic<T> needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.diagnosticTyText(v.ty) }});
|
||||
return l.def("atomic", try l.wrap(.atomic, v.ty), try l.fmt("atomic.new %{s}", .{v.name}), e.span);
|
||||
}
|
||||
if (eq(u8, p, "atomic.take")) {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "`atomic.take` takes one cell", &.{});
|
||||
const c = try l.consuming(args[0], null);
|
||||
if (c.ty != .atomic) return l.fail("E7005", args[0].span, "`atomic.take` takes an `atomic<T>`", &.{.{ .name = "found", .value = l.tyText(c.ty) }});
|
||||
if (c.ty != .atomic) return l.fail("E7005", args[0].span, "`atomic.take` takes an `atomic<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(c.ty) }});
|
||||
return l.def("v", c.ty.inner().?, try l.fmt("atomic.take %{s}", .{c.name}), e.span);
|
||||
}
|
||||
if (eq(u8, p, "atomic.fence")) {
|
||||
@@ -2274,7 +2283,7 @@ const Lowerer = struct {
|
||||
return .{ .name = "", .ty = .void };
|
||||
}
|
||||
const op: []const u8 = if (eq(u8, p, "atomic.swap")) "xchg" else p["atomic.".len..];
|
||||
if ((eq(u8, op, "add.wrap") or eq(u8, op, "sub.wrap")) and t != .int) return l.fail("E7005", args[1].span, "`atomic.add.wrap` and `atomic.sub.wrap` need an integer cell", &.{.{ .name = "found", .value = l.tyText(t) }});
|
||||
if ((eq(u8, op, "add.wrap") or eq(u8, op, "sub.wrap")) and t != .int) return l.fail("E7005", args[1].span, "`atomic.add.wrap` and `atomic.sub.wrap` need an integer cell", &.{.{ .name = "found", .value = l.diagnosticTyText(t) }});
|
||||
const v = try l.def("old", t, try l.fmt("atomic.{s}.{s} %{s}, %{s}", .{ op, ord, c.name, operand.name }), e.span);
|
||||
try l.endNow(temps.items, e.span);
|
||||
return v;
|
||||
@@ -2320,7 +2329,7 @@ const Lowerer = struct {
|
||||
return v;
|
||||
}
|
||||
if ((b.ty == .mut or (b.ty == .ref and !mutable)) and std.meta.activeTag(b.ty.inner().?) == tag) return .{ .name = b.value, .ty = b.ty };
|
||||
return l.fail("E7005", a.span, try l.fmt("{s} is expected here", .{what}), &.{.{ .name = "found", .value = l.tyText(b.ty) }});
|
||||
return l.fail("E7005", a.span, try l.fmt("{s} is expected here", .{what}), &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }});
|
||||
}
|
||||
|
||||
/// The task and channel operations that are plain calls; null for any
|
||||
@@ -2334,7 +2343,7 @@ const Lowerer = struct {
|
||||
if (eq(p, "task.spawn")) {
|
||||
if (args.len < 2) return l.fail("E7005", e.span, "`task.spawn` takes a scope, a function and its arguments", &.{});
|
||||
const sb = try l.bindingOf(args[0], "a task scope");
|
||||
if (sb.ty != .scope) return l.fail("E7005", args[0].span, "`task.spawn` spawns into a scope: `scope s { … task.spawn(s, f, …) … }`", &.{.{ .name = "found", .value = l.tyText(sb.ty) }});
|
||||
if (sb.ty != .scope) return l.fail("E7005", args[0].span, "`task.spawn` spawns into a scope: `scope s { … task.spawn(s, f, …) … }`", &.{.{ .name = "found", .value = l.diagnosticTyText(sb.ty) }});
|
||||
const scope_name = sb.value;
|
||||
if (args[1].kind != .name) return l.fail("E7005", args[1].span, "the function to spawn is named", &.{});
|
||||
const fname = args[1].kind.name;
|
||||
@@ -2355,7 +2364,7 @@ const Lowerer = struct {
|
||||
if (eq(p, "task.join")) {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "`task.join` takes one task", &.{});
|
||||
const t = try l.consuming(args[0], null);
|
||||
if (t.ty != .task) return l.fail("E7005", args[0].span, "`task.join` takes a `task<T>`", &.{.{ .name = "found", .value = l.tyText(t.ty) }});
|
||||
if (t.ty != .task) return l.fail("E7005", args[0].span, "`task.join` takes a `task<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(t.ty) }});
|
||||
const rt = t.ty.task.*;
|
||||
if (rt == .void) {
|
||||
try l.emit(try l.fmt("task.join %{s}", .{t.name}), e.span);
|
||||
@@ -2366,7 +2375,7 @@ const Lowerer = struct {
|
||||
if (eq(p, "task.cancel")) {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "`task.cancel` takes one task, by name", &.{});
|
||||
const b = try l.bindingOf(args[0], "a task");
|
||||
if (b.ty != .task) return l.fail("E7005", args[0].span, "`task.cancel` takes a `task<T>`", &.{.{ .name = "found", .value = l.tyText(b.ty) }});
|
||||
if (b.ty != .task) return l.fail("E7005", args[0].span, "`task.cancel` takes a `task<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }});
|
||||
try l.emit(try l.fmt("task.cancel %{s}", .{b.value}), e.span);
|
||||
return .{ .name = "", .ty = .void };
|
||||
}
|
||||
@@ -2392,7 +2401,7 @@ const Lowerer = struct {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "this operation takes one graph owner", &.{});
|
||||
const o = try l.consuming(args[0], null);
|
||||
const want: std.meta.Tag(Ty) = if (eq(p, "island.freeze")) .island else .frozen;
|
||||
if (std.meta.activeTag(o.ty) != want) return l.fail("E7005", args[0].span, if (want == .island) "`island.freeze` takes an `island<T>`" else "`arc.from_frozen` takes a `frozen<T>`", &.{.{ .name = "found", .value = l.tyText(o.ty) }});
|
||||
if (std.meta.activeTag(o.ty) != want) return l.fail("E7005", args[0].span, if (want == .island) "`island.freeze` takes an `island<T>`" else "`arc.from_frozen` takes a `frozen<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(o.ty) }});
|
||||
const out = if (want == .island) try l.wrap(.frozen, o.ty.inner().?) else try l.wrap(.arc, o.ty.inner().?);
|
||||
return try l.def(if (want == .island) "frozen" else "arc", out, try l.fmt("{s} %{s}", .{ p, o.name }), e.span);
|
||||
}
|
||||
@@ -2400,7 +2409,7 @@ const Lowerer = struct {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "this operation takes one graph owner", &.{});
|
||||
const o = try l.consuming(args[0], null);
|
||||
const want: std.meta.Tag(Ty) = if (eq(p, "island.destroy")) .island else if (eq(p, "frozen.release")) .frozen else .arc;
|
||||
if (std.meta.activeTag(o.ty) != want) return l.fail("E7005", args[0].span, "this operation takes another graph owner", &.{ .{ .name = "operation", .value = p }, .{ .name = "found", .value = l.tyText(o.ty) } });
|
||||
if (std.meta.activeTag(o.ty) != want) return l.fail("E7005", args[0].span, "this operation takes another graph owner", &.{ .{ .name = "operation", .value = p }, .{ .name = "found", .value = l.diagnosticTyText(o.ty) } });
|
||||
try l.emit(try l.fmt("{s} %{s}", .{ p, o.name }), e.span);
|
||||
return .{ .name = "", .ty = .void };
|
||||
}
|
||||
@@ -2414,7 +2423,7 @@ const Lowerer = struct {
|
||||
return v;
|
||||
}
|
||||
if (b.ty == .ref and b.ty.inner().? == .arc) return try l.def("arc", b.ty.inner().?, try l.fmt("arc.clone %{s}", .{b.value}), e.span);
|
||||
return l.fail("E7005", args[0].span, "`arc.clone` takes an `arc<T>`", &.{.{ .name = "found", .value = l.tyText(b.ty) }});
|
||||
return l.fail("E7005", args[0].span, "`arc.clone` takes an `arc<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }});
|
||||
}
|
||||
if (eq(p, "island.at") or eq(p, "frozen.at") or eq(p, "arc.at"))
|
||||
return l.fail("E7006", e.span, "a graph access is a borrow: bind it with `ref x = island.at(g, r);` or `mut x = island.at(g, r);`", &.{});
|
||||
@@ -2427,13 +2436,13 @@ const Lowerer = struct {
|
||||
if (eq(p, "mutex.take")) {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "`mutex.take` takes one mutex", &.{});
|
||||
const m = try l.consuming(args[0], null);
|
||||
if (m.ty != .mutex) return l.fail("E7005", args[0].span, "`mutex.take` takes a `mutex<T>`", &.{.{ .name = "found", .value = l.tyText(m.ty) }});
|
||||
if (m.ty != .mutex) return l.fail("E7005", args[0].span, "`mutex.take` takes a `mutex<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(m.ty) }});
|
||||
return try l.def("v", m.ty.mutex.*, try l.fmt("mutex.take %{s}", .{m.name}), e.span);
|
||||
}
|
||||
if (eq(p, "channel.close_sender")) {
|
||||
if (args.len != 1) return l.fail("E7005", e.span, "`channel.close_sender` takes one sender", &.{});
|
||||
const tx = try l.consuming(args[0], null);
|
||||
if (tx.ty != .sender) return l.fail("E7005", args[0].span, "`channel.close_sender` takes a `sender<T>`", &.{.{ .name = "found", .value = l.tyText(tx.ty) }});
|
||||
if (tx.ty != .sender) return l.fail("E7005", args[0].span, "`channel.close_sender` takes a `sender<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(tx.ty) }});
|
||||
try l.emit(try l.fmt("channel.close_sender %{s}", .{tx.name}), e.span);
|
||||
return .{ .name = "", .ty = .void };
|
||||
}
|
||||
@@ -2455,8 +2464,8 @@ const Lowerer = struct {
|
||||
try temps.append(l.arena, v.name);
|
||||
break :blk v;
|
||||
},
|
||||
.ref => if (b.ty.ref.* == .mutex) .{ .name = b.value, .ty = b.ty } else return l.fail("E7005", place.span, "`lock` needs a mutex", &.{.{ .name = "found", .value = l.tyText(b.ty) }}),
|
||||
else => return l.fail("E7005", place.span, "`lock` needs a mutex", &.{.{ .name = "found", .value = l.tyText(b.ty) }}),
|
||||
.ref => if (b.ty.ref.* == .mutex) .{ .name = b.value, .ty = b.ty } else return l.fail("E7005", place.span, "`lock` needs a mutex", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}),
|
||||
else => return l.fail("E7005", place.span, "`lock` needs a mutex", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}),
|
||||
};
|
||||
const elem = mr.ty.ref.mutex.*;
|
||||
const depth = l.bindings.items.len;
|
||||
@@ -2627,7 +2636,7 @@ const Lowerer = struct {
|
||||
/// scope, task, shield or guard, at any depth. Endpoints inside are the
|
||||
/// reserved `channel_transfer`, left to the verifier (`E0006`).
|
||||
fn elementRule(l: *Lowerer, t: Ty, span: Span, what: []const u8) Error!void {
|
||||
if (try l.forbiddenIn(t, 0)) |bad| return l.fail("E7005", span, try l.fmt("{s} contains no borrow, scope, task, shield or guard", .{what}), &.{ .{ .name = "type", .value = l.tyText(t) }, .{ .name = "found", .value = l.tyText(bad) } });
|
||||
if (try l.forbiddenIn(t, 0)) |bad| return l.fail("E7005", span, try l.fmt("{s} contains no borrow, scope, task, shield or guard", .{what}), &.{ .{ .name = "type", .value = l.diagnosticTyText(t) }, .{ .name = "found", .value = l.diagnosticTyText(bad) } });
|
||||
}
|
||||
|
||||
fn forbiddenIn(l: *Lowerer, t: Ty, depth: u32) Error!?Ty {
|
||||
@@ -2657,7 +2666,7 @@ const Lowerer = struct {
|
||||
const tag = std.meta.stringToEnum(std.meta.Tag(Ty), owner).?;
|
||||
if (std.meta.activeTag(b.ty) == tag) return l.fail("E7005", a.span, try l.fmt("this takes a borrow of the {s}, not the owner: bind `{s} g = {s};` in an enclosing block and pass `g`", .{ owner, if (mutable) "mut" else "ref", a.kind.name }), &.{.{ .name = "name", .value = a.kind.name }});
|
||||
const ok = (b.ty == .ref or (b.ty == .mut and !mutable) or (b.ty == .mut and mutable)) and std.meta.activeTag(b.ty.inner().?) == tag;
|
||||
if (!ok or (mutable and b.ty != .mut)) return l.fail("E7005", a.span, try l.fmt("a {s} borrow of an `{s}<T>` is expected here", .{ if (mutable) "`mut`" else "`ref` or `mut`", owner }), &.{.{ .name = "found", .value = l.tyText(b.ty) }});
|
||||
if (!ok or (mutable and b.ty != .mut)) return l.fail("E7005", a.span, try l.fmt("a {s} borrow of an `{s}<T>` is expected here", .{ if (mutable) "`mut`" else "`ref` or `mut`", owner }), &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }});
|
||||
return .{ .name = b.value, .ty = b.ty };
|
||||
}
|
||||
|
||||
@@ -2671,7 +2680,7 @@ const Lowerer = struct {
|
||||
if (ac.args.len != 2) return l.fail("E7005", place.span, "`.at` takes the graph's borrow binding and an `iref`", &.{});
|
||||
const g = try l.graphBorrow(ac.args[0], owner, mutable);
|
||||
const r = try l.expr(ac.args[1], null);
|
||||
if (r.ty != .iref) return l.fail("E7005", ac.args[1].span, "an `iref` is expected here", &.{.{ .name = "found", .value = l.tyText(r.ty) }});
|
||||
if (r.ty != .iref) return l.fail("E7005", ac.args[1].span, "an `iref` is expected here", &.{.{ .name = "found", .value = l.diagnosticTyText(r.ty) }});
|
||||
const op = if (std.mem.eql(u8, owner, "island")) "island.borrow" else if (std.mem.eql(u8, owner, "frozen")) "frozen.borrow" else "arc.borrow";
|
||||
const target = r.ty.inner().?;
|
||||
const v = try l.def(name, if (mutable) try l.wrap(.mut, target) else try l.wrap(.ref, target), try l.fmt("{s} %{s}, %{s}", .{ op, g.name, r.name }), s.span);
|
||||
@@ -2701,14 +2710,14 @@ const Lowerer = struct {
|
||||
const want: Ty = if (o == .bytes) try l.wrap(.slice, .{ .int = "u8" }) else try l.wrap(.slice_mut, .{ .int = "u8" });
|
||||
if (o == .buffer and a.kind == .bytes) return l.fail("E7005", a.span, "this operand is a buffer the operation writes: pass `mut buf`", &.{});
|
||||
const v = try l.argument(a, want, temps);
|
||||
if (!v.ty.eql(want)) return l.fail("E7005", a.span, if (o == .bytes) "bytes are passed as a borrow: `ref buf`, `ref buf[a..b]` or a byte string `b\"…\"`" else "a buffer is passed as `mut buf` or `mut buf[a..b]`", &.{ .{ .name = "expected", .value = l.tyText(want) }, .{ .name = "found", .value = l.tyText(v.ty) } });
|
||||
if (!v.ty.eql(want)) return l.fail("E7005", a.span, if (o == .bytes) "bytes are passed as a borrow: `ref buf`, `ref buf[a..b]` or a byte string `b\"…\"`" else "a buffer is passed as `mut buf` or `mut buf[a..b]`", &.{ .{ .name = "expected", .value = l.diagnosticTyText(want) }, .{ .name = "found", .value = l.diagnosticTyText(v.ty) } });
|
||||
break :blk v;
|
||||
},
|
||||
.borrowed => |rs| try l.resourceOperand(a, rs, temps),
|
||||
.consumed => |rs| blk: {
|
||||
const v = try l.consuming(a, null);
|
||||
if (v.ty != .resource or std.mem.indexOfScalar(authority.Resource, rs, v.ty.resource) == null)
|
||||
return l.fail("E7005", a.span, "this operation consumes a resource of another type", &.{ .{ .name = "operation", .value = x.name }, .{ .name = "found", .value = l.tyText(v.ty) } });
|
||||
return l.fail("E7005", a.span, "this operation consumes a resource of another type", &.{ .{ .name = "operation", .value = x.name }, .{ .name = "found", .value = l.diagnosticTyText(v.ty) } });
|
||||
break :blk v;
|
||||
},
|
||||
};
|
||||
@@ -2730,7 +2739,7 @@ const Lowerer = struct {
|
||||
else => null,
|
||||
};
|
||||
if (r == null or std.mem.indexOfScalar(authority.Resource, rs, r.?) == null)
|
||||
return l.fail("E7005", a.span, "this operation needs a resource of another type", &.{ .{ .name = "expected", .value = expected }, .{ .name = "found", .value = l.tyText(b.ty) } });
|
||||
return l.fail("E7005", a.span, "this operation needs a resource of another type", &.{ .{ .name = "expected", .value = expected }, .{ .name = "found", .value = l.diagnosticTyText(b.ty) } });
|
||||
if (b.ty == .mut) return .{ .name = b.value, .ty = b.ty };
|
||||
const v = try l.def(a.kind.name, try l.wrap(.mut, b.ty), try l.fmt("borrow.mut %{s}", .{b.value}), a.span);
|
||||
try temps.append(l.arena, v.name);
|
||||
@@ -2745,7 +2754,7 @@ const Lowerer = struct {
|
||||
|
||||
fn expectCap(l: *Lowerer, a: ast.Expr, kind: []const u8) Error!Value {
|
||||
const c = try l.expr(a, null);
|
||||
if (c.ty != .cap) return l.fail("E7005", a.span, "a capability is expected here", &.{ .{ .name = "expected", .value = try l.fmt("cap<{s}>", .{kind}) }, .{ .name = "found", .value = l.tyText(c.ty) } });
|
||||
if (c.ty != .cap) return l.fail("E7005", a.span, "a capability is expected here", &.{ .{ .name = "expected", .value = try l.fmt("cap<{s}>", .{kind}) }, .{ .name = "found", .value = l.diagnosticTyText(c.ty) } });
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -2838,7 +2847,7 @@ const Lowerer = struct {
|
||||
if (std.mem.eql(u8, path, "task.join_cancel")) {
|
||||
try want(l, e.span, args, 1, path);
|
||||
const t = try l.consuming(args[0], null);
|
||||
if (t.ty != .task) return l.fail("E7005", args[0].span, "`task.join_cancel` takes a `task<T>`", &.{.{ .name = "found", .value = l.tyText(t.ty) }});
|
||||
if (t.ty != .task) return l.fail("E7005", args[0].span, "`task.join_cancel` takes a `task<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(t.ty) }});
|
||||
const rt = t.ty.task.*;
|
||||
const ok: []const Ty = if (rt == .void) &.{} else &.{rt};
|
||||
return .{ .text = try l.fmt("task.join.cancel %{s}", .{t.name}), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = ok }, .{ .role = "cancelled", .params = &.{t.ty} } }) };
|
||||
@@ -2872,23 +2881,23 @@ const Lowerer = struct {
|
||||
if (std.mem.eql(u8, path, "channel.close_receiver")) {
|
||||
try want(l, e.span, args, 1, path);
|
||||
const rx = try l.consuming(args[0], null);
|
||||
if (rx.ty != .receiver) return l.fail("E7005", args[0].span, "`channel.close_receiver` takes a `receiver<T>`", &.{.{ .name = "found", .value = l.tyText(rx.ty) }});
|
||||
if (rx.ty != .receiver) return l.fail("E7005", args[0].span, "`channel.close_receiver` takes a `receiver<T>`", &.{.{ .name = "found", .value = l.diagnosticTyText(rx.ty) }});
|
||||
return .{ .text = try l.fmt("channel.close_receiver %{s}", .{rx.name}), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{} }, .{ .role = "pending", .params = &.{rx.ty} } }) };
|
||||
}
|
||||
if (std.mem.eql(u8, path, "cap.narrow.prefix")) {
|
||||
try want(l, e.span, args, 2, path);
|
||||
const c = try l.expr(args[0], null);
|
||||
if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.tyText(c.ty) }});
|
||||
if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.diagnosticTyText(c.ty) }});
|
||||
var temps: std.ArrayList([]const u8) = .empty;
|
||||
const bytes = try l.wrap(.slice, .{ .int = "u8" });
|
||||
const p = try l.argument(args[1], bytes, &temps);
|
||||
if (!p.ty.eql(bytes)) return l.fail("E7005", args[1].span, "the path is a byte string or a `ref` borrow of bytes", &.{.{ .name = "found", .value = l.tyText(p.ty) }});
|
||||
if (!p.ty.eql(bytes)) return l.fail("E7005", args[1].span, "the path is a byte string or a `ref` borrow of bytes", &.{.{ .name = "found", .value = l.diagnosticTyText(p.ty) }});
|
||||
return .{ .text = try l.fmt("cap.narrow.prefix %{s}, %{s}", .{ c.name, p.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{c.ty} }, .{ .role = "err", .params = &.{.{ .builtin = .cap_error }} } }), .temps = temps.items };
|
||||
}
|
||||
if (std.mem.eql(u8, path, "cap.narrow.budget")) {
|
||||
try want(l, e.span, args, 2, path);
|
||||
const c = try l.expr(args[0], null);
|
||||
if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.tyText(c.ty) }});
|
||||
if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.diagnosticTyText(c.ty) }});
|
||||
const n = try l.expr(args[1], usize_ty);
|
||||
try l.checkTy(args[1].span, n.ty, usize_ty);
|
||||
return .{ .text = try l.fmt("cap.narrow.budget %{s}, %{s}", .{ c.name, n.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{c.ty} }, .{ .role = "err", .params = &.{.{ .builtin = .cap_error }} } }) };
|
||||
|
||||
Reference in new issue
Block a user