diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 16:17:21 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 16:17:21 -0300 |
| commit | 8dd122b13ba8def974e8728734948e32e5e89e8e (patch) | |
| tree | b3e525ff0771f95473461694db6cb118ee8501ce /core | |
| parent | f34d3a74cc4a6b735c98ce98cef0df42bd065e67 (diff) | |
| parent | de0b9a53ad18555708121b31a3dc813cbda8fa0e (diff) | |
| download | pardes-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')
| -rw-r--r-- | core/Jump.zig | 29 | ||||
| -rw-r--r-- | core/walk.zig | 39 |
2 files changed, 65 insertions, 3 deletions
diff --git a/core/Jump.zig b/core/Jump.zig index b68da32d..d85ff75a 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -203,8 +203,9 @@ pub fn trackJump(p: *Pardes) void { }; } // Two in a row the same (a closed one reopened beside its own, - // or the entry between them gone): one entry, one step. - if (w > 0 and std.meta.eql(v.jumps.list[w - 1], kept)) { + // or the entry between them gone): one entry, one step; the same + // as the digest sees them (a text's `place` is bytes undefined). + if (w > 0 and pardes.walk.eql(Loc, &v.jumps.list[w - 1], &kept)) { if (i == v.jumps.cur) cur = w - 1; continue; } @@ -361,12 +362,34 @@ test "the jump list never holds two entries in a row the same, when the one betw p.view().jumps.cur = 3; pane.body.cur_row = 80; // where you are now: far from both trackJump(p); - for (1..p.view().jumps.n) |i| try std.testing.expect(!std.meta.eql(p.view().jumps.list[i - 1], p.view().jumps.list[i])); + for (1..p.view().jumps.n) |i| try std.testing.expect(!pardes.walk.eql(Loc, &p.view().jumps.list[i - 1], &p.view().jumps.list[i])); try std.testing.expectEqual(@as(usize, 3), p.view().jumps.n); try std.testing.expectEqual(@as(u32, 1), p.view().jumps.list[0].line); try std.testing.expectEqual(@as(u32, 150), p.view().jumps.list[1].line); } +test "two entries the same but for the bytes past their place's length are one entry, as the digest sees them, on every build" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile(std.mem.asBytes(&@as([200][2]u8, @splat("a\n".*)))); + // A text's entry has no place: `.place = .{}`, its bytes undefined, + // 0xAA on every Debug process and each release process's own (the + // stack's, a load's): one entry on every side or a client parts. + var a: Loc = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 }; + var b = a; + @memset(&a.place.bytes, 0x11); + @memset(&b.place.bytes, 0x22); + p.view().jumps.list[0] = a; + p.view().jumps.list[1] = .{ .pane = 5, .serial = 999, .line = 1, .col = 1 }; + p.view().jumps.list[2] = b; + p.view().jumps.list[3] = .{ .pane = 0, .serial = pane.serial, .line = 150, .col = 1 }; + p.view().jumps.n = 4; + p.view().jumps.cur = 3; + pane.body.cur_row = 80; + trackJump(p); + try std.testing.expectEqual(@as(usize, 3), p.view().jumps.n); +} + test "jump history skips an entry whose pane slot or serial is gone, leaving the selection" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); defer p.deinit(); 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 { |
