summaryrefslogtreecommitdiff
path: root/core/rollback.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 22:48:28 -0300
committerGabriel Schneider <[email protected]>2026-11-23 02:13:53 -0300
commitde0e85daa8ad0bf9618734e16568823aa2b61a54 (patch)
tree613c1861b2ea1d3737eae799eeb63444b32fbd59 /core/rollback.zig
parent1ae5ae5e9201a6a942628ca57a6339bc90372317 (diff)
downloadpardes-de0e85daa8ad0bf9618734e16568823aa2b61a54.tar.gz
pardes-de0e85daa8ad0bf9618734e16568823aa2b61a54.zip
replicas: what a core field points to is the rollback copy's, or lives outside the core by its own declaration (pardes-term-join-12, item 1: the double free of round 11's gate): the copy skipped memory two ways, by inference and by a list, and each let a write survive a put-back: (1) `unwalked` took any type with a digest of its own and no `replica` annotation as outside the copy, so `jj.Session` (`Pardes.changes`, added with the layers) was saved as bytes and its heap never: a splice of the pinned lines at a client's edit (jj.edited) wrote a new `lines` into the answers buffer in place, the put-back freed it and left the pointer, and the next splice or the core's end freed it again (the test before this: allocated at jj.spliceValues under the speculation, freed at Epoch.discard, freed again at jj.spliceValues; the soak's abort at jj.Session.deinit); now a type is outside the copy only by declaring it (`outside_copy`: Term.State, the emulator written by confirmed units alone and counted; locations.Row, made again and never written, in a pinned blob), and every other type is walked, whatever digest it has; (2) `unsaved` skipped the rows cache (`Pardes.shell_rows`, `.derived`) and the replica kept it apart by hand (`speculate` emptied it before its take, `toConfirmed` set it `.{}` after a put-back), which an idle client's copy (`ready`) never emptied: the rows read before it were orphaned in the epoch at every rollback; now the cache is the copy's like any state: its text and rows are made whole and freed whole, so they are blobs the copy pins (no copy of a grid's text; freed raw), the put-back restores the cache with the core (valid: no emulator is written while a copy is held: a unit that writes one lets the copy go, or is applied after it is put back), and both hand resets are deleted; THE RULE the compiler holds: a type is skipped by the copy only by its own `outside_copy`, and a cache (`.derived`) on the copy's skip list (`unsaved`) is a compile error ("a cache the core holds is the copy's, or lives beside what it caches, outside the core"); the copy pins a blob once whoever reaches it (a text and the allocation it starts: never pinned twice nor also saved); not changed: the arenas (the copy saves their bytes, not their nodes: scratch content), the queues (asserted empty at a take), the host's and the process's own (store, Recent, the echo, the tape), a picture's pixels under a speculation (replica.zig's ponytail at `initDump`); the three tests of the change before: pass (the jj test and the rows test under a DebugAllocator as the epoch's child too, no double free reported); the gate (g12, a frozen copy; loads 1.5-12): core-test 918/1082 (164 skipped), shell-test 1124/1127 (3 skipped), term-test 17/17, kitty-test 45/45, pane-test 182/183 (1 skipped), behaviour-test and --replay 275/275, process-test 0 of 146 own and as pairs, the soak 3 of 3 whole and 10 of 10 at seed 0 and 80 ms (diverged 0, unequal 0, unlisted 0, quiet checks all agreed, the corpus 22 of 22, no leak, no abort), daemon.py every mode on Debug and ReleaseSafe (plain 3 of 3 each, --far 7 of 7 on ReleaseSafe, --games on ReleaseSafe with the Debug prefix's game libraries), --upgrade from the installed build 3 of 3, R2D 1 of 1, D2R 4 of 7 (two known test races: Exit's clunk answered after the window ended, far_exec's environment read at the exec; one quiet check of a Debug window client's key not in 30 s, load 6.1), --upgrade --gui 3 of 3, the cross-builds, the frame and perf gate against tree4: 77/77 frames, perfab corpus2x +0.014% (noise 0.049%), 121 counts within 0.1% (largest terminal on all +0.0794%), the gui unit-test 1719/1723 in the workspace (4 skipped, none failing; the copy's longer build root fails six tests whose messages name a temporary path: a 9P error's room is Plan 9's 128 bytes, ninep/tree.zig:549-556)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/rollback.zig')
-rw-r--r--core/rollback.zig36
1 files changed, 21 insertions, 15 deletions
diff --git a/core/rollback.zig b/core/rollback.zig
index a55d3c87..61fb7b89 100644
--- a/core/rollback.zig
+++ b/core/rollback.zig
@@ -441,7 +441,8 @@ pub const Copy = struct {
// the speculation freed would come back as that. Not the
// queues a step drains (undefined between steps), nor the
// authority's.
- if (attr.@"comptime" or comptime (annotated(T, "authority", name) or ((annotated(T, "local", name) or annotated(T, "derived", name)) and unsaved(name)))) continue;
+ if (comptime annotated(T, "derived", name) and unsaved(name)) @compileError("rollback: " ++ @typeName(T) ++ "." ++ name ++ " is a cache the copy would skip: a cache the core holds is the copy's, or lives beside what it caches, outside the core");
+ if (attr.@"comptime" or comptime (annotated(T, "authority", name) or (annotated(T, "local", name) and unsaved(name)))) continue;
// A text and its index: written in place, the epoch
// notes what each write takes out (`Epoch.wrote`).
if (comptime opaqueTo(F) or annotated(T, "journal", name)) continue;
@@ -483,7 +484,7 @@ pub const Copy = struct {
const s = @typeInfo(T).@"struct";
inline for (s.field_names, s.field_types, s.field_attrs) |name, F, attr| {
if (attr.@"comptime") continue;
- if (comptime (annotated(T, "local", name) or annotated(T, "derived", name) or annotated(T, "authority", name)) and unsaved(name)) continue;
+ if (comptime (annotated(T, "local", name) or annotated(T, "authority", name)) and unsaved(name)) continue;
const at = @intFromPtr(&@field(v, name));
if (comptime walk.lengthOf(T, name) != null and @typeInfo(F) == .array) {
try c.save(at, walk.lengthIn(v, comptime walk.lengthOf(T, name).?) * @sizeOf(@typeInfo(F).array.child));
@@ -501,7 +502,10 @@ pub const Copy = struct {
if (try c.reached([]const E, addr)) return;
if (c.pinnable and s.len * @sizeOf(E) >= blob_min and c.epoch.?.owns(addr) != null) {
// A blob of rows with allocations of their own is pinned whole:
- // they are as immutable as it, and kept alive with it.
+ // they are as immutable as it, and kept alive with it. Once,
+ // whatever reaches it (a text and the allocation it is the
+ // start of), and never saved as well.
+ if (try c.reached(void, addr)) return;
const bytes = std.mem.sliceAsBytes(s);
try c.pins.append(c.meta, .{ .addr = addr, .len = bytes.len, .hash = if (checked) std.hash.Wyhash.hash(0, bytes) else 0, .where = c.where });
return;
@@ -511,14 +515,16 @@ pub const Copy = struct {
}
};
-/// A type that hashes itself and says nothing of its fields (`replica`):
-/// a terminal, the authority's (its emulator is never written by a
-/// speculation: terminal.zig's guards), or a location row, made again and
-/// never written. One that says its fields' kinds is walked by them,
-/// whatever digest it has (the 9P state, fs.Namespace and a pane's: a
-/// replayed request writes its buffers in place).
+/// A type the copy does not walk: one that says so (`outside_copy`, with
+/// why: a terminal's handle, its emulator written by confirmed units alone,
+/// counted in Pardes.outside; a location row, made again and never
+/// written). Every other type is walked, whatever digest it has: what a
+/// core field points to is the copy's, saved or pinned, so that a write
+/// into it in place is put back with the rest (jj.Session's answers, whose
+/// lines an edit splices: walked by no one while its digest said "skip
+/// me", a rollback over a client's edit freed them twice).
fn unwalked(comptime T: type) bool {
- return @hasDecl(T, "digest") and @TypeOf(T.digest) == fn (*const T, *walk.Hasher) void and !@hasDecl(T, "replica");
+ return @hasDecl(T, "outside_copy");
}
fn annotatedStruct(comptime T: type) bool {
@@ -527,10 +533,10 @@ fn annotatedStruct(comptime T: type) bool {
/// The queues every step drains (empty between steps, asserted when a copy
/// is taken: what is in their slots is nothing), the frame statistics
-/// (numbers), and the rows a terminal was last read as
-/// (a grid's worth of text, emptied when a copy is taken and when it is
-/// put back: core/replica.zig), and a replica's predicted echo (core/term/echo.zig:
-/// the replica's, never its core's). And the store and Recent, a replica's
+/// (numbers), and a replica's predicted echo (core/term/echo.zig: the
+/// replica's, never its core's). Never a cache (`.derived`): what a core
+/// field caches is the copy's, or lives beside what it caches, outside the
+/// core (a compile error says so). And the store and Recent, a replica's
/// own: on the host's heap (Pardes.recentGpa), which the epoch never puts a
/// free off for, so their bytes put back would point at what is freed. A
/// step reads what the authority holds of them off the tape
@@ -538,7 +544,7 @@ fn annotatedStruct(comptime T: type) bool {
/// `Options.tape`): the process's, which a rollback leaves where it is.
fn unsaved(comptime name: []const u8) bool {
return std.mem.eql(u8, name, "effects") or std.mem.eql(u8, name, "in_q") or std.mem.eql(u8, name, "frames") or std.mem.eql(u8, name, "own_frames") or
- std.mem.eql(u8, name, "shell_rows") or std.mem.eql(u8, name, "echo") or std.mem.eql(u8, name, "store") or
+ std.mem.eql(u8, name, "echo") or std.mem.eql(u8, name, "store") or
std.mem.eql(u8, name, "recent") or std.mem.eql(u8, name, "tape");
}