summaryrefslogtreecommitdiff
path: root/src/walk.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 03:51:15 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit79a1e816ceb13ef81b712007716c8add2de75434 (patch)
tree1714b1bf19da3a58be2623ffe29e3f8be1b21fe3 /src/walk.zig
parenta22b579ad2df8d1811f0e194fa1bbc06e2282cf8 (diff)
parentf1af015f01e4e8d42f6224c4d4063f3aea218f5a (diff)
downloadpardes-79a1e816ceb13ef81b712007716c8add2de75434.tar.gz
pardes-79a1e816ceb13ef81b712007716c8add2de75434.zip
integration: the terminal a module of its own, with the plumber whole and the walker's cheaper compile
A merge of term-phase1a and pardes-next, no conflicts. core-test (the core with no terminal) 411 passed, 535 skipped of 946; shell-test (the same tests, the terminal compiled in) 989/989, on tui. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/walk.zig')
-rw-r--r--src/walk.zig1026
1 files changed, 530 insertions, 496 deletions
diff --git a/src/walk.zig b/src/walk.zig
index 3641d327..0f181cfa 100644
--- a/src/walk.zig
+++ b/src/walk.zig
@@ -367,7 +367,7 @@ pub fn shape(comptime types: []const type) []const u8 {
comptime {
@setEvalBranchQuota(10_000_000);
var out: []const u8 = "";
- for (types) |T| out = out ++ shapeOf(T, 0) ++ "\n";
+ for (types) |T| out = out ++ (shapeOf(T, 0) ++ "\n");
return out;
}
}
@@ -378,15 +378,15 @@ fn shapeOf(comptime T: type, comptime depth: u8) []const u8 {
return switch (@typeInfo(T)) {
.void, .null, .undefined => "v",
.bool => "b",
- .int => |i| std.fmt.comptimePrint("{t}{d}", .{ i.signedness, i.bits }),
- .float => |f| std.fmt.comptimePrint("f{d}", .{f.bits}),
+ .int => |i| @tagName(i.signedness) ++ decimal(i.bits),
+ .float => |f| "f" ++ decimal(f.bits),
.@"enum" => |e| blk: {
var out: []const u8 = shapeOf(e.tag_type, depth + 1) ++ "{";
- for (e.field_names, e.field_values) |n, v| out = out ++ std.fmt.comptimePrint("{s}={d},", .{ n, v });
+ for (e.field_names, e.field_values) |n, v| out = out ++ (n ++ "=" ++ decimal(v) ++ ",");
break :blk out ++ "}";
},
.optional => |o| if (machinery(o.child)) "0" else "?" ++ shapeOf(o.child, depth + 1),
- .array => |a| std.fmt.comptimePrint("[{d}]", .{a.len}) ++ shapeOf(a.child, depth + 1),
+ .array => |a| "[" ++ decimal(a.len) ++ "]" ++ shapeOf(a.child, depth + 1),
.pointer => |p| switch (p.size) {
.one => shapeOf(p.child, depth + 1),
.slice => "[]" ++ shapeOf(p.child, depth + 1),
@@ -397,13 +397,13 @@ fn shapeOf(comptime T: type, comptime depth: u8) []const u8 {
var out: []const u8 = if (s.layout == .@"packed") "p{" else "{";
for (s.field_names, s.field_types, s.field_attrs) |name, F, attr| {
if (attr.@"comptime" or excluded(T, name)) continue;
- out = out ++ name ++ ":" ++ shapeOf(F, depth + 1) ++ ",";
+ out = out ++ (name ++ ":" ++ shapeOf(F, depth + 1) ++ ",");
}
break :blk out ++ "}";
},
.@"union" => |u| blk: {
var out: []const u8 = shapeOf(u.tag_type.?, depth + 1) ++ "(";
- for (u.field_names, u.field_types) |name, F| out = out ++ name ++ ":" ++ shapeOf(F, depth + 1) ++ ",";
+ for (u.field_names, u.field_types) |name, F| out = out ++ (name ++ ":" ++ shapeOf(F, depth + 1) ++ ",");
break :blk out ++ ")";
},
.error_set => "error",
@@ -413,6 +413,15 @@ fn shapeOf(comptime T: type, comptime depth: u8) []const u8 {
}
}
+/// `n` in decimal, as `{d}` writes it: memoized, where comptimePrint (an
+/// inline function) formats again at every call, 5e6 of the compiler's
+/// instructions each.
+fn decimal(comptime n: comptime_int) []const u8 {
+ if (n < 0) return "-" ++ decimal(-n);
+ if (n < 10) return &.{'0' + n};
+ return decimal(n / 10) ++ &[_]u8{'0' + n % 10};
+}
+
/// An error by its name. An `anyerror` must be one `decode` can read back
/// (`errorNamed`): a Debug build stops at one that is not, as it is taped.
fn encodeError(comptime E: type, err: E, w: *std.Io.Writer) std.Io.Writer.Error!void {
@@ -1006,540 +1015,555 @@ const SrcType = struct {
};
const SrcField = struct { name: []const u8, ty: u32 = 0, value: i128 = 0 };
-/// Reads a dump of `roots`, one `into` or `get` each in order.
+/// Reads a dump of `roots`, one `into` or `get` each in order: a `Loader`
+/// told this build's table of them.
pub fn Load(comptime roots: []const type) type {
return struct {
- const Self = @This();
- const types = graph(roots);
+ pub fn init(gpa: std.mem.Allocator, bytes: []const u8) DecodeError!Loader {
+ return Loader.init(gpa, bytes, tableOf(graph(roots)));
+ }
+ };
+}
- /// Where what is read is made (a `replica.alloc` field's own
- /// allocator while it is read).
- gpa: std.mem.Allocator,
- /// The loader's own lists'.
- own: std.mem.Allocator,
- bytes: []const u8,
- at: usize = 0,
- arena: std.heap.ArenaAllocator,
- src: []SrcType = &.{},
- /// Its table is this build's: no name is asked.
- same: bool = false,
- /// Each pointer and slice made so far: what a reference finds, and
- /// what `rollback` frees.
- shared: std.ArrayList(Made) = .empty,
- /// What a type's `dumpRead` made, freed by its `dumpFree` too.
- customs: std.ArrayList(struct { ptr: *anyopaque, gpa: std.mem.Allocator, free: *const fn (*anyopaque, std.mem.Allocator) void }) = .empty,
- /// What was let go, for the person whose session it is.
- notes: std.ArrayList(u8) = .empty,
- /// The field being read, for a note.
- field: []const u8 = "",
- /// Where a field's annotation (`replica.alloc`) says its values are
- /// made instead of `gpa`.
- allocs: Allocators = .{},
+/// `Load`'s reader, one for every root set: it reads by the dump's own
+/// table, and this build's (`table`) only says whether the two are one.
+pub const Loader = struct {
+ const Self = @This();
- pub fn init(gpa: std.mem.Allocator, bytes: []const u8) DecodeError!Self {
- var l: Self = .{ .gpa = gpa, .own = gpa, .bytes = bytes, .arena = .init(gpa) };
- errdefer l.arena.deinit();
- if (!std.mem.startsWith(u8, bytes, dump_magic)) return error.BadDump;
- l.at = dump_magic.len;
- const table_at = l.at;
- try l.readTable();
- l.same = std.mem.eql(u8, tableOf(types), bytes[table_at..l.at]);
- return l;
- }
+ /// Where what is read is made (a `replica.alloc` field's own
+ /// allocator while it is read).
+ gpa: std.mem.Allocator,
+ /// The loader's own lists'.
+ own: std.mem.Allocator,
+ bytes: []const u8,
+ at: usize = 0,
+ arena: std.heap.ArenaAllocator,
+ src: []SrcType = &.{},
+ /// Its table is this build's: no name is asked.
+ same: bool = false,
+ /// Each pointer and slice made so far: what a reference finds, and
+ /// what `rollback` frees.
+ shared: std.ArrayList(Made) = .empty,
+ /// What a type's `dumpRead` made, freed by its `dumpFree` too.
+ customs: std.ArrayList(struct { ptr: *anyopaque, gpa: std.mem.Allocator, free: *const fn (*anyopaque, std.mem.Allocator) void }) = .empty,
+ /// What was let go, for the person whose session it is.
+ notes: std.ArrayList(u8) = .empty,
+ /// The field being read, for a note.
+ field: []const u8 = "",
+ /// Where a field's annotation (`replica.alloc`) says its values are
+ /// made instead of `gpa`.
+ allocs: Allocators = .{},
- pub fn deinit(l: *Self) void {
- l.shared.deinit(l.own);
- l.customs.deinit(l.own);
- l.notes.deinit(l.own);
- l.arena.deinit();
- }
+ pub fn init(gpa: std.mem.Allocator, bytes: []const u8, table: []const u8) DecodeError!Self {
+ var l: Self = .{ .gpa = gpa, .own = gpa, .bytes = bytes, .arena = .init(gpa) };
+ errdefer l.arena.deinit();
+ if (!std.mem.startsWith(u8, bytes, dump_magic)) return error.BadDump;
+ l.at = dump_magic.len;
+ const table_at = l.at;
+ try l.readTable();
+ l.same = std.mem.eql(u8, table, bytes[table_at..l.at]);
+ return l;
+ }
- /// Everything read so far freed: a load that fails leaves nothing.
- /// What it was read into must not be used after (nor freed).
- pub fn rollback(l: *Self) void {
- for (l.customs.items) |c| c.free(c.ptr, c.gpa);
- for (l.shared.items) |m| if (m.bytes.len > 0) m.gpa.rawFree(m.bytes, m.alignment, @returnAddress());
- l.customs.clearRetainingCapacity();
- l.shared.clearRetainingCapacity();
- }
+ pub fn deinit(l: *Self) void {
+ l.shared.deinit(l.own);
+ l.customs.deinit(l.own);
+ l.notes.deinit(l.own);
+ l.arena.deinit();
+ }
- fn made(l: *Self, bytes: []u8, alignment: std.mem.Alignment) DecodeError!usize {
- try l.shared.append(l.own, .{ .bytes = bytes, .alignment = alignment, .gpa = l.gpa });
- return l.shared.items.len - 1;
- }
+ /// Everything read so far freed: a load that fails leaves nothing.
+ /// What it was read into must not be used after (nor freed).
+ pub fn rollback(l: *Self) void {
+ for (l.customs.items) |c| c.free(c.ptr, c.gpa);
+ for (l.shared.items) |m| if (m.bytes.len > 0) m.gpa.rawFree(m.bytes, m.alignment, @returnAddress());
+ l.customs.clearRetainingCapacity();
+ l.shared.clearRetainingCapacity();
+ }
- fn take(l: *Self, n: usize) DecodeError![]const u8 {
- if (l.bytes.len - l.at < n) return error.EndOfDump;
- defer l.at += n;
- return l.bytes[l.at..][0..n];
- }
+ fn made(l: *Self, bytes: []u8, alignment: std.mem.Alignment) DecodeError!usize {
+ try l.shared.append(l.own, .{ .bytes = bytes, .alignment = alignment, .gpa = l.gpa });
+ return l.shared.items.len - 1;
+ }
- fn scalar(l: *Self, comptime T: type) DecodeError!T {
- return std.mem.bytesToValue(T, try l.take(@sizeOf(T)));
- }
+ fn take(l: *Self, n: usize) DecodeError![]const u8 {
+ if (l.bytes.len - l.at < n) return error.EndOfDump;
+ defer l.at += n;
+ return l.bytes[l.at..][0..n];
+ }
- /// A count, as this machine counts (a wasm32 one has 32 bits).
- fn count(l: *Self) DecodeError!usize {
- return countOf(try l.scalar(u64));
- }
+ fn scalar(l: *Self, comptime T: type) DecodeError!T {
+ return std.mem.bytesToValue(T, try l.take(@sizeOf(T)));
+ }
- fn name(l: *Self) DecodeError![]const u8 {
- return l.take(try l.scalar(u16));
- }
+ /// A count, as this machine counts (a wasm32 one has 32 bits).
+ fn count(l: *Self) DecodeError!usize {
+ return countOf(try l.scalar(u64));
+ }
- fn readTable(l: *Self) DecodeError!void {
- const a = l.arena.allocator();
- const n = try l.scalar(u32);
- if (n > l.bytes.len) return error.BadDump;
- l.src = try a.alloc(SrcType, n);
- for (l.src) |*t| {
- const k = std.enums.fromInt(Kind, (try l.take(1))[0]) orelse return error.BadDump;
- t.* = .{ .kind = k };
- switch (k) {
- .int => {
- t.signed = (try l.take(1))[0] != 0;
- t.bits = try l.scalar(u16);
- },
- .float => t.bits = try l.scalar(u16),
- .@"enum" => {
- t.signed = (try l.take(1))[0] != 0;
- t.bits = try l.scalar(u16);
- const list = try a.alloc(SrcField, try l.scalar(u32));
- for (list) |*f| f.* = .{ .name = try l.name(), .value = try l.scalar(i128) };
- t.fields = list;
- },
- .array => {
- t.len = try l.scalar(u64);
- t.child = try l.scalar(u32);
- },
- .optional, .one, .slice, .prefix, .error_union => t.child = try l.scalar(u32),
- .@"struct", .@"union" => {
- const nfields = try l.scalar(u32);
- if (nfields > l.bytes.len) return error.BadDump;
- const list = try a.alloc(SrcField, nfields);
- for (list) |*f| f.* = .{ .name = try l.name(), .ty = try l.scalar(u32) };
- t.fields = list;
- },
- .custom => _ = try l.name(),
- .skip, .void, .bool, .err, .bitset => {},
- }
- }
- for (l.src) |t| {
- if (t.child >= n) return error.BadDump;
- for (t.fields) |f| if (f.ty >= n) return error.BadDump;
+ fn name(l: *Self) DecodeError![]const u8 {
+ return l.take(try l.scalar(u16));
+ }
+
+ fn readTable(l: *Self) DecodeError!void {
+ const a = l.arena.allocator();
+ const n = try l.scalar(u32);
+ if (n > l.bytes.len) return error.BadDump;
+ l.src = try a.alloc(SrcType, n);
+ for (l.src) |*t| {
+ const k = std.enums.fromInt(Kind, (try l.take(1))[0]) orelse return error.BadDump;
+ t.* = .{ .kind = k };
+ switch (k) {
+ .int => {
+ t.signed = (try l.take(1))[0] != 0;
+ t.bits = try l.scalar(u16);
+ },
+ .float => t.bits = try l.scalar(u16),
+ .@"enum" => {
+ t.signed = (try l.take(1))[0] != 0;
+ t.bits = try l.scalar(u16);
+ const list = try a.alloc(SrcField, try l.scalar(u32));
+ for (list) |*f| f.* = .{ .name = try l.name(), .value = try l.scalar(i128) };
+ t.fields = list;
+ },
+ .array => {
+ t.len = try l.scalar(u64);
+ t.child = try l.scalar(u32);
+ },
+ .optional, .one, .slice, .prefix, .error_union => t.child = try l.scalar(u32),
+ .@"struct", .@"union" => {
+ const nfields = try l.scalar(u32);
+ if (nfields > l.bytes.len) return error.BadDump;
+ const list = try a.alloc(SrcField, nfields);
+ for (list) |*f| f.* = .{ .name = try l.name(), .ty = try l.scalar(u32) };
+ t.fields = list;
+ },
+ .custom => _ = try l.name(),
+ .skip, .void, .bool, .err, .bitset => {},
}
}
-
- pub fn note(l: *Self, comptime fmt: []const u8, args: anytype) void {
- if (l.notes.items.len > 4096) return;
- l.notes.print(l.own, fmt ++ "\n", args) catch {};
+ for (l.src) |t| {
+ if (t.child >= n) return error.BadDump;
+ for (t.fields) |f| if (f.ty >= n) return error.BadDump;
}
+ }
- fn root(l: *Self) DecodeError!u32 {
- const ty = try l.scalar(u32);
- if (ty >= l.src.len) return error.BadDump;
- return ty;
- }
+ pub fn note(l: *Self, comptime fmt: []const u8, args: anytype) void {
+ if (l.notes.items.len > 4096) return;
+ l.notes.print(l.own, fmt ++ "\n", args) catch {};
+ }
- /// The next root, made: what it points at is `gpa`'s.
- pub fn get(l: *Self, comptime T: type) DecodeError!T {
- var out: T = undefined;
- try l.fresh(T, &out);
- try l.value(T, try l.root(), &out);
- return out;
- }
+ /// A note on a type's field, its names given as run-time strings:
+ /// one instance of `note` (and of std's `print`) a message, where
+ /// a tuple of the comptime names made one a type, field and message.
+ fn noteField(l: *Self, comptime what: []const u8, type_name: []const u8, field: []const u8) void {
+ l.note("{s}.{s}: " ++ what, .{ type_name, field });
+ }
- /// The next root read into `out` as it stands: a field the dump
- /// holds is replaced (what it held is not freed), every other one
- /// is left as it is. A field another build cannot give is left too,
- /// and noted.
- pub fn into(l: *Self, comptime T: type, out: *T) DecodeError!void {
- const ty = try l.root();
- const s = l.src[ty];
- if (s.kind != .@"struct") return error.BadDump;
- try l.fields(T, s, out, true);
- }
+ fn root(l: *Self) DecodeError!u32 {
+ const ty = try l.scalar(u32);
+ if (ty >= l.src.len) return error.BadDump;
+ return ty;
+ }
- fn fresh(l: *Self, comptime T: type, out: *T) DecodeError!void {
- freshOf(T, out, l.gpa);
- }
+ /// The next root, made: what it points at is `gpa`'s.
+ pub fn get(l: *Self, comptime T: type) DecodeError!T {
+ var out: T = undefined;
+ try l.fresh(T, &out);
+ try l.value(T, try l.root(), &out);
+ return out;
+ }
- /// Whether the source's `ty` and `T` are of one kind, else the
- /// source's value passed over.
- fn kindMatches(l: *Self, comptime T: type, ty: u32) DecodeError!bool {
- if (l.same) return true;
- const want = comptime kindOf(Canon(T));
- const got = l.src[ty].kind;
- if (got == want) return true;
- // A field that came to hold a count and so many, or stopped.
- if ((want == .array and got == .prefix) or (want == .prefix and got == .array)) return true;
- try l.skip(ty);
- return false;
- }
+ /// The next root read into `out` as it stands: a field the dump
+ /// holds is replaced (what it held is not freed), every other one
+ /// is left as it is. A field another build cannot give is left too,
+ /// and noted.
+ pub fn into(l: *Self, comptime T: type, out: *T) DecodeError!void {
+ const ty = try l.root();
+ const s = l.src[ty];
+ if (s.kind != .@"struct") return error.BadDump;
+ try l.fields(T, s, out, true);
+ }
- fn readInt(l: *Self, comptime I: type, s: SrcType) DecodeError!I {
- if (l.same) {
- const info = @typeInfo(I).int;
- const W = @Int(info.signedness, intBytes(info.bits) * 8);
- return @intCast(try l.scalar(W));
- }
- const n = intBytes(s.bits);
- const raw = try l.take(n);
- var wide: u128 = 0;
- for (raw, 0..) |b, i| wide |= @as(u128, b) << @intCast(i * 8);
- if (s.signed and n > 0) {
- const shift: u7 = @intCast(128 - n * 8);
- const signed: i128 = @as(i128, @bitCast(wide << shift)) >> shift;
- return std.math.cast(I, signed) orelse error.Incompatible;
- }
- return std.math.cast(I, wide) orelse error.Incompatible;
+ fn fresh(l: *Self, comptime T: type, out: *T) DecodeError!void {
+ freshOf(T, out, l.gpa);
+ }
+
+ /// Whether the source's `ty` and `T` are of one kind, else the
+ /// source's value passed over.
+ fn kindMatches(l: *Self, comptime T: type, ty: u32) DecodeError!bool {
+ if (l.same) return true;
+ const want = comptime kindOf(Canon(T));
+ const got = l.src[ty].kind;
+ if (got == want) return true;
+ // A field that came to hold a count and so many, or stopped.
+ if ((want == .array and got == .prefix) or (want == .prefix and got == .array)) return true;
+ try l.skip(ty);
+ return false;
+ }
+
+ fn readInt(l: *Self, comptime I: type, s: SrcType) DecodeError!I {
+ if (l.same) {
+ const info = @typeInfo(I).int;
+ const W = @Int(info.signedness, intBytes(info.bits) * 8);
+ return @intCast(try l.scalar(W));
+ }
+ const n = intBytes(s.bits);
+ const raw = try l.take(n);
+ var wide: u128 = 0;
+ for (raw, 0..) |b, i| wide |= @as(u128, b) << @intCast(i * 8);
+ if (s.signed and n > 0) {
+ const shift: u7 = @intCast(128 - n * 8);
+ const signed: i128 = @as(i128, @bitCast(wide << shift)) >> shift;
+ return std.math.cast(I, signed) orelse error.Incompatible;
}
+ return std.math.cast(I, wide) orelse error.Incompatible;
+ }
- /// `T` read from the source's type `ty` into `out`, which `fresh`
- /// has made ready.
- fn value(l: *Self, comptime T: type, ty: u32, out: *T) DecodeError!void {
- if (comptime isAtomic(T)) {
- const R = @FieldType(T, "raw");
- var raw: R = undefined;
- try l.fresh(R, &raw);
- try l.value(R, ty, &raw);
- out.* = .{ .raw = raw };
- return;
- }
- // A field this build compiles out (a void field): passed over,
- // said only when it held something.
- if (comptime kindOf(Canon(T)) == .void) if (!l.same and l.src[ty].kind != .void) {
- const held = l.src[ty].kind != .optional or (l.at < l.bytes.len and l.bytes[l.at] != 0);
- try l.skip(ty);
- if (held) l.note("{s}: not in this build", .{l.field});
- return;
- };
- if (!try l.kindMatches(T, ty)) return error.Incompatible;
- const s = l.src[ty];
- if (comptime isList(T)) {
- const E = @typeInfo(@FieldType(T, "items")).pointer.child;
- const got = try l.slice(E, s);
- out.* = .empty;
- out.items = got;
- out.capacity = got.len;
- return;
- }
- switch (comptime kindOf(T)) {
- .skip, .void => {},
- .bool => out.* = (try l.take(1))[0] != 0,
- .int => out.* = try l.readInt(T, s),
- .float => out.* = if (l.same or s.bits == @typeInfo(T).float.bits) try l.scalar(T) else return error.Incompatible,
- .@"enum" => {
- const e = @typeInfo(T).@"enum";
- if (l.same) {
- out.* = @fromBackingInt(@intCast(try l.readInt(e.tag_type, s)));
- return;
- }
- const n = try l.readInt(i128, s);
- const was = for (s.fields) |f| {
- if (f.value == n) break f.name;
- } else null;
- if (was) |w| inline for (e.field_names) |field| if (std.mem.eql(u8, w, field)) {
- out.* = @field(T, field);
- return;
- };
- if (e.mode == .nonexhaustive and was == null)
- if (std.math.cast(e.tag_type, n)) |tag| {
- out.* = @fromBackingInt(@intCast(tag));
- return;
- };
- l.note("{s}: no {s} here", .{ l.field, was orelse "such value" });
- return error.Incompatible;
- },
- .optional => {
- const C = @typeInfo(T).optional.child;
- if ((try l.take(1))[0] == 0) {
- out.* = null;
- return;
- }
- if (comptime kindOf(Canon(C)) == .skip) {
- out.* = if (comptime C == std.mem.Allocator) l.gpa else null;
- return;
- }
- // A slice's or a pointer's null is its address: set to
- // an undefined payload, the optional itself is undefined,
- // and ReleaseSafe's optimizer read it as null (a pane's
- // `?[]u8` command one byte long, every field after it out
- // of step). Read through a local and set it from that.
- if (comptime @typeInfo(C) == .pointer) {
- var payload: C = undefined;
- try l.value(C, s.child, &payload);
- out.* = payload;
- return;
- }
- out.* = @as(C, undefined);
- try l.fresh(C, &out.*.?);
- l.value(C, s.child, &out.*.?) catch |err| {
- out.* = null;
- return err;
- };
- },
- .one => {
- const C = @typeInfo(T).pointer.child;
- if (try l.ref()) |again| {
- out.* = @ptrCast(@alignCast(again.ptr));
+ /// `T` read from the source's type `ty` into `out`, which `fresh`
+ /// has made ready.
+ fn value(l: *Self, comptime T: type, ty: u32, out: *T) DecodeError!void {
+ if (comptime isAtomic(T)) {
+ const R = @FieldType(T, "raw");
+ var raw: R = undefined;
+ try l.fresh(R, &raw);
+ try l.value(R, ty, &raw);
+ out.* = .{ .raw = raw };
+ return;
+ }
+ // A field this build compiles out (a void field): passed over,
+ // said only when it held something.
+ if (comptime kindOf(Canon(T)) == .void) if (!l.same and l.src[ty].kind != .void) {
+ const held = l.src[ty].kind != .optional or (l.at < l.bytes.len and l.bytes[l.at] != 0);
+ try l.skip(ty);
+ if (held) l.note("{s}: not in this build", .{l.field});
+ return;
+ };
+ if (!try l.kindMatches(T, ty)) return error.Incompatible;
+ const s = l.src[ty];
+ if (comptime isList(T)) {
+ const E = @typeInfo(@FieldType(T, "items")).pointer.child;
+ const got = try l.slice(E, s);
+ out.* = .empty;
+ out.items = got;
+ out.capacity = got.len;
+ return;
+ }
+ switch (comptime kindOf(T)) {
+ .skip, .void => {},
+ .bool => out.* = (try l.take(1))[0] != 0,
+ .int => out.* = try l.readInt(T, s),
+ .float => out.* = if (l.same or s.bits == @typeInfo(T).float.bits) try l.scalar(T) else return error.Incompatible,
+ .@"enum" => {
+ const e = @typeInfo(T).@"enum";
+ if (l.same) {
+ out.* = @fromBackingInt(@intCast(try l.readInt(e.tag_type, s)));
+ return;
+ }
+ const n = try l.readInt(i128, s);
+ const was = for (s.fields) |f| {
+ if (f.value == n) break f.name;
+ } else null;
+ if (was) |w| inline for (e.field_names) |field| if (std.mem.eql(u8, w, field)) {
+ out.* = @field(T, field);
+ return;
+ };
+ if (e.mode == .nonexhaustive and was == null)
+ if (std.math.cast(e.tag_type, n)) |tag| {
+ out.* = @fromBackingInt(@intCast(tag));
return;
- }
- const one = try l.gpa.create(C);
- const at = l.made(std.mem.asBytes(one), .of(C)) catch |err| {
- l.gpa.destroy(one);
- return err;
};
- try l.fresh(C, one);
- l.value(C, s.child, one) catch |err| {
- // Left half made: no later reference may find it.
- l.shared.items[at].dead = true;
- return err;
- };
- out.* = one;
- },
- .slice => {
- const E = @typeInfo(T).pointer.child;
- const got = try l.slice(E, s);
- if (comptime @typeInfo(T).pointer.sentinel_ptr != null) @compileError("walk: a sentinel slice: " ++ @typeName(T));
- out.* = got;
- },
- .array => {
- const E = @typeInfo(T).array.child;
- const n: u64 = if (s.kind == .prefix) try l.scalar(u64) else s.len;
- try l.elements(E, s.child, n, out);
- },
- .prefix => unreachable,
- .@"struct" => try l.fields(T, s, out, false),
- .@"union" => {
- const u = @typeInfo(T).@"union";
- const ordinal = try l.scalar(u16);
- if (ordinal >= s.fields.len) return error.BadDump;
- const was = s.fields[ordinal];
- inline for (u.field_names, u.field_types, 0..) |field, F, i| {
- if (if (l.same) ordinal == i else std.mem.eql(u8, was.name, field)) {
- out.* = @unionInit(T, field, undefined);
- try l.fresh(F, &@field(out.*, field));
- return l.value(F, was.ty, &@field(out.*, field));
- }
+ l.note("{s}: no {s} here", .{ l.field, was orelse "such value" });
+ return error.Incompatible;
+ },
+ .optional => {
+ const C = @typeInfo(T).optional.child;
+ if ((try l.take(1))[0] == 0) {
+ out.* = null;
+ return;
+ }
+ if (comptime kindOf(Canon(C)) == .skip) {
+ out.* = if (comptime C == std.mem.Allocator) l.gpa else null;
+ return;
+ }
+ // A slice's or a pointer's null is its address: set to
+ // an undefined payload, the optional itself is undefined,
+ // and ReleaseSafe's optimizer read it as null (a pane's
+ // `?[]u8` command one byte long, every field after it out
+ // of step). Read through a local and set it from that.
+ if (comptime @typeInfo(C) == .pointer) {
+ var payload: C = undefined;
+ try l.value(C, s.child, &payload);
+ out.* = payload;
+ return;
+ }
+ out.* = @as(C, undefined);
+ try l.fresh(C, &out.*.?);
+ l.value(C, s.child, &out.*.?) catch |err| {
+ out.* = null;
+ return err;
+ };
+ },
+ .one => {
+ const C = @typeInfo(T).pointer.child;
+ if (try l.ref()) |again| {
+ out.* = @ptrCast(@alignCast(again.ptr));
+ return;
+ }
+ const one = try l.gpa.create(C);
+ const at = l.made(std.mem.asBytes(one), .of(C)) catch |err| {
+ l.gpa.destroy(one);
+ return err;
+ };
+ try l.fresh(C, one);
+ l.value(C, s.child, one) catch |err| {
+ // Left half made: no later reference may find it.
+ l.shared.items[at].dead = true;
+ return err;
+ };
+ out.* = one;
+ },
+ .slice => {
+ const E = @typeInfo(T).pointer.child;
+ const got = try l.slice(E, s);
+ if (comptime @typeInfo(T).pointer.sentinel_ptr != null) @compileError("walk: a sentinel slice: " ++ @typeName(T));
+ out.* = got;
+ },
+ .array => {
+ const E = @typeInfo(T).array.child;
+ const n: u64 = if (s.kind == .prefix) try l.scalar(u64) else s.len;
+ try l.elements(E, s.child, n, out);
+ },
+ .prefix => unreachable,
+ .@"struct" => try l.fields(T, s, out, false),
+ .@"union" => {
+ const u = @typeInfo(T).@"union";
+ const ordinal = try l.scalar(u16);
+ if (ordinal >= s.fields.len) return error.BadDump;
+ const was = s.fields[ordinal];
+ inline for (u.field_names, u.field_types, 0..) |field, F, i| {
+ if (if (l.same) ordinal == i else std.mem.eql(u8, was.name, field)) {
+ out.* = @unionInit(T, field, undefined);
+ try l.fresh(F, &@field(out.*, field));
+ return l.value(F, was.ty, &@field(out.*, field));
}
- try l.skip(was.ty);
- l.note("{s}: no {s} here", .{ l.field, was.name });
+ }
+ try l.skip(was.ty);
+ l.note("{s}: no {s} here", .{ l.field, was.name });
+ return error.Incompatible;
+ },
+ .err, .error_union => unreachable,
+ .custom => {
+ const bytes = try l.take(try l.count());
+ T.dumpRead(out, l.gpa, bytes) catch |err| {
+ if (err == error.OutOfMemory) return error.OutOfMemory;
+ l.note("{s}: {t}", .{ l.field, err });
return error.Incompatible;
- },
- .err, .error_union => unreachable,
- .custom => {
- const bytes = try l.take(try l.count());
- T.dumpRead(out, l.gpa, bytes) catch |err| {
- if (err == error.OutOfMemory) return error.OutOfMemory;
- l.note("{s}: {t}", .{ l.field, err });
- return error.Incompatible;
- };
- if (comptime @hasDecl(T, "dumpFree")) try l.customs.append(l.own, .{ .ptr = out, .gpa = l.gpa, .free = @ptrCast(&T.dumpFree) });
- },
- .bitset => {
- const bits = try l.count();
- out.* = try .initEmpty(l.gpa, bits);
- const words = (bits + @bitSizeOf(usize) - 1) / @bitSizeOf(usize);
- if (words > 0) @memcpy(std.mem.sliceAsBytes(out.masks[0..words]), try l.take(words * @sizeOf(usize)));
- },
- }
+ };
+ if (comptime @hasDecl(T, "dumpFree")) try l.customs.append(l.own, .{ .ptr = out, .gpa = l.gpa, .free = @ptrCast(&T.dumpFree) });
+ },
+ .bitset => {
+ const bits = try l.count();
+ out.* = try .initEmpty(l.gpa, bits);
+ const words = (bits + @bitSizeOf(usize) - 1) / @bitSizeOf(usize);
+ if (words > 0) @memcpy(std.mem.sliceAsBytes(out.masks[0..words]), try l.take(words * @sizeOf(usize)));
+ },
}
+ }
- /// A reference to a pointer or slice made before, or null for a
- /// new one (its length then read).
- fn ref(l: *Self) DecodeError!?[]u8 {
- const n = try l.scalar(u32);
- if (n == 0) return null;
- if (n > l.shared.items.len) return error.BadDump;
- const got = l.shared.items[n - 1];
- if (got.dead) return error.Incompatible;
- return got.bytes;
- }
+ /// A reference to a pointer or slice made before, or null for a
+ /// new one (its length then read).
+ fn ref(l: *Self) DecodeError!?[]u8 {
+ const n = try l.scalar(u32);
+ if (n == 0) return null;
+ if (n > l.shared.items.len) return error.BadDump;
+ const got = l.shared.items[n - 1];
+ if (got.dead) return error.Incompatible;
+ return got.bytes;
+ }
- fn slice(l: *Self, comptime E: type, s: SrcType) DecodeError![]E {
- if (try l.ref()) |again| return @as([*]E, @ptrCast(@alignCast(again.ptr)))[0 .. again.len / @max(1, @sizeOf(E))];
- const n = try l.count();
- if (n == 0) return &.{};
- if (n > l.bytes.len) return error.BadDump;
- const many = try l.gpa.alloc(E, n);
- const at = l.made(std.mem.sliceAsBytes(many), .of(E)) catch |err| {
- l.gpa.free(many);
- return err;
- };
- l.elements(E, s.child, n, many) catch |err| {
- l.shared.items[at].dead = true;
- return err;
+ fn slice(l: *Self, comptime E: type, s: SrcType) DecodeError![]E {
+ if (try l.ref()) |again| return @as([*]E, @ptrCast(@alignCast(again.ptr)))[0 .. again.len / @max(1, @sizeOf(E))];
+ const n = try l.count();
+ if (n == 0) return &.{};
+ if (n > l.bytes.len) return error.BadDump;
+ const many = try l.gpa.alloc(E, n);
+ const at = l.made(std.mem.sliceAsBytes(many), .of(E)) catch |err| {
+ l.gpa.free(many);
+ return err;
+ };
+ l.elements(E, s.child, n, many) catch |err| {
+ l.shared.items[at].dead = true;
+ return err;
+ };
+ return many;
+ }
+
+ /// `n` elements of the source's type `ty` into `out` (an array or
+ /// a slice), as many as it holds, the rest passed over.
+ fn elements(l: *Self, comptime E: type, ty: u32, n: u64, out: []E) DecodeError!void {
+ const keep: usize = @intCast(@min(n, out.len));
+ const s = l.src[ty];
+ // Bytes copied whole between builds when both sides agree on
+ // them: integers and bools (an enum's numbers may not be the other's).
+ const bulk = if (comptime flat(E)) l.same or (comptime flatHash(E)) and s.kind == (comptime kindOf(E)) and
+ (s.kind == .bool or (s.bits == @bitSizeOf(E) and s.signed == (@typeInfo(E) == .int and @typeInfo(E).int.signedness == .signed))) else false;
+ if (bulk) {
+ if (n > l.bytes.len) return error.EndOfDump;
+ @memcpy(std.mem.sliceAsBytes(out[0..keep]), try l.take(keep * @sizeOf(E)));
+ _ = try l.take(@intCast((n - keep) * @sizeOf(E)));
+ return;
+ }
+ // An array of optional pointers (a session's panes): one that
+ // cannot be read is left out, not the array.
+ const droppable = comptime @typeInfo(E) == .optional and @typeInfo(@typeInfo(E).optional.child) == .pointer;
+ var failed = false;
+ for (0..try countOf(n)) |i| {
+ if (i >= keep) {
+ try l.skip(ty);
+ continue;
+ }
+ try l.fresh(E, &out[i]);
+ l.value(E, ty, &out[i]) catch |err| {
+ if (err != error.Incompatible) return err;
+ if (droppable) {
+ out[i] = null;
+ l.note("{s}[{d}] left out", .{ l.field, i });
+ } else failed = true;
};
- return many;
}
+ if (failed) return error.Incompatible;
+ }
- /// `n` elements of the source's type `ty` into `out` (an array or
- /// a slice), as many as it holds, the rest passed over.
- fn elements(l: *Self, comptime E: type, ty: u32, n: u64, out: []E) DecodeError!void {
- const keep: usize = @intCast(@min(n, out.len));
- const s = l.src[ty];
- // Bytes copied whole between builds when both sides agree on
- // them: integers and bools (an enum's numbers may not be the other's).
- const bulk = if (comptime flat(E)) l.same or (comptime flatHash(E)) and s.kind == (comptime kindOf(E)) and
- (s.kind == .bool or (s.bits == @bitSizeOf(E) and s.signed == (@typeInfo(E) == .int and @typeInfo(E).int.signedness == .signed))) else false;
- if (bulk) {
- if (n > l.bytes.len) return error.EndOfDump;
- @memcpy(std.mem.sliceAsBytes(out[0..keep]), try l.take(keep * @sizeOf(E)));
- _ = try l.take(@intCast((n - keep) * @sizeOf(E)));
- return;
+ fn fields(l: *Self, comptime T: type, s: SrcType, out: *T, existing: bool) DecodeError!void {
+ const names = comptime dumpFields(T);
+ const packed_struct = comptime @typeInfo(T).@"struct".layout == .@"packed";
+ const outer = l.field;
+ defer l.field = outer;
+ if (l.same) {
+ if (s.fields.len != names.len) return error.BadDump;
+ inline for (names, 0..) |field, k| {
+ l.field = field;
+ try l.oneField(T, field, s.fields[k].ty, out, packed_struct, existing);
}
- // An array of optional pointers (a session's panes): one that
- // cannot be read is left out, not the array.
- const droppable = comptime @typeInfo(E) == .optional and @typeInfo(@typeInfo(E).optional.child) == .pointer;
- var failed = false;
- for (0..try countOf(n)) |i| {
- if (i >= keep) {
- try l.skip(ty);
- continue;
- }
- try l.fresh(E, &out[i]);
- l.value(E, ty, &out[i]) catch |err| {
+ return;
+ }
+ var found: std.StaticBitSet(@max(1, names.len)) = .empty;
+ var failed = false;
+ for (s.fields) |f| {
+ const k: ?usize = inline for (names, 0..) |field, k| {
+ if (std.mem.eql(u8, f.name, field)) break k;
+ } else null;
+ const at = k orelse {
+ try l.skip(f.ty);
+ continue;
+ };
+ found.set(at);
+ inline for (names, 0..) |field, i| if (i == at) {
+ l.field = field;
+ l.oneField(T, field, f.ty, out, packed_struct, existing) catch |err| {
if (err != error.Incompatible) return err;
- if (droppable) {
- out[i] = null;
- l.note("{s}[{d}] left out", .{ l.field, i });
+ const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?];
+ if (comptime attr.default_value_ptr) |dp| {
+ @field(out, field) = @as(*const @FieldType(T, field), @ptrCast(@alignCast(dp))).*;
+ l.noteField("its kind changed; its default taken", @typeName(T), field);
+ } else if (existing) {
+ l.noteField("its kind changed; left as it was", @typeName(T), field);
} else failed = true;
};
- }
- if (failed) return error.Incompatible;
+ };
}
-
- fn fields(l: *Self, comptime T: type, s: SrcType, out: *T, existing: bool) DecodeError!void {
- const names = comptime dumpFields(T);
- const packed_struct = comptime @typeInfo(T).@"struct".layout == .@"packed";
- const outer = l.field;
- defer l.field = outer;
- if (l.same) {
- if (s.fields.len != names.len) return error.BadDump;
- inline for (names, 0..) |field, k| {
- l.field = field;
- try l.oneField(T, field, s.fields[k].ty, out, packed_struct, existing);
+ // A field the writer did not have: its default (`fresh`), or
+ // the value cannot be made.
+ inline for (names, 0..) |field, i| if (!found.isSet(i)) {
+ const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?];
+ if (comptime attr.default_value_ptr == null) {
+ if (!existing) {
+ l.noteField("not in the dump", @typeName(T), field);
+ failed = true;
}
- return;
- }
- var found: std.StaticBitSet(@max(1, names.len)) = .empty;
- var failed = false;
- for (s.fields) |f| {
- const k: ?usize = inline for (names, 0..) |field, k| {
- if (std.mem.eql(u8, f.name, field)) break k;
- } else null;
- const at = k orelse {
- try l.skip(f.ty);
- continue;
- };
- found.set(at);
- inline for (names, 0..) |field, i| if (i == at) {
- l.field = field;
- l.oneField(T, field, f.ty, out, packed_struct, existing) catch |err| {
- if (err != error.Incompatible) return err;
- const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?];
- if (comptime attr.default_value_ptr) |dp| {
- @field(out, field) = @as(*const @FieldType(T, field), @ptrCast(@alignCast(dp))).*;
- l.note("{s}.{s}: its kind changed; its default taken", .{ @typeName(T), field });
- } else if (existing) {
- l.note("{s}.{s}: its kind changed; left as it was", .{ @typeName(T), field });
- } else failed = true;
- };
- };
}
- // A field the writer did not have: its default (`fresh`), or
- // the value cannot be made.
- inline for (names, 0..) |field, i| if (!found.isSet(i)) {
- const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?];
- if (comptime attr.default_value_ptr == null) {
- if (!existing) {
- l.note("{s}.{s}: not in the dump", .{ @typeName(T), field });
- failed = true;
- }
- }
- };
- if (failed) return error.Incompatible;
- }
+ };
+ if (failed) return error.Incompatible;
+ }
- fn oneField(l: *Self, comptime T: type, comptime field: []const u8, ty: u32, out: *T, comptime packed_struct: bool, existing: bool) DecodeError!void {
- const F = @FieldType(T, field);
- const gpa = l.gpa;
- defer l.gpa = gpa;
- if (comptime allocOf(T, field)) |which| if (@field(l.allocs, which)) |a| {
- l.gpa = a;
- };
- if (comptime cutArray(T, field)) {
- return l.value(F, ty, &@field(out, field));
- }
- // A struct held in place in one read as it stands (the root's):
- // what it does not hold stays as it is too.
- if (comptime kindOf(Canon(F)) == .@"struct" and Canon(F) == F and @typeInfo(F).@"struct".layout != .@"packed") if (existing) {
- if (!try l.kindMatches(F, ty)) return error.Incompatible;
- return l.fields(F, l.src[ty], &@field(out, field), true);
- };
- if (packed_struct) {
- var copy: F = undefined;
- try l.fresh(F, &copy);
- try l.value(F, ty, &copy);
- @field(out, field) = copy;
- return;
- }
- try l.fresh(F, &@field(out, field));
- try l.value(F, ty, &@field(out, field));
+ fn oneField(l: *Self, comptime T: type, comptime field: []const u8, ty: u32, out: *T, comptime packed_struct: bool, existing: bool) DecodeError!void {
+ const F = @FieldType(T, field);
+ const gpa = l.gpa;
+ defer l.gpa = gpa;
+ if (comptime allocOf(T, field)) |which| if (@field(l.allocs, which)) |a| {
+ l.gpa = a;
+ };
+ if (comptime cutArray(T, field)) {
+ return l.value(F, ty, &@field(out, field));
}
+ // A struct held in place in one read as it stands (the root's):
+ // what it does not hold stays as it is too.
+ if (comptime kindOf(Canon(F)) == .@"struct" and Canon(F) == F and @typeInfo(F).@"struct".layout != .@"packed") if (existing) {
+ if (!try l.kindMatches(F, ty)) return error.Incompatible;
+ return l.fields(F, l.src[ty], &@field(out, field), true);
+ };
+ if (packed_struct) {
+ var copy: F = undefined;
+ try l.fresh(F, &copy);
+ try l.value(F, ty, &copy);
+ @field(out, field) = copy;
+ return;
+ }
+ try l.fresh(F, &@field(out, field));
+ try l.value(F, ty, &@field(out, field));
+ }
- /// The source's value of type `ty` passed over.
- fn skip(l: *Self, ty: u32) DecodeError!void {
- const s = l.src[ty];
- switch (s.kind) {
- .skip, .void => {},
- .bool => _ = try l.take(1),
- .int, .@"enum" => _ = try l.take(intBytes(s.bits)),
- .float => _ = try l.take(s.bits / 8),
- .optional => if ((try l.take(1))[0] != 0) try l.skip(s.child),
- .one => if (try l.scalar(u32) == 0) {
+ /// The source's value of type `ty` passed over.
+ fn skip(l: *Self, ty: u32) DecodeError!void {
+ const s = l.src[ty];
+ switch (s.kind) {
+ .skip, .void => {},
+ .bool => _ = try l.take(1),
+ .int, .@"enum" => _ = try l.take(intBytes(s.bits)),
+ .float => _ = try l.take(s.bits / 8),
+ .optional => if ((try l.take(1))[0] != 0) try l.skip(s.child),
+ .one => if (try l.scalar(u32) == 0) {
+ _ = try l.made(&.{}, .@"1");
+ l.shared.items[l.shared.items.len - 1].dead = true;
+ try l.skip(s.child);
+ },
+ .slice => if (try l.scalar(u32) == 0) {
+ const n = try l.scalar(u64);
+ if (n > 0) {
_ = try l.made(&.{}, .@"1");
l.shared.items[l.shared.items.len - 1].dead = true;
- try l.skip(s.child);
- },
- .slice => if (try l.scalar(u32) == 0) {
- const n = try l.scalar(u64);
- if (n > 0) {
- _ = try l.made(&.{}, .@"1");
- l.shared.items[l.shared.items.len - 1].dead = true;
- }
- try l.skipMany(s.child, n);
- },
- .prefix => try l.skipMany(s.child, try l.scalar(u64)),
- .array => try l.skipMany(s.child, s.len),
- .@"struct" => for (s.fields) |f| try l.skip(f.ty),
- .@"union" => {
- const ordinal = try l.scalar(u16);
- if (ordinal >= s.fields.len) return error.BadDump;
- try l.skip(s.fields[ordinal].ty);
- },
- .err => _ = try l.name(),
- .error_union => if ((try l.take(1))[0] != 0) try l.skip(s.child) else {
- _ = try l.name();
- },
- .custom => _ = try l.take(try l.count()),
- .bitset => _ = try l.take((try l.count() + 63) / 64 * 8),
- }
+ }
+ try l.skipMany(s.child, n);
+ },
+ .prefix => try l.skipMany(s.child, try l.scalar(u64)),
+ .array => try l.skipMany(s.child, s.len),
+ .@"struct" => for (s.fields) |f| try l.skip(f.ty),
+ .@"union" => {
+ const ordinal = try l.scalar(u16);
+ if (ordinal >= s.fields.len) return error.BadDump;
+ try l.skip(s.fields[ordinal].ty);
+ },
+ .err => _ = try l.name(),
+ .error_union => if ((try l.take(1))[0] != 0) try l.skip(s.child) else {
+ _ = try l.name();
+ },
+ .custom => _ = try l.take(try l.count()),
+ .bitset => _ = try l.take((try l.count() + 63) / 64 * 8),
}
+ }
- fn skipMany(l: *Self, ty: u32, n: u64) DecodeError!void {
- const s = l.src[ty];
- if (s.kind == .int or s.kind == .bool) {
- const size: u64 = if (s.kind == .bool) 1 else intBytes(s.bits);
- if (n > l.bytes.len) return error.EndOfDump;
- _ = try l.take(@intCast(n * size));
- return;
- }
- for (0..try countOf(n)) |_| try l.skip(ty);
+ fn skipMany(l: *Self, ty: u32, n: u64) DecodeError!void {
+ const s = l.src[ty];
+ if (s.kind == .int or s.kind == .bool) {
+ const size: u64 = if (s.kind == .bool) 1 else intBytes(s.bits);
+ if (n > l.bytes.len) return error.EndOfDump;
+ _ = try l.take(@intCast(n * size));
+ return;
}
- };
-}
+ for (0..try countOf(n)) |_| try l.skip(ty);
+ }
+};
/// `out` as a new `T` is before a load reads its fields: each field's
/// default, an allocator `gpa`.
@@ -1854,6 +1878,11 @@ pub const Get = struct {
l.notes.print(l.own, fmt ++ "\n", args) catch {};
}
+ /// A note on a type's field, its names given at run time (Load's).
+ fn noteField(l: *Get, comptime what: []const u8, type_name: []const u8, field: []const u8) void {
+ l.note("{s}.{s}: " ++ what, .{ type_name, field });
+ }
+
/// The value at `c`, made: what it points at is `gpa`'s.
pub fn get(l: *Get, comptime T: type, c: Cursor) Error!T {
var out: T = undefined;
@@ -2270,9 +2299,9 @@ pub const Get = struct {
const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?];
if (comptime attr.default_value_ptr) |dp| {
@field(out, field) = @as(*const @FieldType(T, field), @ptrCast(@alignCast(dp))).*;
- l.note("{s}.{s}: its kind changed; its default taken", .{ @typeName(T), field });
+ l.noteField("its kind changed; its default taken", @typeName(T), field);
} else if (existing) {
- l.note("{s}.{s}: its kind changed; left as it was", .{ @typeName(T), field });
+ l.noteField("its kind changed; left as it was", @typeName(T), field);
} else failed = true;
};
};
@@ -2284,7 +2313,7 @@ pub const Get = struct {
const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?];
if (comptime attr.default_value_ptr == null and kindOf(Canon(F)) != .void) {
if (!existing) {
- l.note("{s}.{s}: not in the dump", .{ @typeName(T), field });
+ l.noteField("not in the dump", @typeName(T), field);
failed = true;
}
} else if (comptime @typeInfo(F) == .optional and defaultIsNull(T, field)) if (existing) {
@@ -2564,3 +2593,8 @@ test "a blob of 4 KiB and up is digested by its length, what it holds told by it
small[1] = 'x';
try std.testing.expect(digest(File, &f) != was);
}
+
+test "a shape's numbers are written as {d} writes them" {
+ inline for (.{ 0, 7, 10, 65535, -1, -300, std.math.minInt(i128), std.math.maxInt(u128) }) |n|
+ try std.testing.expectEqualStrings(std.fmt.comptimePrint("{d}", .{n}), comptime decimal(n));
+}