From 1553f31259f545329dd8032b73888b688520dd38 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 12:56:12 -0300 Subject: kinds and addons: a kind's and an addon's tape calls are the handle's, the step's core's tape or a `tape: *Tape` parameter (the handle's step 3, P20, pardes-handle-sizing section 3's third noun): Kind.zig's fourteen (a kind's open, close, key, search, address, mouse and word refused to a speculation, `p.tape.authorityOnly`; its tag's prefix, `p.tape.value(.addon, ..)`; a tick's `p.tape.speculating` and `poison`; a call's end, `Call.end`, on its core's tape: its outcome taped, its plain block hashed only on a tape that is not `none` (`t.through`, where `tape.on == null` was: the one read of the global outside tape.zig and replica.zig is gone), and a client's plain kind that broke its promise diverging the replay through `Tape.diverge`, made public, under `t.replay` as `tape.diverged` was), and the C callback `api.job` (callconv(.c), no parameter to give) reaching its handle through `Kind.current`, the call under way, whose core it holds at that line (a call that asks a job and is not quiet is a step's: `cl.p.?.tape`), which holds at its one site: the other callbacks ask nothing of the tape; Addon.zig's three, its import gone with Kind.zig's (`const tape = @import("tape.zig")`, 2 lines apart from the count): Addon.need, Addon.take and Kind.Registry.started take `tape` (3 functions, the row said 1 + 20: the graph tied `take` by name to walk.Reader.take and the rest), `swap` reads `p.tape`; Kind.reopen takes the core it was always handed (`*Pardes`, was `?*Pardes`: no caller passed null); Pardes.create names its tape once, for `.kinds = .started(tape, ..)` and `.tape`; the count asked for first: Addon.zig's 48 machine lines are all in functions handed no core (hold 17, scan 11, mark 4, scanDir 3, readSmall 3, closeIdle 2, read 2, listed 2, fileOf, loadListed, unmark, crashedPath), 0 in one that holds it; a step reaches 29 of them through `need` (a kind's first pane, the session's: loadListed, mark, hold, closeIdle) and all 48 on a client's first plain kind (need -> plainOps -> scan), and the addon effect (Effect.perform's arm, not replaying) reaches the same 29 through readLoaded; none of these host halves asks the tape anything, the one question (`replaying`) sits above them in `need` and in perform's arm, so none took the tape, none is handed `&tape.none`, and none needed splitting: `need` is already the split (the step's question, then the host's body); the five numbers: (1) functions that gained the parameter 3 (row: 1 + 20); (2) the 97 per-operation counts within 0.1%, the largest image-frame on longline +0.0308% (the base's own spread); no function on a per-row or per-grapheme path gained it; (3) nothing stopped compiling for want of an io (no io moved: Addon's reads are libc); (4) global io uses 7 (6 and the tape's default, unchanged), free calls into the tape 80 -> 63 (count.py, a call on a `tape` parameter not counted), machine_lines rows unchanged; (5) lines changed: tests 4 (the take calls of three tests), code +41/-37 (with tape.zig's `pub` of diverge and the two import lines). Lines in files not this work's: none (no line in dev/, runtime/, core/replica.zig or test/). Gate: tui core-test 840/983 (143 skipped; Places' "a session's places loaded from its dump find what an edit makes as the session's do" failed once in the whole run, an edit's second crossing a clock second, and passed alone three times of three), shell-test 1018/1021, pane-test 183/184, term-test 15/15, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds 0 failures, process-test lspcomplete and lspcompletemoved (the base's; headersweep and headersweep-restored failed once and passed on the runner's retry), replicas --clients 5 diverged 0, unequal 0, deltas wrong 0 (2033/0, 1978/0, 1682/0), quiet 568/0, 581/0, 748/0, stops not at may_wait 0; its "corpus through a client" fails at steps 18 to 21 (the client's frame 34 or 35 cells otherwise than the own frontend's, row 20) on this change and on the base alike (pardes-entries with the rules' tests, run the same hour), so not this change's; gui unit-test 1616/1620 (the perf check's BaselineHarnessMismatch, the base's); daemon.py plain, --far, --games, --window-clients pass; a session recorded and replayed (test/cross_replay.py, tui to tui, private runtime directory): 28 digests agree in each of the three replicas; semantics 313a99190b93a8c5 (unmoved); frames (gpu/handle2-3 against tree1) 77/77 byte-identical in Debug, gui unit-test 1616/1620 there too, perfab corpus2x +0.083% (session noise 0.071%, threshold 0.4%), pictures identical in all 10 runs, perfops PASS Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Core.zig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'core/Core.zig') diff --git a/core/Core.zig b/core/Core.zig index b4745b24..9684de26 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -514,16 +514,17 @@ pub const perform = @import("Effect.zig").perform; /// second copy of this drifted once, leaving restored tags without an /// allocator and every 9P mtime 0. pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { + // The global still set beside the field (P20): a core made while + // a tape records (PARDES_RECORD, a replica's step) is its. + const tape = opts.tape orelse pardes.tape.on orelse &pardes.tape.none; const p = try gpa.create(Pardes); p.* = .{ .gpa = gpa, .image_gpa = opts.image_allocator orelse gpa, - .kinds = .started(opts.addons), + .kinds = .started(tape, opts.addons), .tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa, .opts = opts, - // The global still set beside the field (P20): a core made while - // a tape records (PARDES_RECORD, a replica's step) is its. - .tape = opts.tape orelse pardes.tape.on orelse &pardes.tape.none, + .tape = tape, .tty_toggle = opts.tty_toggle, .views = .{ View{ .frontend = .{ .windowed = opts.windowed }, -- cgit v1.3 From f1db5eaf5a5cc5f891cc2c180aa706fefc39971d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 13:51:42 -0300 Subject: core: the core's own files' tape calls are the handle's, `p.tape` (the handle's step 4, P20, pardes-handle-sizing section 3's fourth noun): Core.zig's twelve (the state file off in a replica, `p.tape.replaying()`; the config directory, the startup file and Recent by hash asked of the authority, `p.tape.authority`; the focus report under a speculation of screen state, `p.tape.speculating and p.tape.screen_state`; a missing interpreter, the session's facts (its directory, home and shell), a command's prompt and a greeting, the next wake, `p.tape.value`), Messages.zig's two clocks (a message said, the unattended expiry: `p.tape.value(.clock, ..)`), dump.zig's two (a terminal's kind refused to a speculation, a slot revived on a replica); every function among them holds the core, so none gains the parameter; the sizing's three handed none: Core.parentTrouble and config.Runtime.apply took the tape in step 2, and Messages.Message.stamp is no step's at all: its only callers are hosts (dev/file_watch.zig, dev/host_io.zig, dev/tui/tui.zig, dev/gui/gui.zig, runtime/macos.zig: a file reloaded, a save, a language server's status), between steps, handing the text to `setMessage`, an input the tape carries, so its `tape.value(.clock, timeOfDay)` recorded nothing anywhere (a host's call is the host's side: `call` goes straight through) and is now the host's own `timeOfDay()`, no tape, no parameter, no `&tape.none` in five host files; left on the global with the entries, for step 9: init's and initFromDump's startFromEnv, deinit's `current` and `forget` (a client's core freed between its steps would write `forget` into its idle tape, the rule of this line's first change), Restore's `adopt`, and the hand-written entries' enter and leave; config.zig has no other tape call; no file of these four imports `tape` (Core.zig and dump.zig say `pardes.tape.`, config.zig's is a parameter); the five numbers: (1) functions that gained the parameter 0 (row: 3, two of them done in step 2, the third off the tape); (2) the 97 per-operation counts within 0.1%, the largest image-frame on longline +0.0232%; no function on a per-row path touched; (3) nothing stopped compiling for want of an io; (4) global io uses 7 (unchanged), free calls into the tape 63 -> 45, machine_lines rows unchanged (Messages.zig's 6: timeOfDay's libc lines are the same lines); (5) lines changed: tests 0, code +21/-19. Lines in files not this work's: none. Gate: tui core-test 840/983 (143 skipped), shell-test 1018/1021, pane-test 183/184, term-test 15/15, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds 0 failures, process-test lspcomplete and lspcompletemoved (the base's; winch and headersweep failed once, passed on the runner's retry), replicas --clients 5 diverged 0, unequal 0, deltas wrong 0 (2033/0, 1978/0, 1682/0), quiet 568/0, 581/0, 748/0, stops not at may_wait 0 (its "corpus through a client" fails as on the base, steps 18 to 21), gui unit-test 1616/1620 (BaselineHarnessMismatch, the base's), daemon.py plain, --far, --games, --window-clients pass, test/cross_replay.py tui to tui: 28 digests agree in each of the three replicas, semantics 313a99190b93a8c5 (unmoved); frames (gpu/handle2-4 against tree1) 77/77 byte-identical in Debug, gui unit-test 1616/1620, perfab corpus2x +0.112% (session noise 0.068%, threshold 0.4%), pictures identical in all 10 runs, perfops PASS Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Core.zig | 24 ++++++++++++------------ core/Messages.zig | 12 +++++++----- core/dump.zig | 4 ++-- 3 files changed, 21 insertions(+), 19 deletions(-) (limited to 'core/Core.zig') diff --git a/core/Core.zig b/core/Core.zig index 9684de26..769d16cd 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -711,7 +711,7 @@ pub fn recentGpa(_: *const Pardes) std.mem.Allocator { pub fn loadRecent(p: *Pardes) void { // A replica's Recent is its own, in memory: the recording session's // state file is every session's of its user (core/tape.zig). - if (pardes.tape.replaying()) p.db.kind = .off; + if (p.tape.replaying()) p.db.kind = .off; p.db.readRecent(p); } @@ -774,11 +774,11 @@ pub fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: /// reads them: its process's options, so the authority's /// (`tape.authority`); a replica's are its own process's. pub fn configDir(p: *Pardes) ?[]const u8 { - return pardes.tape.authority(optsConfigDir, .{p}); + return p.tape.authority(optsConfigDir, .{p}); } pub fn startupPath(p: *Pardes) ?[]const u8 { - return pardes.tape.authority(optsStartupPath, .{p}); + return p.tape.authority(optsStartupPath, .{p}); } fn optsConfigDir(p: *Pardes) ?[]const u8 { @@ -793,7 +793,7 @@ fn optsStartupPath(p: *Pardes) ?[]const u8 { /// in scratch. Recent is the authority's (every window of its user /// writes it): a replica has its answer (`tape.authority`). pub fn recentByHash(p: *Pardes, hash: u64) ?recent_files.Entry { - return pardes.tape.authority(recentFound, .{ p, hash }); + return p.tape.authority(recentFound, .{ p, hash }); } fn recentFound(p: *Pardes, hash: u64) ?recent_files.Entry { @@ -927,7 +927,7 @@ fn reportFocus(p: *Pardes) void { // session's step makes the write, off the tape on both sides // (tape.hostCall's pty_write), so the switch shows at once and the // program hears of it a round trip later. - if (pardes.tape.speculating() and pardes.tape.screenState()) return; + if (p.tape.speculating and p.tape.screen_state) return; if (v.focus_told) |old| if (p.panes[old.id]) |pane| { if (pane.serial == old.serial and pardes.Term.modes(pane.terminal).focus) p.emitWrite(old.id, "\x1b[O"); }; @@ -1361,7 +1361,7 @@ fn sayShellFailure(p: *Pardes, id: u8, err: anyerror) void { // The script is there; the program its `#!` names is not. var said: pardes.Kind.Buf(320) = .{}; var interp: [256]u8 = undefined; - const name = pardes.tape.value(.interpreter, missingInterpreter, .{ pane.shell orelse p.shellBin(), &interp }); + const name = p.tape.value(.interpreter, missingInterpreter, .{ pane.shell orelse p.shellBin(), &interp }); p.reportFailure(id, if (name) |n| said.print("shell: interpreter {s} not found", .{n}) else "shell: interpreter not found"); } else { p.reportError(id, "shell", err); @@ -1745,15 +1745,15 @@ fn fsReport(p: *Pardes) void { pub fn readSessionFacts(p: *Pardes) void { // A dump made since carries them all: its shell is never empty. if (p.session_shell_len != 0) return; - if (p.session_dir_len == null) if (pardes.tape.value(.env, processDir, .{&p.session_dir})) |dir| { + if (p.session_dir_len == null) if (p.tape.value(.env, processDir, .{&p.session_dir})) |dir| { std.mem.copyForwards(u8, &p.session_dir, dir); p.session_dir_len = @intCast(dir.len); }; - if (pardes.tape.value(.env, filesystem.processHome, .{})) |home| if (home.len <= p.session_home.len) { + if (p.tape.value(.env, filesystem.processHome, .{})) |home| if (home.len <= p.session_home.len) { @memcpy(p.session_home[0..home.len], home); p.session_home_len = @intCast(home.len); }; - const shell = pardes.tape.value(.env, config.defaultShell, .{}); + const shell = p.tape.value(.env, config.defaultShell, .{}); const kept = shell[0..@min(shell.len, p.session_shell.len)]; @memcpy(p.session_shell[0..kept.len], kept); p.session_shell_len = @intCast(kept.len); @@ -1956,7 +1956,7 @@ pub fn sync(p: *Pardes) void { // A directory pane's entries follow its width, as acme's // columns do (Dir.fit). if (pane.file) |file| if (file.listing != null and r.h > pane.tag_rows) pardes.panes.Dir.fit(p, pane, pane.cols); - if (pane.pending_command.wait == .input) pane.releasePendingCommand(p, id, pardes.tape.value(.prompt, struct { + if (pane.pending_command.wait == .input) pane.releasePendingCommand(p, id, p.tape.value(.prompt, struct { fn ready(at: *const Pane) bool { return pardes.Term.prompt(at.terminal).input_ready; } @@ -1968,7 +1968,7 @@ pub fn sync(p: *Pardes) void { // its shell's FIRST prompt, or never: typed later it would land // in whatever runs then, or in the middle of a line someone // typed (Pane.greeting). - if (pane.greet and pane.isTerminal() and p.resize_count > 0) switch (pardes.tape.value(.prompt, Pane.greeting, .{pane})) { + if (pane.greet and pane.isTerminal() and p.resize_count > 0) switch (p.tape.value(.prompt, Pane.greeting, .{pane})) { .wait => {}, .never => pane.greet = false, .now => { @@ -2104,7 +2104,7 @@ fn advanceInner(p: *Pardes, now_ns: u64) void { // The session's ticks are the recording session's: a picture still // decoding or a fade still moving asks for frames the way a message // waiting to go does, and a replica that draws nothing has none. - while (pardes.tape.value(.wake, nextWake, .{p})) |due| { + while (p.tape.value(.wake, nextWake, .{p})) |due| { if (due > now_ns) break; // Only waiting until `due`: its counters move there at once. const held = (due - p.clock.stepped_ns) / frame; diff --git a/core/Messages.zig b/core/Messages.zig index de10b845..767eb297 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -111,9 +111,11 @@ pub const Message = struct { } pub fn stamp(buf: []u8, verb: []const u8, subject: []const u8) []const u8 { - // The time of day as the session that said it read it, in its - // zone: a replica's clock and TZ are its own (core/tape.zig). - const clock = pardes.tape.value(.clock, timeOfDay, .{}); + // The time of day of the host that stamps it, in its zone: only a + // host stamps a message (a file reloaded, a save, a language + // server's status), between steps, and the message it then hands + // the core (`setMessage`, an input) is what the tape carries. + const clock = timeOfDay(); const head = std.fmt.bufPrint(buf, "{s} {s} ", .{ &clock, verb }) catch return buf[0..0]; const room = buf.len - head.len; const tail = if (subject.len <= room) subject else subject[subject.len - room ..]; @@ -161,7 +163,7 @@ fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void { pane.msg_len = @intCast(n); // The clock when it was said (the session clock is the last pump's, // and a 9P write after an idle hour would say it an hour ago). - pane.msg_said_ms = pardes.tape.value(.clock, nowMs, .{}); + pane.msg_said_ms = p.tape.value(.clock, nowMs, .{}); p.needs_frame = true; // New, the same line again or a status update: fresh, so it stays. pane.msg_life = .{}; @@ -185,7 +187,7 @@ fn nowMs() i64 { pub fn expireUnattended(p: *Pardes) void { if (!p.unattended) return; // The clock as the session that recorded read it (core/tape.zig). - const now = pardes.tape.value(.clock, nowMs, .{}); + const now = p.tape.value(.clock, nowMs, .{}); for (p.panes) |slot| { const pane = slot orelse continue; if (pane.msg_len == 0 and pane.msg_older_len == 0) continue; diff --git a/core/dump.zig b/core/dump.zig index 31496674..6f143daa 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -499,7 +499,7 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* /// build's dump could not give): a terminal, a new emulator for its shell. fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void { if (pane.terminal != null or pane.file != null or pane.addon != null or pane.pdf != null) return; - if (pardes.tape.authorityOnly("open a terminal")) return error.OutOfMemory; + if (p.tape.authorityOnly("open a terminal")) return error.OutOfMemory; pane.terminal = try pardes.Term.open(pardes.panes.emulatorGpa(p.gpa), @max(1, pane.cols), @max(1, pane.rows)); } @@ -876,7 +876,7 @@ pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void { s.gen = p.kinds.kinds[k].gen; // A replica has no code to read it for: the authority's outcome is taped. // The authority's code may not be loaded yet: its open loads it. - const bytes: ?[]u8 = if ((s.ops != null or !pardes.tape.replaying()) and s.path.len > 0) filesystem.read(p, s.path) catch null else null; + const bytes: ?[]u8 = if ((s.ops != null or !p.tape.replaying()) and s.path.len > 0) filesystem.read(p, s.path) catch null else null; defer if (bytes) |b| p.gpa.free(b); const kept = .{ s.next_tick, s.views, s.focused }; if (!Kind.reopen(p, id, s, bytes)) { -- cgit v1.3