summaryrefslogtreecommitdiff
path: root/core/walk.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 16:17:21 -0300
committerGabriel Schneider <[email protected]>2026-11-23 16:17:21 -0300
commit8dd122b13ba8def974e8728734948e32e5e89e8e (patch)
treeb3e525ff0771f95473461694db6cb118ee8501ce /core/walk.zig
parentf34d3a74cc4a6b735c98ce98cef0df42bd065e67 (diff)
parentde0b9a53ad18555708121b31a3dc813cbda8fa0e (diff)
downloadpardes-8dd122b13ba8def974e8728734948e32e5e89e8e.tar.gz
pardes-8dd122b13ba8def974e8728734948e32e5e89e8e.zip
integration: the installed tree (main = pardes-merge64, f34d3a74cc4a) and pardes-release-soak round 1 with its unfinished cheap jump equality on top (pardes-jump-eql-wip = mxkpuqwo on mntzqroy on zmxmqkmw): the base of pardes-release-soak round 2; no conflict
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/walk.zig')
-rw-r--r--core/walk.zig39
1 files changed, 39 insertions, 0 deletions
diff --git a/core/walk.zig b/core/walk.zig
index d870052d..593532f8 100644
--- a/core/walk.zig
+++ b/core/walk.zig
@@ -89,6 +89,45 @@ pub fn digest(comptime T: type, v: *const T) u64 {
return h.final();
}
+/// Equal as the digest sees them, by the digest's rules: what the walk
+/// leaves out (a field `replica` names, a Buf's bytes past its length) is
+/// not compared; a type that walks itself, by its digest. std.meta.eql
+/// compares every byte of an array, and those bytes are undefined: 0xAA on
+/// every Debug process, each release process's own garbage; a decision of
+/// the core taken on them agrees between a session and its clients in
+/// Debug alone.
+pub fn eql(comptime T: type, a: *const T, b: *const T) bool {
+ switch (@typeInfo(T)) {
+ .void => return true,
+ .bool, .int, .@"enum" => return a.* == b.*,
+ .optional => |o| return if (a.*) |*x| (if (b.*) |*y| eql(o.child, x, y) else false) else b.* == null,
+ .array => |arr| {
+ if (comptime flatHash(arr.child)) return std.mem.eql(arr.child, a, b);
+ for (a, b) |*x, *y| if (!eql(arr.child, x, y)) return false;
+ return true;
+ },
+ .@"struct" => |s| {
+ if (comptime machinery(T)) return true;
+ if (comptime s.layout == .@"packed" or @hasDecl(T, "digest") or isList(T) or isAtomic(T) or isBitset(T) or @hasField(T, "any_future")) return digest(T, a) == digest(T, b);
+ inline for (s.field_names, s.field_types, s.field_attrs) |name, F, attr| {
+ if (attr.@"comptime" or comptime excluded(T, name)) continue;
+ if (comptime lengthOf(T, name)) |len| {
+ const x = @field(a, name)[0..lengthIn(a, len)];
+ const y = @field(b, name)[0..lengthIn(b, len)];
+ if (comptime flatHash(Element(F))) {
+ if (!std.mem.eql(Element(F), x, y)) return false;
+ } else {
+ if (x.len != y.len) return false;
+ for (x, y) |*p, *q| if (!eql(Element(F), p, q)) return false;
+ }
+ } else if (!eql(F, &@field(a, name), &@field(b, name))) return false;
+ }
+ return true;
+ },
+ else => return digest(T, a) == digest(T, b),
+ }
+}
+
/// A digest of each field `hash` would walk, in order (what a divergence
/// is narrowed down by); `names` are theirs.
pub fn fieldDigests(comptime T: type, v: *const T, out: []u64) []u64 {