summaryrefslogtreecommitdiff
path: root/core/Term.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 22:06:32 -0300
committerGabriel Schneider <[email protected]>2026-11-20 00:38:51 -0300
commit2662a45ac245e574987bf6876f4470aed89da09c (patch)
treec582032cde0cb742a67e2dd548022f7b83f8d1fd /core/Term.zig
parentba10cc4ff30d08d27ad35576df04a03282b6521b (diff)
downloadpardes-2662a45ac245e574987bf6876f4470aed89da09c.tar.gz
pardes-2662a45ac245e574987bf6876f4470aed89da09c.zip
replica: the bytes kind of replica made right and joinable (P29, P32; the brief's step 2: 2a, 2b, 2c and 2d in one change): the one rule in place of two, the faults shown first (a session's output kept over a copy held ahead was fed again by a rollback: the digests apart; the pages an emulator gained while a copy was held were the epoch's and freed with it: a crash in PageList.increaseCapacity in the rollback's replay): every replica's emulators on the C heap (panes.emulatorGpa), Term.writes counting the writes into emulators, a unit whose replay wrote one never kept over a copy taken ahead, never taken as moving nothing (tape.feedsTerminal), a client's input that owed a reflow always replayed when confirmed; a speculation moves a terminal's view under bytes as under screen state; tape.unit_max (1 MiB) and Tape.cut, which the session's Peers sets, so a pump's reads are cut into units under it; the join: whole terminals in a joiner's dump, every replica the session included reloading each live terminal in the step that opens or reopens a view (panes.reloadTerminals), the session's hash taped (Site.reload) and compared, kitty records left out of it, the cell pixels set first as a feed does; .positions and .prompt compared with the replica's own emulator on replay; replicas load kitty images by direct data only (Term.direct); Peers.bytes for the soak; six tests (core/replica.zig, bytes:); tui core-test 848/997 (149 skipped), shell-test 1033/1036, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275 and --replay 0, process-test 2 of 144 (the base's), image- and kitty-harness pass, unit-test bytes: 22/22; gui unit-test 1633/1637 (the perf check's BaselineHarnessMismatch); the soaks in klrvlrly's
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Term.zig')
-rw-r--r--core/Term.zig32
1 files changed, 32 insertions, 0 deletions
diff --git a/core/Term.zig b/core/Term.zig
index 82d5dad7..9f5d6362 100644
--- a/core/Term.zig
+++ b/core/Term.zig
@@ -14,6 +14,15 @@ const dump = @import("dump.zig");
const File = @import("File.zig");
const iface = plain.term;
+/// Writes into this process's emulators (a read fed, a grid reflowed, a
+/// view moved, one opened, closed, loaded or made again): whether a unit's
+/// replay made one, the replica engine's one rule (core/replica.zig
+/// `confirm`) reads across that replay, on its one thread.
+pub var writes: u32 = 0;
+/// The reloads this process made (a join's, on every side) and their time,
+/// for the soak's join line (test/replicas.zig `--bytes`).
+pub var reloads: struct { n: u32 = 0, ns: u64 = 0, worst_ns: u64 = 0 } = .{};
+
/// The terminal module's entries; null in a core built without it.
pub const ops: ?*const iface.Ops = if (@import("term_options").terminal) &@import("term").ops else null;
@@ -94,6 +103,9 @@ pub const State = struct {
defer arena.deinit();
const parts = try walk.load(iface.Parts, arena.allocator(), bytes[8..][0..n], null);
out.* = .{ .impl = try o.load(gpa, bytes[8 + n ..], &parts) };
+ writes +%= 1;
+ // A replica's (a join's, a closed terminal brought back in a step).
+ if (tape.replaying() or dump.terminal_gpa != null) o.direct(out.impl);
}
};
@@ -114,6 +126,10 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State {
const s = try gpa.create(State);
errdefer gpa.destroy(s);
s.* = .{ .impl = try o.open(gpa, cols, rows) };
+ writes +%= 1;
+ // A replica's emulator loads its program's images by direct data alone
+ // (P32): what is read off the session's machine is the session's.
+ if (tape.replaying()) o.direct(s.impl);
return s;
}
@@ -121,6 +137,7 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State {
/// one it was opened with): the allocator a caller hands is not used.
pub fn close(s: *State, _: std.mem.Allocator) void {
const own = the().gpa(s.impl);
+ writes +%= 1;
the().close(s.impl);
own.destroy(s);
}
@@ -130,6 +147,14 @@ pub fn close(s: *State, _: std.mem.Allocator) void {
/// history a page at a time, and a snapshot does not say how its rows were
/// cut into pages). The snapshot's hash, which every side compares.
pub fn reload(s: *State) !u64 {
+ writes +%= 1;
+ const t0 = @import("FrameStats.zig").nowNs();
+ defer {
+ reloads.n += 1;
+ const dt = @import("FrameStats.zig").nowNs() -| t0;
+ reloads.ns += dt;
+ reloads.worst_ns = @max(reloads.worst_ns, dt);
+ }
return the().reload(s.impl);
}
@@ -142,6 +167,7 @@ pub fn due(s: *const State) ?u64 {
/// Loaded from a dump without its shell: its program's modes reset, its
/// history marked off from what the next shell prints.
pub fn revive(s: *State) void {
+ writes +%= 1;
the().revive(s.impl);
}
@@ -160,6 +186,7 @@ pub fn stop() void {
/// One read of its program's output (`Told` says where the tracked rows
/// went).
pub fn feed(s: *State, bytes: []const u8, tracked: []const i32, rows: []i32, erased: []bool) Told {
+ writes +%= 1;
return the().feed(s.impl, bytes, tracked, rows, erased);
}
@@ -171,25 +198,30 @@ pub fn grid(s: ?*const State) Grid {
/// Its view to a row of its history, or onto its output (null).
pub fn viewTo(s: *State, at: ?usize) void {
+ writes +%= 1;
the().viewTo(s.impl, at);
}
/// Its view moved by a number of rows (negative scrolls back).
pub fn scroll(s: *State, delta: i32) void {
+ writes +%= 1;
the().scroll(s.impl, delta);
}
/// Its view back onto its output.
pub fn follow(s: *State) void {
+ writes +%= 1;
the().follow(s.impl);
}
/// Its grid reflowed, now or when `resizeDeferred` makes it.
pub fn resize(s: *State, cols: u16, rows: u16, later: bool) void {
+ writes +%= 1;
the().resize(s.impl, cols, rows, later);
}
pub fn resizeDeferred(s: *State) bool {
+ writes +%= 1;
return the().resizeDeferred(s.impl);
}