From 69bf62d3e245934b922025c62d8703700521cac0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 18 Nov 2026 11:52:57 -0300 Subject: kinds: the Shadow path deleted (the session painting a pane of a kind for each client and sending its frames, the rasters as strips, the client's picture cache): no kind in the tree reached it but a test's since the PDF and the picture run where they are shown (PA_PLAIN); a kind that is not plain shows a line in a client saying it runs in the session alone, its keys and mouse still the session's; Kind.zig 1,743 -> 1,367 lines (the Shadow section, Slot.shadow, draw's Shadow branch, the three Shadow tests), replica.zig 4,579 -> 4,477 (Screens.shadows and the kind_shadow/kind_raster/kind_want messages, PeerOf.shadow, Replica.blobs; Screens.flush keeps its view argument, unread now), the Counter kind's test rewritten for the line, draw.zig's pointer from the Shadow, dump.zig's comments; the manual (running.typ) and next-run.md say what a client shows; net -472 lines; tui core-test 817/956 (139 skipped; the three Shadow tests gone), shell-test 991/994, behaviour-test 274/274, --replay 20 seeds 0 failures, pane-test 181/182, replicas pass, addon-test 1/1, process-test 2 of 144 failed (lspcomplete and lspcompletemoved, the base's), test/daemon.py, --games and --window-clients pass, --far timed out once at load 10-12 (the ssh client's first frame) and passed alone; gui unit-test 1586/1590 (its perf check's BaselineBuildMismatch, the base's), the frame corpus 77/77 against mbase2 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/replica.zig | 128 ++++++-------------------------------------------------- 1 file changed, 13 insertions(+), 115 deletions(-) (limited to 'src/replica.zig') diff --git a/src/replica.zig b/src/replica.zig index f3ea3eee..10bc4253 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -287,15 +287,10 @@ pub const Authority = struct { // A message of either side is u8 pane, u32 the pane's serial (a slot's // next pane is another), u8 kind, and the kind's bytes: // to a replica: kind 1, a delta; kind 2, rows (encodeRows): asked for, -// or a step read them; kind 4, a pane of a kind's frame -// (a Shadow, screen_state.encodeShadow), at the size the -// peer's view gives the pane; kind 5, a strip of one of -// its rasters (encodeStrip), before the frame naming it; +// or a step read them; // to the authority: kind 1, an acknowledgement (u32 seq); kind 2, a // request for rows (u64 lo, u64 hi, absolute); kind 3, a -// delta refused: start this terminal afresh; kind 4, a -// kind's frame naming a raster the replica lacks: all -// of that pane again. +// delta refused: start this terminal afresh. // In the authority's stream to a peer, before it steps any input but a // pty's output, and once a frame: its own steps since the last unit, as one // (`Authority.pending`), then what the peer is owed of the terminals @@ -306,11 +301,8 @@ pub const Authority = struct { const kind_delta = 1; const kind_rows = 2; -const kind_shadow = 4; -const kind_raster = 5; const kind_ack = 1; const kind_reset = 3; -const kind_want = 4; const ScreenMsg = struct { pane: u8, serial: u32, kind: u8, payload: []const u8 }; @@ -341,7 +333,7 @@ pub const Screens = struct { encode_ns: u64 = 0, const Tracked = struct { serial: u32, state: *Term.State, track: *Term.Track }; - const PeerOf = struct { serial: u32 = 0, peer: Term.Peer = .{}, shadow: pardes.Kind.ShadowSent = .{} }; + const PeerOf = struct { serial: u32 = 0, peer: Term.Peer = .{} }; pub fn init(gpa: Allocator) Screens { return .{ .gpa = gpa }; @@ -351,10 +343,7 @@ pub const Screens = struct { pub fn deinit(s: *Screens, core: *Pardes) void { for (&s.tracks, 0..) |*slot, id| if (slot.*) |*tr| Term.untrack(tr.track, s.gpa, if (s.live(core, id, tr)) tr.state else null); for (s.peers.items) |p| { - for (p) |*pp| { - pp.peer.deinit(s.gpa); - pp.shadow.deinit(s.gpa); - } + for (p) |*pp| pp.peer.deinit(s.gpa); s.gpa.destroy(p); } s.peers.deinit(s.gpa); @@ -381,20 +370,16 @@ pub const Screens = struct { /// Peer `peer` gone: what it was sent forgotten, its number free for /// the next `addPeer` (a socket's clients come and go). pub fn dropPeer(s: *Screens, peer: u16) void { - for (s.peers.items[peer]) |*pp| { - pp.peer.deinit(s.gpa); - pp.shadow.deinit(s.gpa); - } + for (s.peers.items[peer]) |*pp| pp.peer.deinit(s.gpa); s.peers.items[peer].* = @splat(.{}); s.free_peers.append(s.gpa, peer) catch {}; } /// What `peer` is owed of every terminal, each a message onto `out` /// (owned): nothing for one it has as it is, or with `bound` in flight. - pub fn flush(s: *Screens, core: *Pardes, peer: u16, view: u8, out: *std.ArrayListUnmanaged([]u8)) !void { + pub fn flush(s: *Screens, core: *Pardes, peer: u16, _: u8, out: *std.ArrayListUnmanaged([]u8)) !void { const t0 = nowNs(); defer s.encode_ns += nowNs() - t0; - try s.shadows(core, peer, view, out); for (core.panes, 0..) |slot, id| { const pane = slot orelse continue; const state = pane.terminal orelse continue; @@ -413,57 +398,6 @@ pub const Screens = struct { } } - /// What `peer` is owed of each pane of a kind this core runs: its - /// frame as the peer's view shows it, when it is not what it was sent. - fn shadows(s: *Screens, core: *Pardes, peer: u16, view: u8, out: *std.ArrayListUnmanaged([]u8)) !void { - const any = for (core.panes) |slot| { - if (slot) |pane| if (pane.addon) |k| if (k.ops != null) break true; - } else false; - if (!any) return; - const Ctx = struct { s: *Screens, peer: u16, out: *std.ArrayListUnmanaged([]u8) }; - try pardes.views.within(core, view, Ctx{ .s = s, .peer = peer, .out = out }, struct { - fn each(x: Ctx, p: *Pardes) anyerror!void { - var arena: std.heap.ArenaAllocator = .init(x.s.gpa); - defer arena.deinit(); - // A plain kind's is drawn where it is shown (Kind.runsHere). - for (p.panes, 0..) |slot, id| if (slot) |pane| if (pane.addon) |k| if (k.ops != null and k.plain == null and !pane.collapsed) { - const pp = &x.s.peers.items[x.peer][id]; - if (pp.shadow.serial != pane.serial) { - pp.shadow.deinit(x.s.gpa); - pp.shadow.serial = pane.serial; - } - const r = p.view().rects[id]; - const cols = r.w -| pardes.config.GUTTER; - const rows = (r.h -| pane.tag_rows) -| pane.notices.span(); - if (cols == 0 or rows == 0) continue; - var frame: pardes.Kind.Frame = .{ .cols = cols, .rows = rows }; - frame.cells = pardes.Kind.paint(p, k, id, arena.allocator(), cols, rows, &frame) orelse continue; - // Its rasters' strips over what it shows that the peer - // lacks, each a message before the frame naming them. - for (frame.places[0..@min(frame.n, 64)]) |*pl| { - // A row past a strip's bound cannot cross: not shown there. - if (@as(usize, pl.w) * 4 > pardes.Kind.strip_max) continue; - var owed = try pp.shadow.owed(x.s.gpa, pl); - while (owed != 0) : (owed &= owed - 1) { - x.s.out.clearRetainingCapacity(); - try writeScreenHead(&x.s.out, x.s.gpa, @intCast(id), pane.serial, kind_raster); - var w: std.Io.Writer.Allocating = .fromArrayList(x.s.gpa, &x.s.out); - defer x.s.out = w.toArrayList(); - try pardes.Kind.encodeStrip(pl, @ctz(owed), &w.writer); - try x.out.append(x.s.gpa, try x.s.gpa.dupe(u8, w.written())); - } - } - x.s.out.clearRetainingCapacity(); - try writeScreenHead(&x.s.out, x.s.gpa, @intCast(id), pane.serial, kind_shadow); - var w: std.Io.Writer.Allocating = .fromArrayList(x.s.gpa, &x.s.out); - defer x.s.out = w.toArrayList(); - if (!try pardes.Kind.encodeShadow(x.s.gpa, &pp.shadow, &frame, k.pointer, &w.writer)) continue; - try x.out.append(x.s.gpa, try x.s.gpa.dupe(u8, w.written())); - }; - } - }.each); - } - /// Rows a peer holds as holes of every terminal a step read (its rows, /// history and all: text mode over a shell), each a rows message onto /// `out` (owned): sent after the step and before its unit, so the @@ -528,8 +462,6 @@ pub const Screens = struct { const m = parseScreen(msg) orelse return null; const pane = core.panes[m.pane] orelse return null; if (pane.serial != m.serial) return null; - // A kind's frame whose raster the peer lacks: its pane sent afresh. - if (m.kind == kind_want and pane.addon != null) s.peers.items[peer][m.pane].shadow.deinit(s.gpa); const state = pane.terminal orelse return null; const pp = &s.peers.items[peer][m.pane]; if (pp.serial != m.serial) return null; @@ -688,8 +620,6 @@ pub const Replica = struct { /// speculation may move a view, so a rollback puts these back. views: [pardes.MAX_PANES]View = @splat(.{}), screen_out: std.ArrayListUnmanaged(u8) = .empty, - /// Its Shadows' rasters, from the session's strips (17.3). - blobs: pardes.Kind.Blobs = .{}, /// A record's bytes by hash coming in pieces (`blobPiece`), and how /// many of them came. incoming: ?tape.Big = null, @@ -764,7 +694,7 @@ pub const Replica = struct { pardes.colors.finishThemeInitialization(c); // It runs a plain kind's code of its own (Addon.plainOps), loaded // at its first pane, each opened here from its record; another's - // panes are Shadows. + // panes show a line. c.kinds.ops = @splat(null); for (c.panes, 0..) |pslot, at| if (pslot) |pane| if (pane.addon) |s| if (c.kinds.byName(s.nameOf())) |k| { if (c.kinds.ops[k] == null) c.kinds.ops[k] = pardes.Addon.plainOps(&c.kinds.kinds[k]); @@ -792,7 +722,6 @@ pub const Replica = struct { c.deinit(); was.end(); } - r.blobs.deinit(r.gpa); if (r.incoming) |b| r.gpa.free(b.bytes); r.copy.deinit(); for (r.pending.items) |p| r.freePending(p); @@ -1169,28 +1098,6 @@ pub const Replica = struct { const c = r.t.core orelse return null; const pane = c.panes[m.pane] orelse return null; if (pane.serial != m.serial) return null; // a pane gone: its slot's next is another - // A strip of a raster of a pane of a kind, kept until a frame shows it. - if (m.kind == kind_raster and m.payload.len >= 8) { - var shown: std.ArrayList([*]const u8) = .empty; - defer shown.deinit(r.gpa); - for (c.panes) |slot| if (slot) |p| if (p.addon) |k| if (k.shadow) |sh| for (sh.places.items) |pl| shown.append(r.gpa, pl.rgba) catch {}; - r.blobs.strip(r.gpa, std.hash.Wyhash.hash(m.serial, m.payload[0..8]), m.payload, shown.items) catch r.fail("a kind's raster did not apply"); - return null; - } - // A pane of a kind: the authority's frame of it, drawn as it is. - if (m.kind == kind_shadow) if (pane.addon) |k| { - const sh = k.shadow orelse sh: { - const made = k.gpa.create(pardes.Kind.Shadow) catch return null; - made.* = .{}; - k.shadow = made; - break :sh made; - }; - const lacking = sh.apply(k.gpa, m.payload, m.serial, &r.blobs) catch { - r.fail("a kind's frame did not apply"); - return null; - }; - return if (lacking != 0) r.screenMessage(m.pane, m.serial, kind_want, &.{}) else null; - }; const state = pane.terminal orelse return null; const slot = &r.screens[m.pane]; if (slot.* == null or slot.*.?.serial != m.serial) { @@ -2039,11 +1946,7 @@ pub const Peers = struct { }, .screen => |in| { defer ps.gpa.free(in.msg); - const reply = (ps.screens.take(core, in.peer.sid, in.msg) catch null) orelse { - // A raster asked for again: its pane's frame now. - if (in.msg.len > 5 and in.msg[5] == kind_want) ps.screensTo(core, in.peer, .flush); - continue; - }; + const reply = (ps.screens.take(core, in.peer.sid, in.msg) catch null) orelse continue; defer ps.gpa.free(reply); const head = wire.header(@backingInt(wire.ServerTag.screen), reply.len); in.peer.send(&.{ &head, reply }); @@ -3171,8 +3074,8 @@ const PtyHost = struct { } }; -/// A kind as a library brings one, for the Shadow's test: a counter its -/// keys move, painted as `count N`. +/// A kind as a library brings one, its state not plain (no PA_PLAIN): a +/// counter its keys move, painted as `count N`. const Counter = struct { const pa = pardes.Kind.c; fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { @@ -4396,13 +4299,10 @@ test "a step that reads a terminal's rows as the core keeps them sends a new cli for ([_]*Replica{ r1, r2 }) |r| try agrees(a, r); } -test "a replica with no code for a kind draws its pane from the authority's frames, and its keys go to the authority" { +test "a replica with no code for a kind whose state is not plain shows its pane as a line saying so, and its keys go to the authority" { const gpa = std.testing.allocator; const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); defer r.deinit(); // What the host read off the library, as the `addon` event: the @@ -4412,8 +4312,7 @@ test "a replica with no code for a kind draws its pane from the authority's fram r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } })); r.confirm(try a.local(.{ .command = "Counter" })); try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null); - try deliver(a, &screens, peer, r, .flush); - try std.testing.expect(try shows(r.core(), "count 0")); + try std.testing.expect(try shows(r.core(), "addon counter 1 does not run in this client")); // A key into it, typed at the replica: the authority's kind takes it. var sent: std.ArrayListUnmanaged([]u8) = .empty; defer { @@ -4425,9 +4324,8 @@ test "a replica with no code for a kind draws its pane from the authority's fram r.confirm(try a.take(m)); r.settle(); } - try deliver(a, &screens, peer, r, .flush); try std.testing.expect(try shows(a.core, "count 1")); - try std.testing.expect(try shows(r.core(), "count 1")); + try std.testing.expect(!try shows(r.core(), "count 1")); if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); try std.testing.expect(r.diverged == null); try std.testing.expectEqual(digestOf(a), r.digest()); -- cgit v1.3