diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-29 17:01:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-29 21:13:33 -0300 |
| commit | 70de5ec5ff3dad01afcc45244ad5e5a481486da6 (patch) | |
| tree | cd4b723dcc2cfd94c4ba2361c134927b0e2df60b /src/tape.zig | |
| parent | 349790339897466f323ff28748916aa48aa344f7 (diff) | |
| download | pardes-70de5ec5ff3dad01afcc45244ad5e5a481486da6.tar.gz pardes-70de5ec5ff3dad01afcc45244ad5e5a481486da6.zip | |
dump: one walker dump of the whole session, by name across builds, for Restore, -l, Handover and the store; dump.zig's hand-written schema gone
A dump is walk.zig's walk of the core with a table of every type it reaches
(fields, enum and union names, number widths), read back by name; terminals
are ghostty's snapshot (screens, history, kitty images); a failed load frees
what it made.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/tape.zig')
| -rw-r--r-- | src/tape.zig | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/tape.zig b/src/tape.zig index 70609858..3573d887 100644 --- a/src/tape.zig +++ b/src/tape.zig @@ -145,6 +145,11 @@ pub const Tape = struct { /// No digests recorded (a speculation's: a replica compares what it /// was given and what it asked, from a state the authority shares). no_digest: bool = false, + /// PARDES_REPLAY_DUMP (phase 2's gate): at the session's end, its dump + /// loaded must be it, digest for digest, and dump again byte for byte. + dump_check: bool = false, + dumps: usize = 0, + dump_bytes: usize = 0, fn record(t: *Tape, kind: Kind, comptime T: type, v: *const T) void { t.scratch.clearRetainingCapacity(); @@ -375,6 +380,34 @@ pub const Tape = struct { t.digests += 1; } + /// The session's dump loaded into a core of its own, which must be the + /// same session (its digest) and dump to the same bytes. The tape is + /// put aside meanwhile: a dump is no input. + fn dumpRoundTrip(t: *Tape, p: *Pardes) void { + on = null; + defer on = t; + const bytes = pardes.dump.dumpBytes(p) catch |err| return t.diverge("dump failed: {t}", .{err}); + defer t.gpa.free(bytes); + var notes: std.ArrayList(u8) = .empty; + defer notes.deinit(t.gpa); + const q = pardes.dump.load(t.gpa, p.opts, bytes, ¬es) catch |err| return t.diverge("dump load failed: {t}", .{err}); + defer q.deinit(); + if (notes.items.len > 0) return t.diverge("dump of this build had notes: {s}", .{notes.items}); + var want: Parts = undefined; + var got: Parts = undefined; + const a = digestParts(p, &want); + const b = digestParts(q, &got); + if (!std.mem.eql(u64, a, b)) return t.diverge("dump round trip: the loaded digest differs in {s}", .{partsDiffer(b, a, t.arena.allocator())}); + const again = pardes.dump.dumpBytes(q) catch |err| return t.diverge("dump of the loaded failed: {t}", .{err}); + defer t.gpa.free(again); + if (!std.mem.eql(u8, bytes, again)) { + const at = std.mem.indexOfDiff(u8, bytes, again) orelse 0; + return t.diverge("dump is no fixpoint: {d} bytes then {d}, first differing at {d}", .{ bytes.len, again.len, at }); + } + t.dumps += 1; + t.dump_bytes += bytes.len; + } + fn applySet(t: *Tape, r: *walk.Reader) void { const which = (r.take(1) catch return)[0]; if (which == set_mask) { @@ -438,7 +471,10 @@ pub const Tape = struct { // The session is over (or the core a Restore replaced is // freed): nothing done now is compared. .deinit => |own| { - if (own) t.core = null; + if (own) { + if (t.dump_check) if (t.core) |core| t.dumpRoundTrip(core); + t.core = null; + } return t.skip(); }, .update => |ev| p.update(ev), @@ -926,6 +962,7 @@ pub fn replayMain(io: std.Io, path: []const u8) u8 { var failed = false; for (runs) |run| { var t: Tape = .{ .gpa = gpa, .replay = true, .in = .{ .bytes = bytes }, .headless = run.headless, .scratch = .init(gpa), .arena = .init(gpa) }; + t.dump_check = std.mem.eql(u8, run.name, "first") and libc.getenv("PARDES_REPLAY_DUMP") != null; on = &t; defer on = null; while (t.diverged == null) { @@ -950,6 +987,7 @@ pub fn replayMain(io: std.Io, path: []const u8) u8 { failed = true; std.debug.print("replay {s}: {s} replica diverged after {d} digests: {s}\n", .{ path, run.name, t.digests, why }); } else std.debug.print("replay {s}: {s} replica: {d} digests agree\n", .{ path, run.name, t.digests }); + if (t.dump_check and t.diverged == null) std.debug.print("replay {s}: {d} dumps loaded to their digests and dumped to their bytes again ({d} bytes)\n", .{ path, t.dumps, t.dump_bytes }); } return if (failed) 1 else 0; } |
