From 2c714f8bc6733ba24499e62cbe8632037baacd03 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:58:37 -0300 Subject: walk: dead branches out: hashMap and its dispatch (no HashMap is reachable from a digest's roots: a map in Pardes would not compile past opaqueTo), and the dump's arms for errors with Load.errorNamed (no dumped type holds one, and Load refuses anyerror); the Kind numbers stay, an old dump's table still names them, and the tape keeps its errors Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/walk.zig | 46 +++------------------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/walk.zig b/src/walk.zig index 14e1929e..facc4bd9 100644 --- a/src/walk.zig +++ b/src/walk.zig @@ -319,7 +319,6 @@ pub fn hash(comptime T: type, v: *const T, h: *Hasher) void { if (s.layout == .@"packed") return hashInt(s.backing_integer.?, @bitCast(v.*), h); if (comptime isList(T)) return hashSlice(@typeInfo(@FieldType(T, "items")).pointer.child, v.items, h); - if (comptime @hasDecl(T, "KV") and @hasDecl(T, "Hash") and @hasField(T, "metadata")) return hashMap(T, v, h); // std.atomic.Value: what it holds. if (comptime @hasField(T, "raw") and s.field_names.len == 1 and @hasDecl(T, "load")) return hash(@FieldType(T, "raw"), &v.raw, h); // A worker's future is a handle of the host's, never state. @@ -405,20 +404,6 @@ fn hashSlice(comptime E: type, items: []const E, h: *Hasher) void { for (items) |*e| hash(E, e, h); } -/// A hash map's entries in no order: each one's own digest, summed. -fn hashMap(comptime T: type, v: *const T, h: *Hasher) void { - var sum: u64 = 0; - var it = v.iterator(); - while (it.next()) |entry| { - var one = Hasher.init(0); - hash(@TypeOf(entry.key_ptr.*), entry.key_ptr, &one); - hash(@TypeOf(entry.value_ptr.*), entry.value_ptr, &one); - sum +%= one.final(); - } - h.update(std.mem.asBytes(&v.count())); - h.update(std.mem.asBytes(&sum)); -} - /// The value as bytes, the same walk: what the tape carries (src/tape.zig), /// to a replica of another build too (a window of a terminal's session, a /// Linux client of a FreeBSD one). Native byte order, which every machine @@ -795,8 +780,6 @@ fn kindOf(comptime T: type) Kind { else .@"struct", .@"union" => |u| if (u.tag_type == null) @compileError("walk: an untagged union: " ++ @typeName(T)) else .@"union", - .error_set => .err, - .error_union => .error_union, else => @compileError("walk: cannot dump " ++ @typeName(T)), }; } @@ -856,7 +839,6 @@ fn children(comptime T: type) []const type { .one, .slice => &.{Canon(@typeInfo(T).pointer.child)}, .array => &.{Canon(@typeInfo(T).array.child)}, .prefix => &.{T.element}, - .error_union => &.{Canon(@typeInfo(T).error_union.payload)}, .@"struct" => blk: { var out: []const type = &.{}; for (dumpFields(T)) |name| out = out ++ .{FieldDump(T, name)}; @@ -1150,14 +1132,8 @@ pub fn Dump(comptime roots: []const type) type { inline else => |*payload| try d.value(@TypeOf(payload.*), payload), } }, - .err => try writeName(w, @errorName(v.*)), - .error_union => if (v.*) |*payload| { - try w.writeByte(1); - try d.value(@typeInfo(T).error_union.payload, payload); - } else |err| { - try w.writeByte(0); - try writeName(w, @errorName(err)); - }, + // Kinds an old dump's table may name (`skip`); no type walked here has them. + .err, .error_union => unreachable, .custom => { const at = d.out.writer.end; try w.writeAll(&std.mem.toBytes(@as(u64, 0))); @@ -1569,16 +1545,7 @@ pub fn Load(comptime roots: []const type) type { l.note("{s}: no {s} here", .{ l.field, was.name }); return error.Incompatible; }, - .err => out.* = try l.errorNamed(T), - .error_union => { - const P = @typeInfo(T).error_union.payload; - if ((try l.take(1))[0] != 0) { - var payload: P = undefined; - try l.fresh(P, &payload); - try l.value(P, s.child, &payload); - out.* = payload; - } else out.* = try l.errorNamed(@typeInfo(T).error_union.error_set); - }, + .err, .error_union => unreachable, .custom => { const bytes = try l.take(try l.count()); T.dumpRead(out, l.gpa, bytes) catch |err| { @@ -1597,13 +1564,6 @@ pub fn Load(comptime roots: []const type) type { } } - fn errorNamed(l: *Self, comptime E: type) DecodeError!E { - const was = try l.name(); - const names = @typeInfo(E).error_set.error_names orelse @compileError("walk: anyerror cannot be loaded by name: " ++ @typeName(E)); - inline for (names) |field| if (std.mem.eql(u8, was, field)) return @field(E, field); - return error.Incompatible; - } - /// 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 { -- cgit v1.3