diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-18 17:44:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-18 17:44:54 -0300 |
| commit | 41f665c986886790e474bef78928f4b0d3b05c21 (patch) | |
| tree | fe14dc9afdbcc36e42fbdcb17e7257083dda9d98 /src/replica.zig | |
| parent | e3e9a2d35ded6b668c2bb668845bb39d86e0412b (diff) | |
| parent | f3a38a45c00eb02f0aaaca7185e5601ab7224913 (diff) | |
| download | pardes-41f665c986886790e474bef78928f4b0d3b05c21.tar.gz pardes-41f665c986886790e474bef78928f4b0d3b05c21.zip | |
integration: addons in a client part 4 (the scroll bench's clock, a view laid out as the active one, the Shadow path deleted, address P:H on a late joiner) with the client path's round 4 and Zig 0.17.1: no conflict; on Zig 0.17.1: replicas with five clients: diverged 0, unequal 0, deltas checked/wrong 1782/0, 1769/0, 1871/0, quiet checks 582/0, 773/0, 791/0; tui core-test 819/960 (141 skipped), shell-test 995/998, behaviour-test 274/274 and its replay 20 seeds with 0 failures, pane-test 183/184; gui frame corpus 77/77 Debug and ReleaseFast against mbase171, unit-test 1592/1596, the tui build has no SDL symbol; the perf window, each of its three runs now the gated tree's: corpus2x -0.096% (spread 0.19%), corpus-snake -0.164%: the +0.77% that held this merge was the gate measuring another workspace (the helper that ignored GATE_W)
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/replica.zig')
| -rw-r--r-- | src/replica.zig | 128 |
1 files changed, 13 insertions, 115 deletions
diff --git a/src/replica.zig b/src/replica.zig index 3af1caac..16c6b15d 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -342,15 +342,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 @@ -361,11 +356,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 }; @@ -396,7 +388,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 }; @@ -406,10 +398,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); @@ -436,20 +425,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; @@ -468,57 +453,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 @@ -583,8 +517,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; @@ -746,8 +678,6 @@ pub const Replica = struct { serials: [pardes.MAX_PANES]u32 = @splat(0), retiring: bool = false, 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, @@ -822,7 +752,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]); @@ -856,7 +786,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); @@ -1287,28 +1216,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) { @@ -2178,11 +2085,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 }); @@ -3310,8 +3213,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 { @@ -4694,13 +4597,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 @@ -4710,8 +4610,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 { @@ -4723,9 +4622,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()); |
