summaryrefslogtreecommitdiff
path: root/core/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 21:55:10 -0300
committerGabriel Schneider <[email protected]>2026-11-22 21:59:50 -0300
commit18e674964e5db67d35e1cf5ded128757ced22a98 (patch)
treef99ed84b30ecfcbc028b2c9c16deadc282dd06ce /core/panes.zig
parent9acf9f558de00f4588b51dee2cd56b9150c7fb35 (diff)
downloadpardes-18e674964e5db67d35e1cf5ded128757ced22a98.tar.gz
pardes-18e674964e5db67d35e1cf5ded128757ced22a98.zip
replicas: one decision a unit, by one count in the core (pardes-term-join-11, item 2; P54, the coordinator's lean, held against the code first): `Replica.confirm` asked one question four ways from three sources ("did applying this unit write state outside the rollback copy, an emulator?"): the speculation's own observation (`Pending.terminal` from `Tape.touched`, set by `touchTerminal` at a grid it owed and at every READ of a terminal's rows), the unit's records (`tape.feedsTerminal`), a process-wide counter (`Term.writes`, seven increments, shared by every side of the soak's one process) and a dead read (`read_terminal`, always false); round 10's predicate over the records failed because no record names the unit whose `sync` reflows a grid, a load or a teardown; now the core counts its emulators' writes itself (`Pardes.outside`, a `Term.Outside`): a field, so copied with a speculation, digested and dumped, a function of the tape, the same on every side; every write of the `calls` table's WRITE rows takes it first and counts (core/Term.zig `open`, `close`, `revive`, `reload`, `feed`, `resize`, `endOutputHere`, and `replies` when it drained any), a comptime block fails the build if a WRITE row's entry does not take it (the compiler holds the call sites; S1's `calls` test holds that a new write is listed); `resize` owes under a speculation (counted, not made: the grid's guard moved there from panes.zig `resizeGrid`); a load sets it (the walk loads the field; `dumpRead` counts nothing); the one read in `confirm`: on the fast path the count's movement over the input's speculation (`Pending.outside`, a number, equal to the unit's by the path's premise: moved, the unit is replayed once on the confirmed core), on the replay paths its movement over `replayUnit` on the core that applied it (moved over a copy held ahead, the copy goes), and on the neutral path no read at all: the session's digest after the unit holds the count, so a unit that wrote an emulator never ends where it began (`feedsTerminal` deleted with its one use); the predicted echo is judged at every unit that moved it; DELETED: `Tape.touched`, both `touchTerminal`s and the read-touch in edit.zig `shellRows` (a read writes nothing outside the copy; on the one road a speculation reads the confirmed emulator), `Term.writes` and its seven increments, `feedsTerminal`, `read_terminal`; where the lean does not stretch, said and not built: a picture's pixels, a kind's state and the Store's closed list are written BY a speculation, so the fast path must let the copy go, not replay: `panesMoved`, the serials and `retiring` stay for them; the dump changes (a core field): the wire stays at 31 (its history line says so); tests: the existing path tests green (fast, neutral, ahead, owed grid, "a view that sized a terminal closing leaves nothing queued ..." among them); new: a session's reflow of a terminal's grid over a copy held ahead is the count's to decide (a unit with no output record: the copy goes, a rollback does not reflow again), and the count digested (one side's emulator written outside any unit, a colour set no other digested field shows: `partsApart` names `outside` alone); core-test 917/1079 (162 skipped), shell-test 1121/1124 (3 skipped), the gate below
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/panes.zig')
-rw-r--r--core/panes.zig48
1 files changed, 23 insertions, 25 deletions
diff --git a/core/panes.zig b/core/panes.zig
index 032cb4db..5bf6992a 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -762,8 +762,8 @@ pub const Pane = struct {
var scrolled: Scrolled = .of(pane, p.live);
defer scrolled.put(pane, p.live);
if (!has_positions) {
- _ = Term.feed(state, bytes, &.{}, &.{}, &.{}, scrolled.places());
- } else if (pane.followRows(state, bytes, scrolled.places())) if (paneIdOf(p, pane)) |id| p.setMessage(.at(id), positions_lost);
+ _ = Term.feed(&p.outside, state, bytes, &.{}, &.{}, &.{}, scrolled.places());
+ } else if (pane.followRows(&p.outside, state, bytes, scrolled.places())) if (paneIdOf(p, pane)) |id| p.setMessage(.at(id), positions_lost);
p.shell_rows.markStale(pane);
}
@@ -802,7 +802,7 @@ pub const Pane = struct {
/// (the edit copy, the cursors and selections, their undo, the
/// pointer's rows) moved as the rows move (`Term.Told`). True when one
/// could not be kept (no memory for its pin).
- fn followRows(pane: *Pane, state: *Term.State, bytes: []const u8, places: []?usize) bool {
+ fn followRows(pane: *Pane, outside: *Term.Outside, state: *Term.State, bytes: []const u8, places: []?usize) bool {
const Group = struct { overlay: ?*Text.EditBuffer, cursor: *i32, selection: *Text.CharSel };
var groups: [Text.history_max * 2 + 1]Group = undefined;
groups[0] = .{
@@ -898,11 +898,11 @@ pub const Pane = struct {
var rows_buf: [512]i32 = undefined;
var erased_buf: [512]bool = undefined;
// Out of memory for them, the read is parsed and nothing moves.
- const track = if (n <= track_buf.len) track_buf[0..n] else pane.gpa.alloc(i32, n) catch return feedLost(state, bytes, places);
+ const track = if (n <= track_buf.len) track_buf[0..n] else pane.gpa.alloc(i32, n) catch return feedLost(outside, state, bytes, places);
defer if (n > track_buf.len) pane.gpa.free(track);
- const rows_after = if (n <= rows_buf.len) rows_buf[0..n] else pane.gpa.alloc(i32, n) catch return feedLost(state, bytes, places);
+ const rows_after = if (n <= rows_buf.len) rows_buf[0..n] else pane.gpa.alloc(i32, n) catch return feedLost(outside, state, bytes, places);
defer if (n > rows_buf.len) pane.gpa.free(rows_after);
- const erased_after = if (n <= erased_buf.len) erased_buf[0..n] else pane.gpa.alloc(bool, n) catch return feedLost(state, bytes, places);
+ const erased_after = if (n <= erased_buf.len) erased_buf[0..n] else pane.gpa.alloc(bool, n) catch return feedLost(outside, state, bytes, places);
defer if (n > erased_buf.len) pane.gpa.free(erased_after);
var k: usize = 0;
for (spans[0..nspans]) |span| for ([_]i32{ span.row, span.row +| (span.rows - 1) }) |row| {
@@ -913,7 +913,7 @@ pub const Pane = struct {
track[k] = at.grid;
k += 1;
};
- const fed = Term.feed(state, bytes, track, rows_after, erased_after, places);
+ const fed = Term.feed(outside, state, bytes, track, rows_after, erased_after, places);
const after = tape.value(.positions, keepTold, .{Term.Told{ .rows = fed.rows, .erased = fed.erased, .cleared = fed.cleared, .alive = fed.alive, .failed = failed or fed.failed }});
if (after.rows.len != n or after.erased.len != n) return false; // a replica its authority's states apart (diverged)
failed = after.failed;
@@ -994,8 +994,8 @@ pub const Pane = struct {
return t;
}
- fn feedLost(state: *Term.State, bytes: []const u8, places: []?usize) bool {
- _ = Term.feed(state, bytes, &.{}, &.{}, &.{}, places);
+ fn feedLost(outside: *Term.Outside, state: *Term.State, bytes: []const u8, places: []?usize) bool {
+ _ = Term.feed(outside, state, bytes, &.{}, &.{}, &.{}, places);
return true;
}
@@ -1016,21 +1016,19 @@ pub const Pane = struct {
}
/// Its terminal's grid reflowed to `cols` by `rows`, every open view's
- /// place carried through it (`Scrolled`; `live` the live view's index).
- pub fn resizeGrid(pane: *Pane, live: u8, cols: u16, rows: u16) void {
- // A client's speculation does what its replay does (its
- // selections) but the grid: it waits for no round trip. Under bytes
- // it owes the grid (`touchTerminal`): its input is replayed when
- // confirmed, never taken as speculated (replica.zig `confirm`).
+ /// place carried through it (`Scrolled`). A client's speculation does
+ /// what its replay does (its selections) but the grid, which it owes
+ /// (Term.resize: counted, not made): its input is replayed when
+ /// confirmed, never taken as speculated (replica.zig `confirm`).
+ pub fn resizeGrid(pane: *Pane, p: *Pardes, cols: u16, rows: u16) void {
const state = pane.terminal orelse return;
if (cols != pane.cols) for (0..pane.sel.len) |button| {
pane.clearPointerSelection(button);
pane.sel[button].state = .none;
};
- if (tape.speculating()) return tape.touchTerminal();
- var scrolled: Scrolled = .of(pane, live);
- defer scrolled.put(pane, live);
- Term.resize(state, cols, rows, scrolled.places());
+ var scrolled: Scrolled = .of(pane, p.live);
+ defer scrolled.put(pane, p.live);
+ Term.resize(&p.outside, state, cols, rows, scrolled.places());
}
/// The rows its terminal's top is passed over by in a view whose rect
@@ -1188,7 +1186,7 @@ pub fn reloadTerminals(p: *Pardes) void {
// frontend's draw sets its own view's between steps (ansi.zig), a
// window's other than a terminal's, and the snapshot holds it.
Term.cellPixels(state, p.view().cell_pixels.w, p.view().cell_pixels.h);
- const mine: ?u64 = Term.reload(state) catch null;
+ const mine: ?u64 = Term.reload(&p.outside, state) catch null;
p.shell_rows.markStale(pane);
if (tape.value(.reload, sameHash, .{mine}) != mine) tape.diverged("a terminal reloaded at a join is not the session's");
};
@@ -1216,10 +1214,10 @@ pub fn createDoc(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
/// A terminal pane: a pane and its emulator. Slot ownership, serial
/// assignment and spawn effects remain core lifecycle invariants.
-pub fn createTerminal(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
+pub fn createTerminal(outside: *Term.Outside, gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
const pane = try createDoc(gpa, cols, rows);
errdefer gpa.destroy(pane);
- pane.terminal = try Term.open(emulatorGpa(gpa), cols, rows);
+ pane.terminal = try Term.open(outside, emulatorGpa(gpa), cols, rows);
pane.tty_filter = true;
return pane;
}
@@ -1324,7 +1322,7 @@ pub fn teardownPane(p: *Pardes, pane: *Pane) void {
// A pane with none (a file's, a picker's, a preview's) closes in a
// speculation as anywhere.
if (pane.terminal) |state| if (!p.tape.authorityOnly("close a terminal")) {
- Term.close(state, p.gpa);
+ Term.close(&p.outside, state);
pane.terminal = null;
};
pane.clearCwd();
@@ -1361,7 +1359,7 @@ pub fn newShell(p: *Pardes, id: usize, cwd: []const u8) !*Pane {
if (cwd.len > limits.host_path_cap) return error.PathTooLong;
// A speculation opens no emulator: a terminal is the authority's to open.
if (p.tape.authorityOnly("open a terminal")) return error.OutOfMemory;
- const pane = try panes.createTerminal(p.gpa, p.view().screen_w, p.view().screen_h);
+ const pane = try panes.createTerminal(&p.outside, p.gpa, p.view().screen_w, p.view().screen_h);
// Named by the directory it is started in from the first, so the
// shell saying it is there is no rename (`new N /` then `rename`);
// out of memory for it, the shell names it when it says.
@@ -1394,7 +1392,7 @@ pub fn newCommand(p: *Pardes, id: usize, cwd: []const u8, line: []const u8) !*Pa
const owned = try p.gpa.dupe(u8, line);
errdefer p.gpa.free(owned);
if (p.tape.authorityOnly("open a terminal")) return error.OutOfMemory;
- const pane = try panes.createTerminal(p.gpa, p.view().screen_w, p.view().screen_h);
+ const pane = try panes.createTerminal(&p.outside, p.gpa, p.view().screen_w, p.view().screen_h);
pane.command = owned;
pane.command_pty = true;
pane.body.mode = .tty;