From 58c230e73ab64e7b015a95462bde554c6b25df79 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 17:12:08 -0300 Subject: tape: a yes or no only the authority holds (whether a script reads a pane's events, whether the session serves a socket) is guessed by a replica's speculation from the authority's last answer to that question, recorded as the answer so its unit confirms or rolls it back: a Look or a click's command in a pane shows at once again, not a round trip late (11 of a Look class's 12 stops); lists (the closed panes, Recent) are still asked Co-Authored-By: Claude Opus 5.5 --- src/tape.zig | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/tape.zig') diff --git a/src/tape.zig b/src/tape.zig index 3975681e..12f7fe3d 100644 --- a/src/tape.zig +++ b/src/tape.zig @@ -219,6 +219,9 @@ pub const Tape = struct { /// What stopped it: a host function's or a site's name, or a poison's /// reason (PARDES_REPLICA_STATS counts them). poisoned_by: []const u8 = "", + /// The authority's last yes or no to each question a replayed unit + /// asked it (`authority`), a speculation's guess. + answers: std.AutoHashMapUnmanaged(u64, bool) = .empty, /// It read a terminal (its rows) or moved one's view: what it did /// depends on the emulator, which deltas write (`touchTerminal`). touched: bool = false, @@ -845,11 +848,40 @@ pub fn value(comptime s: Site, comptime f: anytype, args: anytype) @typeInfo(@Ty /// What it returns is the tape's arena's on a replay: `f` returns what /// lives to the step's end (scratch, or the authority's own), and the /// caller copies what it keeps. +/// +/// A yes or no (whether a script reads a pane's events, whether the +/// session serves a socket) is guessed by a speculation, mosh's way: the +/// authority's last answer to that question, as a replayed unit gave it, +/// recorded as the answer, so its unit confirms the guess or rolls it back. +/// A Look or a click's command in a pane then shows at once, not a round +/// trip late. ponytail: bools alone; a list (the closed panes, Recent) +/// changes with what the user does, and is asked of the authority. pub fn authority(comptime f: anytype, args: anytype) @typeInfo(@TypeOf(f)).@"fn".return_type.? { + if (comptime @typeInfo(@TypeOf(f)).@"fn".return_type.? == bool) if (on) |t| { + const key = question(f, args); + if (t.speculating) if (t.answers.get(key)) |was| { + const id: u16 = @as(u16, host_fns.len) + @backingInt(Site.authority); + t.record(.host, u16, &id); + t.record(.ret, bool, &was); + return was; + }; + if (t.replay) { + const got = value(.authority, f, args); + t.answers.put(t.gpa, key, got) catch {}; + return got; + } + }; poison("the authority's own state"); return value(.authority, f, args); } +/// What `authority` was asked: `f` and its arguments as they are. +fn question(comptime f: anytype, args: anytype) u64 { + var h = std.hash.Wyhash.init(@intFromPtr(&f)); + inline for (args) |a| h.update(std.mem.asBytes(&a)); + return h.final(); +} + fn call(comptime s: Site, a: ?std.mem.Allocator, comptime f: anytype, args: anytype, comptime yields: bool) @typeInfo(@TypeOf(f)).@"fn".return_type.? { const R = @typeInfo(@TypeOf(f)).@"fn".return_type.?; comptime { @@ -1059,6 +1091,7 @@ pub fn memory(gpa: std.mem.Allocator) Tape { /// What a tape in memory holds, given back (its core is gone already). pub fn release(t: *Tape) void { + t.answers.deinit(t.gpa); t.buf.deinit(t.gpa); t.scratch.deinit(); t.arena.deinit(); -- cgit v1.3