From bf351b62e8843a3d173cedeefa2dd0b8ef4b4392 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 18:35:16 -0300 Subject: core, dev: what carries a slot across the core's edge carries its type (P21, pardes-ids change 3): `Pane.Id` in Event's six variants that carry a pane (output, eof, exited, file_changed, addon, job), in the fourteen effects that do (spawn, write, resize_pty, signal_pty, close_pty, start, save_file, save_text, lsp, watch, dump_themes, detach, addon, job), in the fourteen Host functions that take one (dev/Host.zig: adopt, upgrade, spawn, pty_write, pty_resize, pty_signal, close_pty, tty_taken, fg_name, kill_job, write_file, watch_file, dump_themes, job; tape.zig's Wrap follows with no edit), in the device messages that carry one into the core (the inbox's output and eof and the five reader functions that make them, dev/Lsp.zig's Request, host_io's Adoption and Adoptions.take, which hold what adoptShell answered); `View.Id` in abi/wire.zig's welcome.view (its bytes on the wire unchanged: one byte, hand-encoded, `.at(takeByte())`/`writeByte(view.index())`); every producer converts at its own line (`.pane = .at(id)`, a script that refuses any path outside the workspace, `fields.py`), every consumer where it indexes or compares (`o.pane.index()`), every Host implementer at its own first line (`fn spawn(ctx, id: pardes.Pane.Id, ..) { const pane = id.index(); ..}`: the terminal's 14, the window's 14, the Mac's 10, and the tests' hosts), and an id that went integer and back is passed through whole (`s.core.readerFailed(e.pane, err)`); the compiler caught no pane's slot passed as a view's or the reverse, only integers meeting the type; kept integers on purpose: KindJob.pane (core/Kind.zig, another agent's, reads it four times; converted at KindJob's and Effect's lines), the Watch table (file_watch: its last slot is the theme's, no pane), the hello's view and the replica's Peer/Joined/Replica views (core/replica.zig, another agent's), the C ABI's `pardes_watch_changed(uint8_t pane)` (abi/pardes.h unchanged; runtime/macos.zig converts at its Host functions); in files another agent is in, each conversion on the line that was there: core/Kind.zig 2 lines, core/Addon.zig 4, core/replica.zig 31 (the welcome's view, 3 test hosts, test literals), test/replicas.zig 12 (4 host functions with their first lines, 1 signature, the welcome's view, 5 literals); the tape's shape moves (Event is update's input), so the semantics word moves, c47ecf638b3f4b9f -> 38b5ae573b965550; test/perf.zig follows on 6 lines its Event and effect literals forced, so its harness id moves, be7cc504010471bc -> 1ed95030eb768eae (unit-test's perf check was BaselineHarnessMismatch already); 607 lines added, 562 deleted in 48 files. Gate (load 4 to 8): tui core-test 841/984 (143 skipped), shell-test 1020/1023, term-test 15/15, pane-test 183/184, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds of 70 steps, 0 failures, process-test lspcomplete and lspcompletemoved (the base's; hscroll failed once and passed on the runner's retry), gui unit-test 1618/1622 (BaselineHarnessMismatch, the base's); replicas --clients 5 (TMPDIR /tmp/claude-1000/ids): diverged 0, unequal 0 at rtt 30, 80, 207, deltas checked/wrong 1811/0, 1838/0, 1660/0, quiet checks 567/0, 650/0, 655/0, stops not on may_wait 0 (corpus through a client fails at step 21 as on the base with that TMPDIR); daemon.py plain, --far, --games, --window-clients, --upgrade both ways against pardes-tree's base prefix pass (the semantics words differ: the upgrade carries the session by its dump); test/cross_replay.py (tui records, gui replays): 27 digests agree in each of three replicas; rollback-bench runs; the macOS library for Linux and aarch64-macos and the FreeBSD cross-build build; frames (gpu/ids-3 against tree1) 77/77 byte-identical in Debug, unit-test 1618/1622 there, perfab corpus2x -0.021% (session noise 0.036%, threshold 0.4%), pictures identical in all 10 runs, perfops 97 counts within 0.1% (largest image-frame on longline +0.0231%), key-down on medium 10,040,108 -> 10,039,990 an operation (-0.0012%), render on medium 11,455,765 -> 11,455,683 (-0.0007%), terminal on all +0.0030% Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/host_io.zig | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'dev/host_io.zig') diff --git a/dev/host_io.zig b/dev/host_io.zig index 2ee7c47e..f86c3250 100644 --- a/dev/host_io.zig +++ b/dev/host_io.zig @@ -69,7 +69,7 @@ pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u /// A shell of a dead session the daemon handed this one (Adopt), and the /// terminal pane made for it once there is one. -pub const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?u8 }; +pub const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?pardes.Pane.Id }; /// The shells of dead sessions handed this one (Adopt), each waiting for /// the spawn of the terminal pane made for it (`take`). @@ -99,7 +99,7 @@ pub const Adoptions = struct { a.list[a.len] = .{ .pid = pid, .fd = fd, .pane = null }; a.len += 1; if (core.adoptShell()) |id| { - a.list[a.len - 1].pane = id.index(); + a.list[a.len - 1].pane = id; a.taken += 1; return; } @@ -112,7 +112,7 @@ pub const Adoptions = struct { } /// The adopted shell pane `pane`'s spawn takes, off the list. - pub fn take(a: *Adoptions, pane: u8) ?Adoption { + pub fn take(a: *Adoptions, pane: pardes.Pane.Id) ?Adoption { for (a.list[0..a.len], 0..) |it, i| if (it.pane == pane) { std.mem.copyForwards(Adoption, a.list[i .. a.len - 1], a.list[i + 1 .. a.len]); a.len -= 1; @@ -1105,7 +1105,7 @@ pub fn takeExits(core: *pardes.Pardes, ptys: anytype, ctx: anytype, comptime clo if (!pt.cmd.watched or !pt.cmd.due()) continue; pt.cmd.told = true; const eof = pt.cmd.eof; - core.update(.{ .exited = .{ .pane = @intCast(id), .status = pt.cmd.status } }); + core.update(.{ .exited = .{ .pane = .at(id), .status = pt.cmd.status } }); if (eof) close(ctx, id); } } @@ -1115,7 +1115,7 @@ pub fn takeExits(core: *pardes.Pardes, ptys: anytype, ctx: anytype, comptime clo pub fn commandEof(core: *pardes.Pardes, ptys: anytype, id: usize, ctx: anytype, comptime close: anytype) void { const pt = slotPty(&ptys[id]) orelse return; pt.cmd.eof = true; - core.update(.{ .eof = .{ .pane = @intCast(id) } }); + core.update(.{ .eof = .{ .pane = .at(id) } }); if (pt.cmd.told) return close(ctx, id); takeExits(core, ptys, ctx, close); } @@ -1549,7 +1549,7 @@ pub const PtyTests = struct { } fn tail(queue: *Inbox, bytes: []u8) void { - if (queue.pushOutput(0, 1, bytes)) queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } }); + if (queue.pushOutput(.at(0), 1, bytes)) queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } }); } }; @@ -2155,9 +2155,9 @@ test "completion survives a full output queue" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 7 }; defer queue.deinit(); - queue.acceptReader(0, 1); + queue.acceptReader(.at(0), 1); for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ - .pane = 0, + .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "output"), } }); @@ -2193,15 +2193,15 @@ test "PTY backpressure retains byte order and tail before EOF" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; defer queue.deinit(); - queue.acceptReader(0, 1); - for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); + queue.acceptReader(.at(0), 1); + for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); const tail = try gpa.dupe(u8, "tail"); var thread: ?std.Thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| { gpa.free(tail); return err; }; defer { - queue.cancelReader(0, 1); + queue.cancelReader(.at(0), 1); if (thread) |owned| owned.join(); } try PtyTests.waitBlocked(&queue); @@ -2227,24 +2227,24 @@ test "PTY backpressure cancellation and close release owned producers" { for ([_]bool{ false, true }) |close| { var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; defer queue.deinit(); - queue.acceptReader(0, 1); - for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); + queue.acceptReader(.at(0), 1); + for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); const tail = try gpa.dupe(u8, "cancelled"); const thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| { gpa.free(tail); return err; }; defer { - queue.cancelReader(0, 1); + queue.cancelReader(.at(0), 1); thread.join(); } try PtyTests.waitBlocked(&queue); - if (close) queue.close() else queue.cancelReader(0, 1); + if (close) queue.close() else queue.cancelReader(.at(0), 1); if (!close) { - queue.acceptReader(0, 2); - queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } }); - try std.testing.expect(queue.pushOutput(0, 2, try gpa.dupe(u8, "replacement"))); - queue.push(.{ .eof = .{ .pane = 0, .gen = 2 } }); + queue.acceptReader(.at(0), 2); + queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } }); + try std.testing.expect(queue.pushOutput(.at(0), 2, try gpa.dupe(u8, "replacement"))); + queue.push(.{ .eof = .{ .pane = .at(0), .gen = 2 } }); var batch = queue.take(); defer for (batch.slice()) |msg| msg.deinit(gpa, gpa); try std.testing.expectEqual(@as(usize, 2), batch.len); @@ -2258,14 +2258,14 @@ test "PTY EOF reserve cannot evict terminal output" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; defer queue.deinit(); - for (0..pardes.MAX_PANES) |pane| queue.acceptReader(@intCast(pane), 1); - for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); - for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = @intCast(pane), .gen = 1 } }); + for (0..pardes.MAX_PANES) |pane| queue.acceptReader(.at(pane), 1); + for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); + for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = .at(pane), .gen = 1 } }); var batch = queue.take(); defer for (batch.slice()) |msg| msg.deinit(gpa, gpa); try std.testing.expectEqual(Inbox.capacity, batch.len); for (batch.items[0..Inbox.output_capacity]) |msg| try std.testing.expectEqualStrings("before", msg.output.bytes); - for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane); + for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane.index()); } test "completions retain their arrival order across LSP and pipes" { @@ -2288,8 +2288,8 @@ test "completion reset frees queued payloads and rejects late LSP workers" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 9 }; defer queue.deinit(); - queue.acceptReader(0, 1); - queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "retained") } }); + queue.acceptReader(.at(0), 1); + queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "retained") } }); queue.push(.{ .lsp = .{ .id = 9, .rows = try gpa.dupe(u8, "current") } }); queue.push(.{ .lsp = .{ .id = 8, .rows = try gpa.dupe(u8, "late old request") } }); try std.testing.expectEqualStrings("current", queue.completions[0].lsp.rows.?); @@ -2343,7 +2343,7 @@ test "LSP query answers, and a newer one cancels it" { defer queue.deinit(); for (0..2) |_| { core.lspRequest(core.view().active, .status, ""); - queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" }); + queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = .at(core.view().active), .offset = 0, .arg = "" }); } const last = core.lsp_ask.wait.?.id; queue.lsp_task.?.future.await(io); -- cgit v1.3