diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/replica.zig | 134 |
1 files changed, 83 insertions, 51 deletions
diff --git a/core/replica.zig b/core/replica.zig index 31a06214..92e49df5 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -562,8 +562,6 @@ pub const Stats = struct { speculated: u32 = 0, /// Stopped at a host call, a syscall or an emulator: waits one RTT. stopped: u32 = 0, - /// Not tried: an event of the view's (a resize, the pointer), phase 4's. - unspeculated: u32 = 0, /// The authority's unit was the pending head, recorded the same. fast: u32 = 0, /// The copy put back: the head recorded otherwise (a guess of the clock @@ -3008,6 +3006,9 @@ pub const Link = struct { /// waits a while after each). input_ns: u64 = 0, asked_ns: u64 = 0, + /// The clock those read, when not the machine's: a simulation's (the + /// soak's, test/replicas.zig), as `Echo.now` is. + now: ?u64 = null, /// How many of its own inputs the session recorded otherwise when it /// last drew: a frame after one that draws something is a rollback that /// may have been seen (counted so: an upper bound, the frame shows the @@ -3035,6 +3036,10 @@ pub const Link = struct { draws: u32 = 0, again: u32 = 0, + fn time(c: *const Link) u64 { + return c.now orelse nowNs(); + } + /// The test knobs the environment sets (PARDES_REPLICA_CHECK, /// PARDES_TEST_DIVERGE). pub fn fromEnv(c: *Link, gpa: Allocator, env: *const std.process.Environ.Map) !void { @@ -3079,7 +3084,7 @@ pub const Link = struct { pub fn input(c: *Link, ev: pardes.Event) void { // Its notice read: a key of its own puts it away. if (c.notice_len > 0 and (ev == .key or ev == .paste)) c.notice_len = 0; - c.input_ns = nowNs(); + c.input_ns = c.time(); const msg = c.r.input(ev) catch return; if (!sendInput(c.fd, msg)) c.cut(); c.dirty = true; @@ -3155,12 +3160,12 @@ pub const Link = struct { pub fn quietCheck(c: *Link) ?u32 { if (!c.changed or c.asked or !c.r.quiet()) return null; const quiet_ns = 300 * std.time.ns_per_ms; - const since = nowNs() -| @max(c.input_ns, c.asked_ns); + const since = c.time() -| @max(c.input_ns, c.asked_ns); if (since < quiet_ns) return @intCast((quiet_ns - since) / std.time.ns_per_ms + 1); c.changed = false; c.asked = askCheck(c.fd); if (!c.asked) c.cut(); - c.asked_ns = nowNs(); + c.asked_ns = c.time(); return null; } @@ -5247,7 +5252,10 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re /// The kinds of pane the walk below stands in: a file's, a plain kind's, /// a shell's raw (its program has the keys) and a shell's in normal mode /// (pardes's own keys over its history). `any` is a row's for all four. -const On = enum { any, file, kind, shell, shell_normal }; +/// `addon`: a kind whose state is its own on the session (a PDF's), which +/// the walk does not stand in (its Still has no search, place or word): +/// the soak's (test/replicas.zig) PDF and pictures are, judged by name. +const On = enum { any, file, kind, shell, shell_normal, addon }; /// What a far client may wait a round trip for (the user's line, P14: a /// side effect on the system may be slow; motions, edits and layout are @@ -5299,12 +5307,31 @@ const may_wait = [_]Wait{ .{ .what = "DumpConfig", .on = .any, .stop = "the authority's own state", .why = "the config file written" }, .{ .what = "ThemeFile *", .on = .any, .stop = "the authority's own state", .why = "a theme file, the session's" }, .{ .what = "DumpThemes", .on = .any, .stop = "the authority's own state", .why = "the theme files written" }, + // A search's rows: the session's worker or its loop writes them, and + // whether it has a worker is not the client's to know (12a); a + // +Preview's text is read from the session's disk. + .{ .what = "Search *", .on = .any, .stop = "search", .why = "a search's rows, the session's worker's" }, + .{ .what = "Search *", .on = .any, .stop = "preview", .why = "a +Preview's file, from the session's disk" }, + // A kind's own state on the session (a PDF's document): asking it. + .{ .what = "*", .on = .addon, .stop = "a kind's search", .why = "a search in a kind's pane: its own state, the session's" }, + .{ .what = "*", .on = .addon, .stop = "a kind's address", .why = "a place in a kind's pane (`Look doc.pdf:3`): its own state" }, + .{ .what = "*", .on = .addon, .stop = "a kind's close", .why = "a kind's pane closed: its state let go on the session" }, + .{ .what = "*", .on = .addon, .stop = "a kind's word", .why = "a word to a kind (a key it takes as one): its own state" }, + .{ .what = "*", .on = .addon, .stop = "a kind's open", .why = "a kind's pane opened (`Life`): its state made on the session" }, } ++ (if (pardes.platform == .gui) [_]Wait{ // A window's view (the font words are a window's). .{ .what = "Font *", .on = .any, .stop = "fonts", .why = "the session's machine's fonts, its disk" }, .{ .what = "Fonts", .on = .any, .stop = "fonts", .why = "the session's machine's fonts, its disk" }, } else [_]Wait{}); +/// Whether a stop of that name (`Tape.poisoned_by`) is one `may_wait` +/// lists for something: the soak's (test/replicas.zig) judge of its +/// clients' inputs, which it cannot name as the walk does. +pub fn mayWait(stop: []const u8) bool { + for (may_wait) |row| if (std.mem.eql(u8, row.stop, stop)) return true; + return false; +} + /// The keys the walk types: every printable one, and the specials a /// frontend reads; each plain, with Ctrl and with Alt. const walk_keys = keys: { @@ -5374,53 +5401,58 @@ fn keyName(buf: []u8, k: pardes.Key) []const u8 { return std.fmt.bufPrint(buf, "{s}{u}", .{ mod, k.cp }) catch unreachable; } -/// A session's host with every entry a step may ask, each doing nothing: -/// a client's step stops, or goes on, as against a real session's (a -/// client's tape offers only the entries its session's host has). The -/// loop's own (`now`, `wait_input`, the frame's) no step asks. -const FullHost = struct { - fn Noop(comptime F: type) type { - const info = @typeInfo(@typeInfo(@typeInfo(F).optional.child).pointer.child).@"fn"; - const R = info.return_type.?; - const P = info.param_types; - return switch (P.len) { - 1 => struct { - fn f(_: ?*anyopaque) R { - return std.mem.zeroes(R); - } - }, - 2 => struct { - fn f(_: ?*anyopaque, _: P[1].?) R { - return std.mem.zeroes(R); - } - }, - 3 => struct { - fn f(_: ?*anyopaque, _: P[1].?, _: P[2].?) R { - return std.mem.zeroes(R); - } - }, - 4 => struct { - fn f(_: ?*anyopaque, _: P[1].?, _: P[2].?, _: P[3].?) R { - return std.mem.zeroes(R); - } - }, - 5 => struct { - fn f(_: ?*anyopaque, _: P[1].?, _: P[2].?, _: P[3].?, _: P[4].?) R { - return std.mem.zeroes(R); - } - }, - else => @compileError("a host entry of more arguments"), - }; - } - const vtable = table: { - var v: pardes.Host.VTable = .{}; - for (@typeInfo(pardes.Host.VTable).@"struct".field_names) |name| { - if (std.mem.eql(u8, name, "now") or std.mem.eql(u8, name, "wait_input") or std.mem.eql(u8, name, "present") or - std.mem.eql(u8, name, "post_present") or std.mem.eql(u8, name, "poll_frame")) continue; - @field(v, name) = &Noop(@FieldType(pardes.Host.VTable, name)).f; +/// `v` with every entry a step may ask that it leaves out doing nothing +/// (answering zero): a client's step stops, or goes on, as against a real +/// session's (a client's tape offers only the entries its session's host +/// has). The loop's own (`now`, `wait_input`, the frame's) no step asks. +pub fn everyEntry(comptime v: pardes.Host.VTable) pardes.Host.VTable { + const Noop = struct { + fn Of(comptime F: type) type { + const info = @typeInfo(@typeInfo(@typeInfo(F).optional.child).pointer.child).@"fn"; + const R = info.return_type.?; + const P = info.param_types; + return switch (P.len) { + 1 => struct { + fn f(_: ?*anyopaque) R { + return std.mem.zeroes(R); + } + }, + 2 => struct { + fn f(_: ?*anyopaque, _: P[1].?) R { + return std.mem.zeroes(R); + } + }, + 3 => struct { + fn f(_: ?*anyopaque, _: P[1].?, _: P[2].?) R { + return std.mem.zeroes(R); + } + }, + 4 => struct { + fn f(_: ?*anyopaque, _: P[1].?, _: P[2].?, _: P[3].?) R { + return std.mem.zeroes(R); + } + }, + 5 => struct { + fn f(_: ?*anyopaque, _: P[1].?, _: P[2].?, _: P[3].?, _: P[4].?) R { + return std.mem.zeroes(R); + } + }, + else => @compileError("a host entry of more arguments"), + }; } - break :table v; }; + var all = v; + for (@typeInfo(pardes.Host.VTable).@"struct".field_names) |name| { + if (std.mem.eql(u8, name, "now") or std.mem.eql(u8, name, "wait_input") or std.mem.eql(u8, name, "present") or + std.mem.eql(u8, name, "post_present") or std.mem.eql(u8, name, "poll_frame")) continue; + if (@field(all, name) == null) @field(all, name) = &Noop.Of(@FieldType(pardes.Host.VTable, name)).f; + } + return all; +} + +/// A session's host with every entry a step may ask, each doing nothing. +const FullHost = struct { + const vtable = everyEntry(.{}); fn host() pardes.Host { return .{ .vtable = &vtable }; } |
