summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Term.zig5
-rw-r--r--core/edit.zig11
-rw-r--r--core/locations.zig4
-rw-r--r--core/replica.zig12
-rw-r--r--core/rollback.zig36
5 files changed, 39 insertions, 29 deletions
diff --git a/core/Term.zig b/core/Term.zig
index d1065b49..f0329852 100644
--- a/core/Term.zig
+++ b/core/Term.zig
@@ -71,6 +71,11 @@ pub const State = struct {
/// same snapshot again from the dump.
written: bool = true,
+ /// Not walked by a replica's rollback copy (core/rollback.zig): its
+ /// emulator is written by confirmed units alone, each write counted
+ /// (Pardes.outside), never by a speculation, so no copy holds any of it.
+ pub const outside_copy = {};
+
/// The emulator as its program has made it, for the replay digest.
pub fn digest(s: *const State, h: *walk.Hasher) void {
the().digest(s.impl, h);
diff --git a/core/edit.zig b/core/edit.zig
index 129b004c..70b765cc 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -427,8 +427,13 @@ pub var drawing = false;
/// A terminal's rows as text (`Term.rows`), kept for one pane until its
/// grid moves. Returned slices remain valid until the next cache rebuild
-/// or reset.
+/// or reset. A replica's rollback copy holds it as any state: its text and
+/// rows are made whole and freed whole, never written, so the copy pins
+/// them (blobs, freed raw) and puts the cache back with the core: no
+/// emulator is written while a copy is held (replica.zig `confirm`: a unit
+/// that writes one lets the copy go or is applied after it is put back).
pub const RowsCache = struct {
+ pub const replica = .{ .blob = .{ "text", "rows", "text_alloc" } };
/// whose grid this describes; null = the slot is free
pane: ?*const Pane = null,
/// the rows joined by '\n' — `flatSurface` hands this back verbatim
@@ -442,8 +447,8 @@ pub const RowsCache = struct {
stale: bool = false,
pub fn reset(c: *RowsCache, gpa: std.mem.Allocator) void {
- if (c.text_alloc.len > 0) gpa.free(c.text_alloc);
- if (c.rows.len > 0) gpa.free(c.rows);
+ pardes.memory.freeRaw(gpa, c.text_alloc);
+ pardes.memory.freeRaw(gpa, c.rows);
c.* = .{};
}
diff --git a/core/locations.zig b/core/locations.zig
index 6972647e..10704912 100644
--- a/core/locations.zig
+++ b/core/locations.zig
@@ -25,6 +25,10 @@ pub const Row = struct {
code_start: usize,
colors: []u8 = &.{},
+ /// Not walked by a replica's rollback copy (core/rollback.zig): made
+ /// again, never written, in a blob the copy pins whole.
+ pub const outside_copy = {};
+
/// The replay digest's (core/walk.zig): all of it but its colours. They
/// are painted from what this process has painted (the owner's
/// highlights a frame made, the locations cache: both derived), so a
diff --git a/core/replica.zig b/core/replica.zig
index 936eb3e4..b37dcdb2 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -608,10 +608,7 @@ pub const Replica = struct {
if (r.t.core) |c| {
const was = Stepping.begin(&r.t, &r.epoch);
// The state it ends on is whole as it is: the copy let go, its
- // put-off frees done. Put back, it would bring back what was
- // freed between steps meanwhile (the shell's rows a draw read
- // again after a delta), which `toConfirmed` drops and this
- // freed again (a held copy across an input of its own, a
+ // put-off frees done (a held copy across an input of its own, a
// rejoin's old replica).
if (r.copy.held) r.copy.release();
c.deinit();
@@ -901,11 +898,6 @@ pub const Replica = struct {
if (!whole) return r.fail("out of memory for a rollback");
// The frame its host drew is of the memory put back: drawn again.
r.moved = true;
- // The rows a terminal was read as are no copy's: what the
- // speculation built was the epoch's, freed with it, and what
- // was there before is of a grid the deltas since moved on
- // from (a rollback never brings a terminal's past back).
- r.core().shell_rows = .{};
}
r.applied = 0;
for (r.since.items) |u| if (tape.replayUnit(&r.t, u)) |why| {
@@ -942,8 +934,6 @@ pub const Replica = struct {
const c = r.core();
if (!r.copy.held) {
const t0 = nowNs();
- // A grid's worth of text the copy would save, and put back stale.
- c.shell_rows.reset(c.gpa);
r.copy.take(&r.epoch, c) catch return false;
r.keepSerials();
rollback.Epoch.select(&r.epoch);
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");
}