diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 18:35:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 20:24:14 -0300 |
| commit | bf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (patch) | |
| tree | ed415f31749669a36d5df304af4101f56e9fdd23 /core/Effect.zig | |
| parent | 78d94c4a62ec3f4039a475b637ff6a60649fde52 (diff) | |
| download | pardes-bf351b62e8843a3d173cedeefa2dd0b8ef4b4392.tar.gz pardes-bf351b62e8843a3d173cedeefa2dd0b8ef4b4392.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Effect.zig')
| -rw-r--r-- | core/Effect.zig | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/core/Effect.zig b/core/Effect.zig index f0e18335..7166294f 100644 --- a/core/Effect.zig +++ b/core/Effect.zig @@ -37,29 +37,29 @@ pub const Effect = union(enum) { /// A child for the pane in slot `pane` -- the one whose serial is /// `serial`: a pane closed and its slot taken before the effect is /// performed is not the one it was for (perform). - spawn: struct { pane: u8, serial: u32, cwd: Buf(effect_path_cap) }, - write: struct { pane: u8, bytes: Buf(effect_write_cap) }, - resize_pty: struct { pane: u8, cols: u16, rows: u16 }, + spawn: struct { pane: Pane.Id, serial: u32, cwd: Buf(effect_path_cap) }, + write: struct { pane: Pane.Id, bytes: Buf(effect_write_cap) }, + resize_pty: struct { pane: Pane.Id, cols: u16, rows: u16 }, /// For the pane whose serial is `serial`, as `spawn` is (perform). - signal_pty: struct { pane: u8, serial: u32, sig: PtySignal }, + signal_pty: struct { pane: Pane.Id, serial: u32, sig: PtySignal }, /// The terminal pane in this slot is gone: the shell hangs up its pty /// and ends the shell, rather than leave it running with nobody to read. - close_pty: struct { pane: u8 }, + close_pty: struct { pane: Pane.Id }, open_link: Buf(256), /// A program a plumbing rule starts (Plumb.run): its directory, then /// its argv, each ended by a NUL. A failure to start it is said at /// pane `pane`. - start: struct { pane: u8, line: Buf(effect_path_cap) }, + start: struct { pane: Pane.Id, line: Buf(effect_path_cap) }, /// write this pane's file content to its path; the shell reads both off /// the core (content is unbounded, effects are fixed-size values) - save_file: struct { pane: u8 }, - save_text: struct { pane: u8, serial: u32, path: Buf(effect_path_cap), promote: bool = false }, + save_file: struct { pane: Pane.Id }, + save_text: struct { pane: Pane.Id, serial: u32, path: Buf(effect_path_cap), promote: bool = false }, write_dump, set_clipboard, read_clipboard, /// `arg` up to 128 bytes, or for `explain` the query it explains, /// `<kind> <arg>`. - lsp: struct { id: u32, kind: lsp.Kind, pane: u8, offset: u32, arg: Buf(160) }, + lsp: struct { id: u32, kind: lsp.Kind, pane: Pane.Id, offset: u32, arg: Buf(160) }, /// Snapshot the matching request with pipeRequest(id), then run it away /// from the UI/event loop and answer with pipe_resp. pipe: struct { id: u32 }, @@ -71,19 +71,19 @@ pub const Effect = union(enum) { hand_over: struct { seq: u32 }, /// Write what an Edit's `w` took (`Pipe.writes`), in order. edit_write, - watch: struct { pane: u8, on: bool, mode: WatchMode = .reconcile }, + watch: struct { pane: Pane.Id, on: bool, mode: WatchMode = .reconcile }, theme_file: struct { generation: u32, on: bool }, /// Write the build-time theme ring below the per-user config directory. /// The pane receives the completion/error message from the native host. - dump_themes: struct { pane: u8 }, - detach: struct { pane: u8 }, + dump_themes: struct { pane: Pane.Id }, + detach: struct { pane: Pane.Id }, /// An addon loaded, let go, or let go and loaded again (Addon.zig): /// `arg` its path, or for unload its kind's name. Answered by an /// `addon` event. - addon: struct { op: @import("Addon.zig").Op, pane: u8, arg: Buf(effect_path_cap) }, + addon: struct { op: @import("Addon.zig").Op, pane: Pane.Id, arg: Buf(effect_path_cap) }, /// A kind's job for the host's workers (host_io.Job), answered by a /// `job` event. - job: struct { pane: u8, serial: u32, token: u32 }, + job: struct { pane: Pane.Id, serial: u32, token: u32 }, quit, pub fn Buf(comptime n: usize) type { @@ -120,8 +120,8 @@ fn performInner(p: *Pardes, e: Effect) void { switch (e) { // The host reads the pane (its command, its shell) as it forks, // so the slot must still hold the pane the spawn was for. - .spawn => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane] orelse "") else s.cwd.slice()) else { - p.fallback.spawned[s.pane] = true; + .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice()) else { + p.fallback.spawned[s.pane.index()] = true; }, // A pane with no child is silent: nothing invents output on its // screen, and the bytes are dropped rather than transcribed. @@ -129,7 +129,7 @@ fn performInner(p: *Pardes, e: Effect) void { .resize_pty => |r| if (v.pty_resize) |f| f(p.host.ctx, r.pane, r.cols, r.rows), // A signal for a pane that closed, its slot retaken in the same // step, would reach another pane's child. - .signal_pty => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig), + .signal_pty => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig), .close_pty => |c| if (v.close_pty) |f| f(p.host.ctx, c.pane), // The view's frontend opens it, yanks and pastes, on its own // machine (View.yanks); the host here only for a view no client @@ -149,17 +149,17 @@ fn performInner(p: *Pardes, e: Effect) void { _ = words.next(); // its directory const prog = words.next() orelse ""; var said: pardes.Kind.Buf(160) = .{}; - p.reportFailure(st.pane, said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w })); + p.reportFailure(st.pane.index(), said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w })); }, .save_file => |sf| { - const pane = p.panes[sf.pane] orelse return; + const pane = p.panes[sf.pane.index()] orelse return; const f = if (pane.file) |*file| file else return; const was = f.saved_revision; f.saved_revision = f.revision; // A save the host could not do (saveFailed) is its err // record alone, not a `save`, and changes nothing: a clean // file stays clean. - const saved_pane = writeChecked(p, sf.pane, pane.serial, f.path, f.content, was) orelse return; + const saved_pane = writeChecked(p, sf.pane.index(), pane.serial, f.path, f.content, was) orelse return; const saved = if (saved_pane.file) |*file| file else return; // Edited while it was written: what is on disk is not this. if (saved.saved_revision != saved.revision) return; @@ -174,19 +174,19 @@ fn performInner(p: *Pardes, e: Effect) void { p.emit(.{ .watch = .{ .pane = sf.pane, .on = true } }); }, .save_text => |st| { - const pane = p.panes[st.pane] orelse return; + const pane = p.panes[st.pane.index()] orelse return; if (pane.serial != st.serial) return; // a recycled slot: not ours if (pane.file) |*f| { // Failed, it changes nothing: not the name, not dirty. - const after = writeChecked(p, st.pane, st.serial, st.path.slice(), f.content, f.saved_revision) orelse return; + const after = writeChecked(p, st.pane.index(), st.serial, st.path.slice(), f.content, f.saved_revision) orelse return; if (after.file == null) return; - if (st.promote) promoteSaved(p, st.pane, st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice()); + if (st.promote) promoteSaved(p, st.pane.index(), st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice()); return; } if (!pane.isTerminal()) return; - const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(.at(st.pane), "Save", err); + const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(st.pane, "Save", err); defer p.gpa.free(text); - if (writeChecked(p, st.pane, st.serial, st.path.slice(), text, 0)) |still| + if (writeChecked(p, st.pane.index(), st.serial, st.path.slice(), text, 0)) |still| ctlfs.events.noteLogAs(p, .save, still, st.path.slice()); }, .write_dump => { @@ -249,22 +249,22 @@ fn performInner(p: *Pardes, e: Effect) void { }, .watch => |w| if (v.watch_file) |f| { // What a watch is about: a real file, or a kind's (a PDF's). - const path: []const u8 = if (p.panes[w.pane]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else ""; + const path: []const u8 = if (p.panes[w.pane.index()]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else ""; f(p.host.ctx, w.pane, path, w.on, w.mode); } else { - p.fallback.watched[w.pane] = w.on; + p.fallback.watched[w.pane.index()] = w.on; }, .theme_file => |t| if (v.watch_theme) |f| f(p.host.ctx, t.generation, t.on), .dump_themes => |d| if (v.dump_themes) |f| f(p.host.ctx, d.pane), .detach => |d| if (v.detach) |f| f(p.host.ctx) else - p.reportError(.at(d.pane), "detach", error.NotAttached), + p.reportError(d.pane, "detach", error.NotAttached), // dlopen is the same on every host, so none has a method of its // own; a replica's core holds no library (what it brought comes in // the event this taped). - .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane, a.arg.slice()), - .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane, j.serial, j.token), + .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane.index(), a.arg.slice()), + .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane.index(), j.serial, j.token), // the loop's own condition; a host tears down after its own loop .quit => p.endSession(), } @@ -282,7 +282,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: [] if (filesystem.localPath(path)) |local| filesystem.makeDirs(p.tape, std.Io.Dir.path.dirname(local) orelse "/"); // The in-process filesystem reports the same way a real host does, // so an OOM there leaves the pane dirty rather than looking saved. - if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); + if (p.host.vtable.write_file) |f| f(p.host.ctx, .at(id), path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); const pane = p.panes[id] orelse return null; if (pane.serial != serial) return null; if (p.fs.failures == failures) return pane; @@ -312,7 +312,7 @@ fn promoteSaved(p: *Pardes, id: u8, path: []const u8) void { ctlfs.events.noteLog(p, .save, pane); p.recent.opened(p.recentGpa(), f.path); if (filesystem.localPath(f.path) != null) - p.emit(.{ .watch = .{ .pane = id, .on = true } }); + p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); } fn drainForSavePath(p: *Pardes, buf: []u8) ?[]const u8 { @@ -343,7 +343,7 @@ test "Detach asks the host to let its terminal go, and says so when there is not .detach => |d| break d, else => {}, } else return error.NoDetachAsked; - try std.testing.expectEqual(@as(u8, 0), asked.pane); + try std.testing.expectEqual(0, asked.pane.index()); p.perform(.{ .detach = asked }); const pane = p.panes[0].?; @@ -376,7 +376,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file // The write asked for, the pane is the file once it is done. var saved = false; while (p.nextEffect()) |effect| { - if (effect == .save_text and @as(usize, effect.save_text.pane) == id) saved = true; + if (effect == .save_text and effect.save_text.pane.index() == id) saved = true; p.perform(effect); } try std.testing.expect(saved); @@ -392,7 +392,7 @@ test "Save on a terminal writes its plaintext scrollback and stays a terminal" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; p.setCwd(.at(0), "/tmp/pardes-tty-save"); - p.update(.{ .output = .{ .pane = 0, .bytes = "hello scrollback\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "hello scrollback\r\n" } }); while (p.nextEffect()) |_| {} try std.testing.expect(p.executeBuiltinLine(0, "Save")); @@ -474,7 +474,7 @@ test "Save takes the path as an argument, relative to the pane's own directory" while (p.nextEffect()) |_| {} const pane = p.panes[0].?; p.setCwd(.at(0), "/tmp/pardes-arg-save"); - p.update(.{ .output = .{ .pane = 0, .bytes = "typed and gone\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "typed and gone\r\n" } }); while (p.nextEffect()) |_| {} var buf: [256]u8 = undefined; @@ -510,9 +510,9 @@ test "Save takes the path as an argument, relative to the pane's own directory" test "a save the host could not do leaves the pane dirty" { const gpa = std.testing.allocator; const Refusing = struct { - fn writeFile(ctx: ?*anyopaque, pane: u8, _: []const u8, _: []const u8) void { + fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const core: *Pardes = @ptrCast(@alignCast(ctx.?)); - core.saveFailed(.at(pane), "/x/y.txt", error.PermissionDenied); + core.saveFailed(id, "/x/y.txt", error.PermissionDenied); } }; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -577,7 +577,7 @@ test "saves armed in one batch stay with their own panes" { const tty_id = p.freeSlot() orelse return error.NoPaneSlots; const shell = try p.newShell(tty_id, "/tmp/pardes-batch"); p.setCwd(.at(tty_id), "/tmp/pardes-batch"); - p.update(.{ .output = .{ .pane = @intCast(tty_id), .bytes = "shell text\r\n" } }); + p.update(.{ .output = .{ .pane = .at(tty_id), .bytes = "shell text\r\n" } }); const file = try p.setTestFile("file text\n"); const file_id = panes.paneIdOf(p, file) orelse return error.MissingFilePane; try std.testing.expect(shell.isTerminal()); @@ -606,7 +606,7 @@ test "a save whose pane is gone before the drain writes nothing" { const doomed = p.freeSlot() orelse return error.NoPaneSlots; const shell = try p.newShell(doomed, "/tmp/pardes-gone"); - p.update(.{ .output = .{ .pane = @intCast(doomed), .bytes = "doomed text\r\n" } }); + p.update(.{ .output = .{ .pane = .at(doomed), .bytes = "doomed text\r\n" } }); while (p.nextEffect()) |_| {} try std.testing.expect(shell.isTerminal()); @@ -687,19 +687,19 @@ test "a Save the host could not do logs no save record" { const Failing = struct { core: *Pardes, const vtable: Host.VTable = .{ .write_file = write }; - fn write(ctx: ?*anyopaque, pane: u8, path: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, _: []const u8) void { const f: *@This() = @ptrCast(@alignCast(ctx.?)); - f.core.saveFailed(.at(pane), path, error.AccessDenied); + f.core.saveFailed(id, path, error.AccessDenied); } }; var host: Failing = .{ .core = p }; p.host = .{ .ctx = &host, .vtable = &Failing.vtable }; _ = th.wr(p, ctlfs.Node.of(p.panes[0].?.serial, .body), "more\n"); - p.perform(.{ .save_file = .{ .pane = 0 } }); + p.perform(.{ .save_file = .{ .pane = .at(0) } }); try std.testing.expect(!th.logHas(p, "\nsave ")); try std.testing.expect(p.panes[0].?.file.?.saved_revision != p.panes[0].?.file.?.revision); // With the host's write done, it is logged. p.host = .{}; - p.perform(.{ .save_file = .{ .pane = 0 } }); + p.perform(.{ .save_file = .{ .pane = .at(0) } }); try std.testing.expect(th.logHas(p, "\nsave ")); } |
