diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 00:03:29 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 00:03:29 -0300 |
| commit | 3a3601f984d25f1e03cee3ac47da7eeb2548e511 (patch) | |
| tree | 445331cb8ad346989c4e4f6a3ceff54411064e4a | |
| parent | 8a1f65a2d374796b9b5559c4aab87c8d1e8f6e68 (diff) | |
| parent | 528530ed065b2059d16b08efd92103d1dbbccc31 (diff) | |
| download | pardes-3a3601f984d25f1e03cee3ac47da7eeb2548e511.tar.gz pardes-3a3601f984d25f1e03cee3ac47da7eeb2548e511.zip | |
integration: a far client's seven small faults on the renamed tree: pardes-far-faults (a refocus that no longer asks the session's host about a newer build; a drag in a kind's pane grown too short; a draw's token that no rollback takes back; a text's declarations dumped so a joined client's query reads what the session's does; a search that goes on at once on a far client; two tests of what cannot happen) and pardes-merge24, merged without a textual conflict; the coordinator's gate in the ledger (reorg/merge25)
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | core/Core.zig | 6 | ||||
| -rw-r--r-- | core/Effect.zig | 2 | ||||
| -rw-r--r-- | core/File.zig | 18 | ||||
| -rw-r--r-- | core/Kind.zig | 17 | ||||
| -rw-r--r-- | core/Messages.zig | 3 | ||||
| -rw-r--r-- | core/Query.zig | 34 | ||||
| -rw-r--r-- | core/Stream.zig | 34 | ||||
| -rw-r--r-- | core/dump.zig | 12 | ||||
| -rw-r--r-- | core/mouse.zig | 7 | ||||
| -rw-r--r-- | core/replica.zig | 492 | ||||
| -rw-r--r-- | core/root.zig | 12 | ||||
| -rw-r--r-- | core/tape.zig | 4 | ||||
| -rw-r--r-- | dev/Host.zig | 3 | ||||
| -rw-r--r-- | dev/gui/gui.zig | 2 | ||||
| -rw-r--r-- | dev/tui/tui.zig | 14 | ||||
| -rw-r--r-- | runtime/upgrade.zig | 6 |
16 files changed, 571 insertions, 95 deletions
diff --git a/core/Core.zig b/core/Core.zig index b109b073..351c3626 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -72,7 +72,6 @@ const lsp = pardes.lsp; const memory = pardes.memory; const modal = pardes.modal; const mouse = pardes.mouse; -const newer_build_words = pardes.newer_build_words; const platform = pardes.platform; const recent_files = @import("recent.zig"); const sel_slot = pardes.sel_slot; @@ -1704,10 +1703,7 @@ fn updateInner(p: *Pardes, ev: Event) void { edit.applyPaste(p, bytes) catch |err| p.reportError(.at(v.active), "paste", err); }, .command => |line| _ = p.executeBuiltinLine(v.active, line), - .focus => |focused| { - v.window_focused = focused; - if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(.at(v.active), newer_build_words); - }, + .focus => |focused| v.window_focused = focused, .handed => |h| p.handover.finish(p, h.seq, h.to, h.failure), .addon => |a| pardes.Addon.landed(p, a.op, a.pane.index(), a.kind.*), .job => |j| pardes.Kind.jobDone(p, j.pane.index(), j.serial, j.token, j.gen, j.bytes), diff --git a/core/Effect.zig b/core/Effect.zig index 7475cc84..5e821065 100644 --- a/core/Effect.zig +++ b/core/Effect.zig @@ -218,7 +218,7 @@ fn performInner(p: *Pardes, e: Effect) void { else p.update(.{ .pipe_resp = .{ .id = q.id, .success = false, .outputs = &.{} } }), // No workers here (a test, a board): it runs on the loop. - .search => |q| if (v.search) |f| f(p.host.ctx, q.gen) else Stream.runHere(p, q.gen), + .search => |q| if (v.search) |f| f(p.host.ctx, q.gen) else Stream.runHere(p, q.gen, false), // No windows here (a test, the tty): it stays. .hand_over => |h| if (v.hand_over) |f| { if (p.handover.bytes) |bytes| f(p.host.ctx, h.seq, bytes); diff --git a/core/File.zig b/core/File.zig index 020985da..75d8049b 100644 --- a/core/File.zig +++ b/core/File.zig @@ -59,8 +59,13 @@ pub const History = struct { } }; -/// Owned syntax results. Excluded from dumps as State.context is derived. +/// Owned syntax results: a text's declarations at a revision. pub const ContextCache = struct { + /// Its revision is dumped and digested: a worker's parse is an input, + /// which a client joined since never saw, and a step reads what it + /// left (Query.ownerDecls). The declarations are made again from the + /// text at a load (`reload`), with the allocator that made them. + pub const replica = .{ .local = .{"allocator"}, .derived = .{"declarations"} }; allocator: ?std.mem.Allocator = null, declarations: []syntax.ContextDeclaration = &.{}, revision: ?u32 = null, @@ -70,6 +75,15 @@ pub const ContextCache = struct { self.* = .{}; } + /// A loaded text's (its revision the dump's): its declarations parsed + /// again where they are of the text it has. + pub fn reload(self: *ContextCache, gpa: std.mem.Allocator, path: []const u8, content: []const u8, revision: u32) void { + const at = self.revision orelse return; + if (at != revision) return; + const declarations = syntax.contextDeclarations(gpa, path, content) catch return; + self.replace(gpa, declarations, at); + } + /// Takes ownership of declarations allocated by gpa. pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, declarations: []syntax.ContextDeclaration, revision: u32) void { self.deinit(); @@ -83,7 +97,7 @@ pub const State = struct { /// from the text whenever it is wanted. // Syntax caches must not load through the dump loader's core allocator. pub const replica = .{ - .derived = .{ "cap", "line_starts", "line_cap", "highlights", "highlight_start", "syntax_dirty", "context", "node_tree", "node_tree_revision", "node_tree_edits", "node_history", "tables" }, + .derived = .{ "cap", "line_starts", "line_cap", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_tree_edits", "node_history", "tables" }, // Big texts, dumped and sent by their hash (core/walk.zig). The // text is written in place by `replace`, but never while a join // sends it (memory.zig `pin`): then an edit puts a new buffer in diff --git a/core/Kind.zig b/core/Kind.zig index 7641c2d1..81997afb 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -136,7 +136,7 @@ pub const Slot = struct { // jobs' inputs, its file's hash, a placeholder's record), and what // a frame makes (the thumb, the pointer, whether one was drawn: a // view's, never a step's). - .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used", "draws" }, + .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used" }, }; /// Its kind's code here; null in a placeholder (`live` false: its kind /// not in the registry, its record kept for the day it comes) or a @@ -198,11 +198,6 @@ pub const Slot = struct { /// whether a frame was painted since its last tick. pointer: u8 = 0, painted: bool = false, - /// The last of its draws' tokens (api.draw), each its own process's: a - /// draw is a frame's, and how many frames each process paints differs, - /// so it is in no digest; the copy holds it with the slot. A kind - /// keeping one in its state (PA_PLAIN) is caught at that call's digest. - draws: u32 = 0, /// Each view's facts (a hash of its pa_view) as `view` was last told /// them, 0 for none: a change tells it again. views: [views.max]u64 = @splat(0), @@ -1220,8 +1215,8 @@ pub const api: c.pa_api = .{ heap.free(copy); return 0; }; - cl.slot.draws = (cl.slot.draws +% 1) & ~c.PA_DRAWN; - const token = c.PA_DRAWN | cl.slot.draws; + drawn = (drawn +% 1) & ~c.PA_DRAWN; + const token = c.PA_DRAWN | drawn; j.* = .{ .gpa = heap, .pane = @intCast(cl.id), .serial = pane.serial, .token = token, .gen = cl.slot.gen, .ops = ops, .in = copy, .arena = .init(heap), .draw = p }; Addon.holdJob(ops, true); if (drawer) |d| if (d.go(d.ctx, j)) return token; @@ -1250,6 +1245,12 @@ pub const api: c.pa_api = .{ pub var drawer: ?struct { ctx: ?*anyopaque, go: *const fn (ctx: ?*anyopaque, j: *host_io.KindJob) bool } = null; /// Draws done, each kept for its pane's next paint (the loop's alone). var ready: std.ArrayListUnmanaged(*host_io.KindJob) = .empty; +/// The last token a draw was given: a draw is a frame's, this process's, in +/// no digest and no copy (a kind keeping one in its PA_PLAIN state is +/// caught at that call's digest). A rollback takes a slot back, never this, +/// so no draw is given the token a discarded speculation's frame was, whose +/// answer may come after. +var drawn: u32 = 0; /// A draw done on a worker, back on the loop: kept for its pane's next /// paint, a frame owed. One of another core's (a client joined again diff --git a/core/Messages.zig b/core/Messages.zig index 1fb232c7..46dab136 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -76,7 +76,8 @@ pub const Message = struct { extern "c" fn localtime_r(timep: *const libc.time_t, result: *Tm) ?*Tm; /// PARDES_NOTIME set (the tests, a snapshot run): every clock reads - /// `--:--:--`. + /// `--:--:--`. A host's (`stamp`, dev/lsp): no step reads it, the text + /// it stamps crossing as a setMessage's. pub fn noTime() bool { const v = libc.getenv("PARDES_NOTIME") orelse return false; return std.mem.span(v).len != 0; diff --git a/core/Query.zig b/core/Query.zig index 0cecb93e..704206e6 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -754,7 +754,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz const oid = owner_id orelse return; const owner = p.panes[oid].?; const f = if (owner.file) |*file| file else return; - const decls = ownerDecls(p, f, false) orelse { + const decls = ownerDecls(f) orelse { // Parsed on the worker; listed when it is done (declsArrived). Stream.parseFor(p, oid); return; @@ -782,31 +782,15 @@ fn recentRows(p: *Pardes, out: *std.Io.Writer.Allocating) []const u8 { return out.written(); } -/// The owner's declarations, from a parse that already exists: its sticky -/// headers' (TreeContext) at this revision, or the locations cache's. None -/// is made here, on the loop, unless `small` and the text is small: a -/// tree-sitter parse of a 1.2 MB file is seconds in a Debug build. -/// ponytail: no grouping for a big file until the disk engine's worker -/// parses it (phase 4). -fn ownerDecls(p: *Pardes, f: *File.State, small: bool) ?[]const syntax.ContextDeclaration { +/// The owner's declarations, from its parse at this revision (its context: +/// sticky headers' (TreeContext), a worker's answer, a dump's load), or +/// none: never the locations cache's (a Diff's), which a client joined +/// since has not, nor a parse made here (Stream.parseFor asks one). +fn ownerDecls(f: *const File.State) ?[]const syntax.ContextDeclaration { if (f.context.revision) |rev| if (rev == f.revision and f.context.declarations.len > 0) return f.context.declarations; - const cache = &p.locations_cache; - for (cache.entries[0..cache.len]) |entry| { - if (entry.declarations_ready and std.mem.eql(u8, entry.path, f.path) and std.mem.eql(u8, entry.source, f.content)) return entry.analysis.declarations; - } - if (!small or f.content.len > small_parse_bytes or !syntax.supportsPath(f.path)) return null; - var got = p.locations_cache.get(p.tree_sitter_gpa, f.path, f.content, true, false) catch return null; - if (got.owned) { - got.deinit(p.tree_sitter_gpa); - return null; - } - return got.analysis.declarations; + return null; } -/// A text this small is parsed on the loop for its declarations when a -/// Symbols query asks (about 40 ms in a Debug build). -const small_parse_bytes = 64 << 10; - /// The rows as `note` says, and nothing else: no hits. fn noteRows(p: *Pardes, id: usize, note: []const u8) void { const rp = p.panes[id].?; @@ -1043,7 +1027,7 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar const rel = lookPath(&relbuf, path, dir); const width = addressWidth(rel, index.len); var sh: Shades = .{}; - const decls = ownerDecls(p, f, false) orelse &.{}; + const decls = ownerDecls(f) orelse &.{}; var decl_now: ?usize = null; var i: usize = @min(from, hits.len); // the line of the first, found in the index @@ -1107,7 +1091,7 @@ fn makeTextRows(p: *Pardes, id: usize, oid: usize, full: bool) !void { var rows: std.ArrayList(locations.Row) = .empty; var budget: usize = if (full) max_rows else live_rows; // Grouped once a parse of the text exists: asked of the worker now. - if (ownerDecls(p, &owner.file.?, false) == null) Stream.parseFor(p, oid); + if (ownerDecls(&owner.file.?) == null) Stream.parseFor(p, oid); const at = set.current orelse (if (set.seek) |s| Places.firstFrom(set.hits.items, s) else 0); // While typed, a window of rows from just before the current place, so // it sits under line 1. diff --git a/core/Stream.zig b/core/Stream.zig index 74c8128a..5960d249 100644 --- a/core/Stream.zig +++ b/core/Stream.zig @@ -559,7 +559,7 @@ pub fn step(p: *Pardes) void { s.state = .searching; // A script's write (whose answer says whether it found anything) and a // host with no workers: done before this returns. - if (p.host.vtable.search != null and !p.fs.serving) p.emit(.{ .search = .{ .gen = s.gen } }) else runHere(p, s.gen); + if (p.host.vtable.search != null and !p.fs.serving) p.emit(.{ .search = .{ .gen = s.gen } }) else runHere(p, s.gen, false); } /// When the core next needs a tick for the stream: the end of the pause. @@ -576,12 +576,8 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, p: *Pardes, gen: u32, ctx: ?*an if (gen & paint_bit != 0) { for ([_]*?TextTask{ &s.paint, &s.rows_paint }) |slot| if (slot.*) |*t| if (t.job.gen == gen and t.future == null) { t.job.out = gpa; - t.future = io.concurrent(paintWork, .{ io, t.job, ctx, sink }) catch { - const job = t.job; - slot.* = null; - job.deinit(); - return; - }; + // No worker to be had: let go as runHere does, by an input. + t.future = io.concurrent(paintWork, .{ io, t.job, ctx, sink }) catch return runHere(p, gen, true); t.io = io; }; return; @@ -589,12 +585,9 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, p: *Pardes, gen: u32, ctx: ?*an // A parse's generation: its own task. if (s.parse) |*t| if (gen == s.parse_gen and t.job.gen == gen and t.future == null) { t.job.out = gpa; - t.future = io.concurrent(parseWork, .{ io, t.job, ctx, sink }) catch { - const job = t.job; - s.parse = null; - job.deinit(); - return; - }; + // No worker to be had: let go by an input, a parse that found none. + t.future = io.concurrent(parseWork, .{ io, t.job, ctx, sink }) catch + return p.update(.{ .search = .{ .gen = gen, .parsed = .{ .serial = t.job.serial, .revision = t.job.revision } } }); t.io = io; return; }; @@ -607,7 +600,7 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, p: *Pardes, gen: u32, ctx: ?*an const future = io.concurrent(work, .{ io, job, ctx, sink }) catch { // No worker to be had: it runs here, on the loop. job.deinit(); - return runHere(p, gen); + return runHere(p, gen, true); }; s.task = .{ .job = job, .future = future, .io = io }; } @@ -625,13 +618,18 @@ fn makeJob(gpa: std.mem.Allocator, s: *const Stream) !*Job { /// A host with no workers (a test's, the fallback when none can be had): /// the whole search on the loop, the turn out for it, its batches taken in -/// as a worker's would be. Its cap is a hard stop. -pub fn runHere(p: *Pardes, gen: u32) void { +/// as a worker's would be. Its cap is a hard stop. `in_call`: run in the +/// host's `search` entry, where what it wrote into the core would be in no +/// record: each batch handed in as a worker's is, an input the tape records +/// and every replica takes. +pub fn runHere(p: *Pardes, gen: u32, comptime in_call: bool) void { // A paint with no worker to run it (a shell not threaded yet): let go, - // never left to hold its slot; the rows or the view ask again. + // never left to hold its slot; the rows or the view ask again. In a + // host's call, by an input: a worker's answer of nothing. if (gen & paint_bit != 0) { const s = &p.stream; for ([_]*?TextTask{ &s.paint, &s.rows_paint }) |slot| if (slot.*) |t| if (t.job.gen == gen and t.future == null) { + if (in_call) return p.update(.{ .search = .{ .gen = gen, .end = .done, .painted = .{ .serial = t.job.serial, .revision = t.job.revision, .start = t.job.start } } }); slot.* = null; t.job.deinit(); }; @@ -655,7 +653,7 @@ pub fn runHere(p: *Pardes, gen: u32) void { const batches = p.tape.site(.search, p.gpa, searchHere, .{ p.gpa, job }); defer p.gpa.free(batches); for (batches) |*b| { - receive(p, b); + if (in_call) p.update(.{ .search = b.* }) else receive(p, b); b.deinit(p.gpa); } } diff --git a/core/dump.zig b/core/dump.zig index a8dd170a..e6cdceec 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -406,6 +406,7 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: for (others) |o| gpa.free(o.panes); gpa.free(others); l.shared.shrinkRetainingCapacity(at); + for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| f.context.reload(p.tree_sitter_gpa, f.path, f.content, f.revision); p.readSessionFacts(); return p; } @@ -491,6 +492,7 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* try views.undumpedOld(p, others, gpa); } l.made.shrinkRetainingCapacity(at); + for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| f.context.reload(p.tree_sitter_gpa, f.path, f.content, f.revision); p.readSessionFacts(); return p; } @@ -1200,7 +1202,7 @@ test "an old dump's file, a byte dump, is read by -l and by a Restore of its pat try std.testing.expectEqualSlices(u8, bytes, again); } -test "restored syntax context caches are rebuilt rather than loaded with the core allocator" { +test "restored syntax context caches are rebuilt from the text rather than loaded with the core allocator" { const gpa = std.testing.allocator; var syntax_gpa: std.heap.DebugAllocator(.{}) = .init; defer std.testing.expect(syntax_gpa.deinit() == .ok) catch @panic("syntax allocator leaked"); @@ -1237,9 +1239,13 @@ test "restored syntax context caches are rebuilt rather than loaded with the cor defer gpa.free(bytes); const q = try load(gpa, opts, bytes, null); defer q.deinit(); + // This build's: the revision kept, the declarations parsed again from + // the text, with the syntax allocator. + const want = try pardes.syntax.contextDeclarations(syntax_gpa.allocator(), f.path, f.content); + defer syntax_gpa.allocator().free(want); for (q.panes) |slot| if (slot) |restored| if (restored.file) |file| { - try std.testing.expectEqual(@as(usize, 0), file.context.declarations.len); - try std.testing.expectEqual(@as(?u32, null), file.context.revision); + try std.testing.expectEqual(f.context.revision, file.context.revision); + try std.testing.expectEqualSlices(pardes.syntax.ContextDeclaration, want, file.context.declarations); }; } diff --git a/core/mouse.zig b/core/mouse.zig index cefc0335..cdf4892e 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -247,8 +247,11 @@ fn kindMouse(p: *Pardes, m: Mouse) bool { if (m.kind == .press) v.active = id; if (m.kind == .press and m.button != .wheel_up and m.button != .wheel_down and m.button != .wheel_left and m.button != .wheel_right) v.kind_grab = @intCast(id); if (m.kind == .release) v.kind_grab = null; - const col = std.math.clamp(m.col, x0, r.x + r.w -| 1) - x0; - const row = std.math.clamp(m.row, top, r.y + r.h -| 1) - top; + // Grabbed, it may be anywhere, and the pane since made too narrow + // or short for a cell of body (a resize, a pane added above): its + // body's last cell, the first of none. + const col = @min(m.col -| x0, (r.x + r.w) -| x0 -| 1); + const row = @min(m.row -| top, (r.y + r.h) -| top -| 1); return pardes.Kind.mouse(p, id, m, col, row); } kindLeave(p); diff --git a/core/replica.zig b/core/replica.zig index c68848f2..3aeb21af 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -5342,7 +5342,6 @@ const may_wait = [_]Wait{ .{ .what = "Dump", .on = .any, .stop = "write_dump", .why = "a dump written" }, .{ .what = "Upgrade", .on = .any, .stop = "upgrade", .why = "the session execs itself" }, .{ .what = "Detach", .on = .any, .stop = "detach", .why = "the session lets its frontend go" }, - .{ .what = "focus lost and found", .on = .any, .stop = "newer_build", .why = "a window found again asks whether a newer build is installed: the session's disk" }, // What the session alone holds: its closed panes, Recent and History // (every session of its user writes them), the config and theme files. .{ .what = "Restore", .on = .any, .stop = "the authority's own state", .why = "the session's dumps" }, @@ -5354,10 +5353,7 @@ 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" }, + // A +Preview's text is read from the session's disk. .{ .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" }, @@ -5884,3 +5880,489 @@ test "an idle client's check answered covers the units that came while it was as c.take(.{ .checked = digestOf(a) }); try std.testing.expect(!c.asked and c.changed); } + +// A window's keyboard found again asked the session's host whether a newer +// pardes is installed, in the core's focus step: a client's refocus waited +// a round trip for a question about the session's binary that its own +// window has nothing to do with. Each process's build is its own frontend's +// to look at, at its own focus-in (upgrade.noticeNewer). +test "a far client's window found again is instant: its refocus asks the session's host nothing, and the session's unit confirms it" { + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, FullHost.host(), false); + defer a.deinit(); + const r = try joinedFresh(a); + defer r.deinit(); + for ([_]bool{ false, true }) |focused| { + const msg = try gpa.dupe(u8, try r.input(.{ .focus = focused })); + defer gpa.free(msg); + try std.testing.expectEqual(@as(usize, 1), r.applied); + r.confirm(try a.take(msg)); + r.settle(); + try agrees(a, r); + } + try std.testing.expectEqual(@as(u32, 0), r.stats.stopped); + try std.testing.expectEqual(@as(u32, 2), r.stats.fast); +} + +/// Kind `ops`'s code in the client for its pane `id`, as a client that +/// has its library runs it (initDump: Addon.plainOps, dump.plainHere). +fn runsHere(r: *Replica, id: usize, ops: *const pardes.Kind.Ops) !void { + const was = Stepping.begin(&r.t, &r.epoch); + defer was.end(); + const c = r.core(); + const slot = c.panes[id].?.addon.?; + c.kinds.ops[c.kinds.byName(slot.nameOf()).?] = ops; + c.panes[id].?.addon = try pardes.dump.plainHere(c, id, slot, ops); +} + +/// A plain kind that takes the mouse (normal mode has its keys). +const Pointed = struct { + const pa = pardes.Kind.c; + fn mouse(_: ?*anyopaque, _: [*c]const pa.pa_mouse) callconv(.c) c_int { + return 1; + } + const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Pointed", .opens = 1, .doc = "a pane that takes the mouse" })}; + const ops = std.mem.zeroInit(pardes.Kind.Ops, .{ + .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "pointed".* ++ @as([9]u8, @splat(0)), .version = 1, .exts = "", .flags = pa.PA_PLAIN, .words = &words, .nwords = 1 }), + .open = Still.open, + .paint = Still.paint, + .mouse = mouse, + }); +}; + +// A press grabs a kind's pane (the drag and release after it are the +// kind's wherever they land); a step between can leave that pane too +// short for a row of body, and the drag's row clamped into an empty range +// tripped std.math.clamp's assertion (the soak, once, at rtt 207, in a +// client's speculation). +test "a far client's drag in a kind's pane it grabbed, the pane since too short for a row of body: the kind is told its edge, at once and as on the session" { + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + defer a.deinit(); + var words: [64]pardes.Kind.LoadedWord = undefined; + const pointed = pardes.Kind.loadedOf(&Pointed.ops, "/x/pointed.so", @splat(8), &words); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &pointed } }); + _ = try a.local(.{ .command = "Pointed" }); + const kid = a.core.view().active; + const r = try joinedFresh(a); + defer r.deinit(); + try runsHere(r, kid, &Pointed.ops); + const rect = r.core().view().rects[kid]; + const col = rect.x + 4; + const row = rect.y + r.core().panes[kid].?.tag_rows + 1; + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + for ([_]pardes.Event{ + .{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row } }, + .{ .resize = .{ .cols = 80, .rows = 4 } }, + .{ .mouse = .{ .button = .left, .kind = .drag, .col = col, .row = 30 } }, + .{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = 30 } }, + }) |ev| { + try sent.append(gpa, try gpa.dupe(u8, try r.input(ev))); + } + try std.testing.expectEqual(@as(u16, 1), r.core().view().rects[kid].h); + try std.testing.expectEqual(@as(u32, 0), r.stats.stopped); + for (sent.items) |m| { + r.confirm(try a.take(m)); + r.settle(); + } + try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); + try agrees(a, r); +} + +// A draw's token is its slot's count of draws, which the rollback copy +// holds with the slot: a frame drawn under a speculation asks token T, the +// rollback takes the count back, and the next frame's draw (of the state +// the replay came to) is given T again. Its answer and the discarded one's +// both come to job_done as T, in the order the workers finish. +test "a far client's frame drawn under a speculation that rolls back asks a picture whose token the next draw is never given again: the kind keeps the picture of the state it shows" { + // A plain kind whose picture is a draw of its count (api.draw from its + // paint, when the picture asked for is of another count), its answer kept + // for the token it asked last, once: a kind with one draw outstanding. + // What it shows is this process's (a kind's own memory, never its block). + const Drawn = struct { + const pa = pardes.Kind.c; + var want: u32 = 0; + var asked: ?u32 = null; + var shown: ?u32 = null; + fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { + const n: *u32 = @ptrCast(@alignCast(pardes.Kind.api.alloc.?(4))); + n.* = 0; + return n; + } + fn paint(st: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void { + const n: *const u32 = @ptrCast(@alignCast(st.?)); + if (asked == n.*) return; + asked = n.*; + want = pardes.Kind.api.draw.?(n, 4); + } + fn press(st: ?*anyopaque, _: [*c]const pa.pa_key) callconv(.c) c_int { + const n: *u32 = @ptrCast(@alignCast(st.?)); + n.* = n.* * 2 + 1; + return 1; + } + fn jobRun(in: [*c]const u8, n: u32, out: [*c]pa.pa_out) callconv(.c) u32 { + const o: [*]u8 = @ptrCast(out.*.alloc.?(out, n) orelse return 0); + @memcpy(o[0..n], in[0..n]); + return n; + } + fn jobDone(_: ?*anyopaque, token: u32, out: [*c]const u8, n: u32) callconv(.c) void { + if (token != want or n != 4) return; + want = 0; + shown = std.mem.readInt(u32, out[0..4], .little); + } + const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Drawn", .opens = 1, .doc = "a picture of a count" })}; + const ops = std.mem.zeroInit(pardes.Kind.Ops, .{ + .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "drawn".* ++ @as([11]u8, @splat(0)), .version = 1, .exts = "", .flags = pa.PA_PLAIN, .words = &words, .nwords = 1 }), + .open = open, + .paint = paint, + .key = press, + .job_run = jobRun, + .job_done = jobDone, + }); + }; + + // A frontend's workers for draws, run when the test says, each landing + // when it says (host_io.KindJob: run on a worker, landed on the loop). + const HeldDraws = struct { + var held: [4]*@import("dev").host_io.KindJob = undefined; + var n: usize = 0; + fn go(_: ?*anyopaque, j: *@import("dev").host_io.KindJob) bool { + j.run(); + held[n] = j; + n += 1; + return true; + } + }; + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + defer a.deinit(); + var words: [64]pardes.Kind.LoadedWord = undefined; + const drawn = pardes.Kind.loadedOf(&Drawn.ops, "/x/drawn.so", @splat(9), &words); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &drawn } }); + _ = try a.local(.{ .command = "Drawn" }); + const kid = a.core.view().active; + const r = try joinedFresh(a); + defer r.deinit(); + try runsHere(r, kid, &Drawn.ops); + Drawn.want = 0; + Drawn.asked = null; + Drawn.shown = null; + HeldDraws.n = 0; + const was = pardes.Kind.drawer; + pardes.Kind.drawer = .{ .ctx = null, .go = HeldDraws.go }; + defer pardes.Kind.drawer = was; + const none: pardes.views.Present = .{ .ctx = null, .f = null }; + // Its own key: 0 -> 1, drawn (a picture of 1 asked). + const msg = try gpa.dupe(u8, try r.input(.{ .key = .{ .cp = 'x', .text = "x" } })); + defer gpa.free(msg); + _ = r.draw(none); + try std.testing.expectEqual(@as(?u32, 1), Drawn.asked); + // The session's own key first: rolled back, its own applied again on + // top (0 -> 1 -> 3), drawn (a picture of 3 asked). + r.confirm(try a.own(.{ .key = .{ .cp = 'x', .text = "x" } })); + r.settle(); + _ = r.draw(none); + try std.testing.expectEqual(@as(?u32, 3), Drawn.asked); + try std.testing.expectEqual(@as(usize, 2), HeldDraws.n); + // The discarded picture's worker done first, then the other's; a frame. + for (HeldDraws.held[0..2]) |j| pardes.Kind.landDraw(r.core(), j); + _ = r.draw(none); + try std.testing.expectEqual(@as(?u32, 3), Drawn.shown); + r.confirm(try a.take(msg)); + r.settle(); + try agrees(a, r); +} + +// A program that asked for focus events is told of a click into its shell +// by the session's step (Core.reportFocus): a client's own step writes +// nothing. Where the shell's queue is backed up (a 9P write past what the +// effects ring holds, parked until the session's next pump), the session's +// report parks behind it, into `pending_write`, which is digested, where +// the client's speculation skips the write. It cannot differ: a client's +// step settles as the session's does, draining the queue, and what is +// parked is a write into the shell, which stops it (the client holds the +// same queue: the unit that parked it is the session's, which it replays). +test "a far client's click into a shell whose queue is backed up: the session's focus report queues behind what is parked, and the client ends as the session does" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const gpa = std.testing.allocator; + const Told = struct { + var bytes: usize = 0; + var tail: [3]u8 = @splat(0); + fn write(_: ?*anyopaque, _: pardes.Pane.Id, b: []const u8) void { + bytes += b.len; + if (b.len >= 3) @memcpy(&tail, b[b.len - 3 ..]); + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_write = write }; + }; + const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, .{ .vtable = &Told.vtable }, true); + defer a.deinit(); + const shell: u8 = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.isTerminal()) break @intCast(id); + } else return error.NoShell; + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } }); + _ = (try a.pending()).?; + _ = try a.local(.{ .command = "New" }); + var screens: Screens = .init(gpa); + defer screens.deinit(a.core); + const peer = try screens.addPeer(); + const r = try joinedFresh(a); + defer r.deinit(); + try deliver(a, &screens, peer, r, .flush); + r.settle(); + // A 9P write into the shell, past the ring: the rest parked, on both. + const big = try gpa.alloc(u8, pardes.memory.limits.effect_cap * pardes.effect_write_cap + 100); + defer gpa.free(big); + @memset(big, 'x'); + { + const was = Stepping.begin(&a.t, null); + defer was.end(); + _ = a.core.serveFs(.{ .tag = 1, .op = .write, .node = pardes.ctlfs.Node.of(a.core.panes[shell].?.serial, .pty_data), .data = big }); + } + a.seq += 1; + r.confirm(try a.unit(0, a.seq)); + r.settle(); + try std.testing.expect(a.core.pending_write[shell] != null and r.core().pending_write[shell] != null); + Told.bytes = 0; + const rect = r.core().view().rects[shell]; + const row = rect.y + r.core().panes[shell].?.tag_rows + 1; + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + r.stats.stops = @splat(.{}); + for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .mouse = .{ .button = .left, .kind = kind, .col = rect.x + 2, .row = row } }))); + // The client's own step drains the queue it holds as the session's + // does: what is parked is a write into the shell, so it stops there, + // and waits for the session's step, focus report and all. + try std.testing.expectEqual(@as(usize, 0), r.applied); + for (r.stats.stops) |st| if (st.n > 0) try std.testing.expectEqualStrings("pty_write", st.name); + for (sent.items) |m| { + try deliver(a, &screens, peer, r, .flush); + const u = try gpa.dupe(u8, try a.take(m)); + defer gpa.free(u); + try deliver(a, &screens, peer, r, .fill); + r.confirm(u); + r.settle(); + } + // The program had what was parked, then the focus. + try std.testing.expectEqual(big.len + 3, Told.bytes); + try std.testing.expectEqualStrings("\x1b[I", &Told.tail); + try std.testing.expectEqual(@as(usize, shell), r.core().view().active); + try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); + try agrees(a, r); +} + +// A `/` in a file groups its rows under the declarations they are in once +// a parse of the text exists (Query.ownerDecls): the pane's context, a +// worker's answer, or the locations cache's (a Diff's). Both were kept out +// of the dump as made again from the text, so a client joined since had +// neither, and its replay of the session's next row asked a parse the +// session never asked: the context is dumped now, the cache's no longer read. +test "a client joined from a dump makes a `/` query's rows as the session does, though only the session has the owner's declarations from a worker's parse" { + // A session's host whose parses and searches run on a worker (a tty's, + // Stream.start), their batches posted to an inbox; `land` hands them to + // the core as the session's inputs, as its loop does. + const WorkerSearch = struct { + const Inbox = @import("dev").host_io.Inbox; + var q: Inbox = undefined; + var core: ?*Pardes = null; + fn search(_: ?*anyopaque, gen: u32) void { + pardes.Stream.start(std.testing.io, std.testing.allocator, core.?, gen, &q, Inbox.pushSearch); + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .search = search }; + fn init(a: *Authority) void { + q = .{ .gpa = std.testing.allocator, .lsp_allocator = std.testing.allocator, .io = std.testing.io }; + core = a.core; + } + // The batches posted until the parse asked has answered (a second's + // wait at most), each a unit the replica takes. + fn land(a: *Authority, r: ?*Replica) !void { + var waited: u32 = 0; + while (a.core.stream.parse != null) : (waited += 1) { + if (waited == 1000) return error.Timeout; + var batch: Inbox.Batch = .{}; + q.takeInto(&batch); + for (batch.slice()) |m| switch (m) { + .search => |b| { + const u = try a.local(.{ .search = b }); + if (r) |c| { + c.confirm(u); + c.settle(); + } + b.deinit(std.testing.allocator); + }, + else => m.deinit(std.testing.allocator, std.testing.allocator), + }; + if (a.core.stream.parse != null) { + const rest: std.c.timespec = .{ .sec = 0, .nsec = std.time.ns_per_ms }; + _ = std.c.nanosleep(&rest, null); + } + } + } + }; + if (comptime !pardes.syntax.enabled) return error.SkipZigTest; + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, .{ .vtable = &WorkerSearch.vtable }, false); + defer a.deinit(); + WorkerSearch.init(a); + defer WorkerSearch.q.deinit(); + // The session's own `/`: its parse asked of the worker, its answer an + // input (the rows grouped once it lands). + _ = try a.local(.{ .command = "Search /pub" }); + try WorkerSearch.land(a, null); + // A client joined now, and a key typed into the query: both its rows. + const r = try joinedNow(a, 1, 0); + defer r.deinit(); + try std.testing.expectEqual(digestOf(a), r.digest()); + try std.testing.expectEqual(a.core.panes[0].?.file.?.context.declarations.len, r.core().panes[0].?.file.?.context.declarations.len); + const u = try gpa.dupe(u8, try a.local(.{ .key = .{ .cp = 'l', .text = "l" } })); + defer gpa.free(u); + r.confirm(u); + r.settle(); + try agrees(a, r); +} + +// A text's places show as ticks on its rail (Places.addTicks), made again +// only when `gen` moves (buildTicks), by a frame or by a step's rail click +// (tickHit), whichever asks first; a dump keeps neither. A frame's ticks +// that a click read after the places changed under them would land it +// elsewhere on a core that drew than on one that did not. +test "a client joined from a dump lands a click on a rail's tick as the session does, the session's ticks drawn before the places changed" { + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host(), false); + defer a.deinit(); + _ = try a.local(.{ .command = "Search /pub" }); + const owner: usize = 0; + try std.testing.expect(a.core.panes[owner].?.places.hits.items.len > 1); + // The session draws: its ticks, of `/pub`'s places. + { + const was = Stepping.begin(&a.t, null); + defer was.end(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + _ = try a.core.render(arena.allocator()); + } + const ticks_gen = a.core.panes[owner].?.places.ticks_gen; + try std.testing.expectEqual(a.core.panes[owner].?.places.gen, ticks_gen); + const r = try joinedFresh(a); + defer r.deinit(); + // Its places changed (`/publ`), then a click on each row of the rail. + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .key = .{ .cp = 'l', .text = "l" } }))); + const rect = r.core().view().rects[owner]; + const pane = r.core().panes[owner].?; + for (rect.y + pane.tag_rows..rect.y + rect.h) |row| for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| { + try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .mouse = .{ .button = .left, .kind = kind, .col = rect.x, .row = @intCast(row) } }))); + }; + try std.testing.expect(a.core.panes[owner].?.places.ticks_gen == ticks_gen); + for (sent.items) |m| { + r.confirm(try a.take(m)); + r.settle(); + } + // (The key may be mispredicted: a step's places are a frame's time's + // worth, `tape.over`, the session's verdict, and its drawn caches let + // it find more in that time than the client's speculation did.) + try agrees(a, r); + try std.testing.expectEqual(a.core.panes[owner].?.places.current, r.core().panes[owner].?.places.current); +} + +// `search` stopped every client's step that asked for one, because a host +// with no worker wrote the rows outside any record: then no client had them, +// stopped or not (a replay answers the entry from the tape and runs no +// host). Its rows are inputs now, as a worker's are, and a step that asks +// the session's host for a search goes on. +test "a far client's step that asks for a search goes on at once, and a session whose host searches on its loop gives every client its rows" { + // A session's host with no worker for a search (a frontend before its + // threads, or one whose worker could not be had: Stream.start): it runs + // the search on its loop, in its `search` entry. + const LoopSearch = struct { + var core: ?*Pardes = null; + fn search(_: ?*anyopaque, gen: u32) void { + pardes.Stream.runHere(core.?, gen, true); + } + fn now(_: ?*anyopaque) u64 { + var ts: std.c.timespec = undefined; + _ = std.c.clock_gettime(.MONOTONIC, &ts); + return @intCast(ts.sec * std.time.ns_per_s + ts.nsec); + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .search = search, .now = now }; + }; + const gpa = std.testing.allocator; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.zig", .data = "const needle = 1;\nfn f() void {}\n// a needle\n" }); + var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + var path_buf: [std.Io.Dir.max_path_bytes + 8]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/a.zig", .{dir}); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = path }, .{ .vtable = &LoopSearch.vtable }, false); + defer a.deinit(); + LoopSearch.core = a.core; + const r = try joinedFresh(a); + defer r.deinit(); + // A `/` in a file asks the session's host for its parse. + const msg = try gpa.dupe(u8, try r.input(.{ .command = "Search /ne" })); + defer gpa.free(msg); + try std.testing.expectEqual(@as(u32, 0), r.stats.stopped); + r.confirm(try a.take(msg)); + r.settle(); + try agrees(a, r); + // A Grep the session's loop runs when the typing pauses: its rows. + r.confirm(try a.local(.{ .key = .{ .cp = pardes.Key.escape } })); + r.confirm(try a.local(.{ .command = "Search Grep needle" })); + r.settle(); + var ticks: u32 = 0; + while (a.core.stream.state == .waiting) : (ticks += 1) { + if (ticks == 200) return error.Timeout; + const rest: std.c.timespec = .{ .sec = 0, .nsec = 10 * std.time.ns_per_ms }; + _ = std.c.nanosleep(&rest, null); + r.confirm(try a.local(.tick)); + r.settle(); + } + try std.testing.expect(a.core.stream.state == .done); + try agrees(a, r); +} + +// PARDES_NOTIME (the tests' `--:--:--` clock) is read by `Message.stamp`, +// which only a host calls: between steps, or in its own entry during one. +// The stamped text crosses as the setMessage the host makes, so a client +// whose environment says otherwise replays the session's text. +test "a far client's replay of a message its session's host stamped takes the session's text, whatever its own PARDES_NOTIME says" { + const gpa = std.testing.allocator; + const Stamping = struct { + var core: ?*Pardes = null; + fn yank(_: ?*anyopaque, _: []const u8) void { + var buf: [64]u8 = undefined; + const c = core.?; + c.setMessage(.at(c.view().active), pardes.Messages.Message.stamp(&buf, "yanked", "x")); + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = yank }; + }; + const Shell = @import("dev").host_io.Shell; + const was = if (std.c.getenv("PARDES_NOTIME")) |v| try gpa.dupeSentinel(u8, std.mem.span(v), 0) else null; + defer if (was) |v| gpa.free(v); + defer _ = if (was) |v| Shell.setenv("PARDES_NOTIME", v, 1) else @import("dev").host_io.testUnsetenv("PARDES_NOTIME"); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &Stamping.vtable }, false); + defer a.deinit(); + Stamping.core = a.core; + const r = try joinedFresh(a); + defer r.deinit(); + // The session's machine says `--:--:--`; the client's the time of day. + _ = Shell.setenv("PARDES_NOTIME", "1", 1); + const u = try gpa.dupe(u8, try a.own(.{ .command = "ClipYank" })); + defer gpa.free(u); + _ = @import("dev").host_io.testUnsetenv("PARDES_NOTIME"); + r.confirm(u); + r.settle(); + try agrees(a, r); + try std.testing.expect(try shows(r.core(), "--:--:-- yanked x")); +} diff --git a/core/root.zig b/core/root.zig index 69ec3ded..632385a0 100644 --- a/core/root.zig +++ b/core/root.zig @@ -324,7 +324,8 @@ comptime { } } -/// Said at a focus-in when the Host's `newer_build` answers yes (upgrade.zig). +/// Said by a session's own frontend at its focus-in, when the build at the +/// path it started from is not its own (upgrade.noticeNewer). pub const newer_build_words = "a newer pardes is installed: Upgrade (SPC s U) moves this session onto it"; pub const Rect = layout.Rect; @@ -457,7 +458,7 @@ const allowed_vars = [_]struct { []const u8, []const u8, []const u8 }{ .{ "Kind.zig", "current", "the kind call in progress, put back at its end (threadlocal)" }, .{ "Kind.zig", "breach", "Debug: the first call over budget, for the addon test tool" }, .{ "Kind.zig", "drawer heap seed_base", "set once by the host at start" }, - .{ "Kind.zig", "ready", "this process's draws done, each keyed by its core, pane and serial" }, + .{ "Kind.zig", "ready drawn", "this process's draws: those done, each keyed by its core, pane and serial, and the last token given, which no rollback takes back" }, .{ "Names.zig", "dp_rows dp_trace", "the scorer's scratch, written before it is read in one call" }, .{ "Turn.zig", "yield_depth", "this thread's nesting of yields (threadlocal)" }, .{ "c_heap.zig", "allocators allocators_len allocators_lock last", "the C heap's registry of allocators and its lookup's memo" }, @@ -613,7 +614,7 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{ .{ "FrameStats.zig", 7, "a frame's clock and log: frames are local, never digested" }, .{ "Handover.zig", 29, "a window carried to another process over a socket: the session's host" }, .{ "Kind.zig", 1, "host_io's KindJob: a kind's job is the host's" }, - .{ "Messages.zig", 6, "the message clock, read through tape.value(.clock); PARDES_NOTIME, the tests' (a step's read of the environment: set on one side only it would diverge)" }, + .{ "Messages.zig", 6, "the message clock, read through tape.value(.clock); PARDES_NOTIME, the tests', read by a host's `stamp` alone (between steps, or in a host's call), whose text the tape carries in the setMessage it makes: never a step's" }, .{ "Output.zig", 2, "the fonts module (Fonts lists them under tape.site(.fonts)) and the build's version line" }, .{ "Stream.zig", 14, "the disk search's worker: it runs off the step and its batches are inputs" }, .{ "builtins.zig", 2, "Mount's probe (tape.site(.probe)) and Term's shell check (tape.site(.shell))" }, @@ -744,12 +745,13 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{ .{ "panes.zig views.zig", "pan", "written by steps only (sync, a view unparked) from the pane and its terminal" }, .{ "File.zig", "cap line_starts line_cap", "the text's line index, of its bytes" }, .{ "File.zig", "highlights highlight_start syntax_dirty", "how a text looks, painted by frames: read by frames, and by a query's rows for colours only (out of their digest)" }, - .{ "File.zig", "context", "the declarations of the text at a revision: found in sync (refreshContext), by a parse's answer (a step) or a dump's load" }, + .{ "File.zig", "allocator", "ContextCache's: what its declarations were made with, the parse's or a load's (a machine's handle, no state)" }, + .{ "File.zig", "declarations", "ContextCache's: the text's at its revision (dumped, digested), parsed again from the text at a load" }, .{ "File.zig", "node_tree node_tree_revision node_tree_edits node_history", "the parse of the text at its revision, made by the first key that walks it" }, .{ "File.zig", "tables", "the whole text's, read at once by whoever asks first (Tables.ensure): no reading under way that a frame could move" }, .{ "Text.zig", "room", "a buffer's capacity" }, .{ "Kind.zig", "ops st gpa arena plain file opened reloads jobs record", "the kind's code and memory here: a plain kind's block is in the copy, and its state hash is checked at every call (Kind.Call.end)" }, - .{ "Kind.zig", "thumb_at thumb_span pointer painted over used draws", "a frame's: written by a paint; `painted` is read by a tick of a kind that is not plain, whose calls are the authority's alone" }, + .{ "Kind.zig", "thumb_at thumb_span pointer painted over used", "a frame's: written by a paint; `painted` is read by a tick of a kind that is not plain, whose calls are the authority's alone" }, .{ "Places.zig", "ticks ticks_gen re", "the rail's ticks, made again when the places move (`gen`), and the compiled pattern, of the pattern" }, .{ "Plumb.zig", "parsed parsed_arena", "the rules parsed, of their text" }, .{ "Stream.zig", "parse_ns paint paint_retired paint_count ahead ahead_for painted_ahead painted_on_loop ahead_seen ahead_ask", "the workers' paints and timings: how a text looks, and numbers" }, diff --git a/core/tape.zig b/core/tape.zig index 5ba999bf..61bdcc08 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -1181,10 +1181,6 @@ const keeps_stopping = .{ "upgrade", "hand_over", "detach", - // A host with no worker runs the search on its loop and writes the - // rows outside any record (Stream.runHere, from tui's and gui's - // `search`); whether the session has one is not the client's to know. - "search", // The loop's, never a step's. "wait_input", "present", diff --git a/dev/Host.zig b/dev/Host.zig index 24df3895..a23c9ef5 100644 --- a/dev/Host.zig +++ b/dev/Host.zig @@ -28,9 +28,6 @@ pub const VTable = struct { /// Upgrade: this process exec'd as the pardes installed since, at /// the step's end (upgrade.zig); `pane` hears why if it cannot be. upgrade: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null, - /// Whether a newer pardes is installed at the path this process - /// started from, to be said once (upgrade.zig): asked at a focus-in. - newer_build: ?*const fn (ctx: ?*anyopaque) bool = null, spawn: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, cwd: []const u8) void = null, pty_write: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, bytes: []const u8) void = null, pty_resize: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, cols: u16, rows: u16) void = null, diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 3aed1ed6..9695bf83 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -3540,7 +3540,7 @@ fn kindJob(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { fn search(ctx: ?*anyopaque, gen: u32) void { const s = shellOf(ctx); if (s.threads_ok) return pardes.Stream.start(s.io, s.gpa, s.core, gen, s.queue, Queue.pushSearch); - pardes.Stream.runHere(s.core, gen); + pardes.Stream.runHere(s.core, gen, true); } /// Handover `seq`'s dump to its file, and a worker to carry it to another diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 1f6b9a49..d7ea8ed6 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1274,7 +1274,6 @@ const Shell = struct { .detach = detach, .adopt = adopt, .upgrade = upgradeAsked, - .newer_build = newerBuild, .spawn = spawn, .pty_write = ptyWrite, .pty_resize = ptyResize, @@ -1392,12 +1391,6 @@ const Shell = struct { s.adoptions.ask(s.core, pane); } - /// A client's own build is not the session's to say (its core's host - /// is the session's, through the tape). - fn newerBuild(ctx: ?*anyopaque) bool { - return of(ctx).client == null and upgrade.newer(); - } - fn upgradeAsked(ctx: ?*anyopaque, id: pardes.Pane.Id) void { const pane = id.index(); const s = of(ctx); @@ -1739,7 +1732,10 @@ const Shell = struct { c.link.gone = true; return true; }, - .focus_in => s.feed(.{ .focus = true }), + .focus_in => { + s.feed(.{ .focus = true }); + if (s.client == null) upgrade.noticeNewer(s.core); + }, .focus_out => { s.feed(.pointer_leave); s.feed(.{ .focus = false }); @@ -2220,7 +2216,7 @@ const Shell = struct { fn search(ctx: ?*anyopaque, gen: u32) void { const s = of(ctx); if (s.threads_ok) return pardes.Stream.start(s.io, s.gpa, s.core, gen, s, deliverSearch); - pardes.Stream.runHere(s.core, gen); + pardes.Stream.runHere(s.core, gen, true); } /// A draw (api.draw) on a worker, as a job is. diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 77928dd0..2a8d6edf 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -80,9 +80,9 @@ pub fn noticeNewer(core: *pardes.Pardes) void { if (newer()) core.setMessage(.at(core.view().active), pardes.newer_build_words); } -/// Whether to say a newer build is installed now (`noticeNewer`): the -/// tty's Host answers the core's focus step with it, so its replica -/// clients take the line from the tape. +/// Whether to say a newer build is installed now (`noticeNewer`): asked +/// by a session's own frontend at its focus-in, between steps; the line is +/// an input (setMessage) its replica clients take from the tape. pub fn newer() bool { const was = started_inode orelse return false; const now = inodeOf(exe() orelse return false) orelse return false; |
