diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 21:17:23 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 00:01:23 -0300 |
| commit | 5d22d59506b58dbcc58910fb167bd212c2516544 (patch) | |
| tree | 77d45342b5a859fa1f7f9fbecc266d71ffa430dc | |
| parent | 6ca2655317e7a576dd74ab23c1bb69bba020641b (diff) | |
| download | pardes-5d22d59506b58dbcc58910fb167bd212c2516544.tar.gz pardes-5d22d59506b58dbcc58910fb167bd212c2516544.zip | |
far client: a step that asks the session's host for a search goes on at once, and a host that runs one on its loop hands its rows in as inputs: `search` was on tape.zig's keeps_stopping because a host with no worker (tui's and gui's `search` before their threads, and Stream.start when no worker can be had) runs the search in its entry and writes the rows into the core outside any record (Stream.runHere's `receive`); but then no client had those rows, stopped or not (a replay answers the entry from the tape and runs no host), so the stop protected nothing and cost every `/` in a file (its parse asked of the session's host) and every query whose rows ask colours a round trip; whether the session has the entry at all a client already knows (the host's mask, told at the join: a client's tape offers only the session's entries), and with no entry the search runs in the step under `tape.site(.search)`, which still stops; the same host also let go a paint (`rows_paint`, digested) or a parse it had no worker for by writing the core in its entry; now `runHere` takes `in_call` (comptime): from a host's entry each batch goes in as `p.update(.{ .search = b })`, a nested input the tape records and every replica replays, as a worker's batches are, and a paint it cannot run is let go by an input too (a worker's answer of nothing); Stream.start, when no worker can be had, does the same for a paint, a parse (an answer that found none) and a search (tui's and gui's entries and Stream.start pass true; Stream.step and Effect's perform, in a step, false); `search` leaves keeps_stopping, and may_wait's row `Search *` at `search` goes (the walk would call it stale); the 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` (end of core/replica.zig: a `/` in a file, then a Grep the session's loop runs at its ticks) failed on the base with `expected 0, found 1` (stopped), and with the host writing as before (`runHere(.., false)` in its entry) the client's digest differed after the `/` (the paint the host let go) and never had the Grep's rows; it passes; a user could hit the second only with a window or tty session whose worker could not be had (std.Io's concurrency refused) while a client was attached; gates on the seven together (the stack's top, load 18 to 50 beside them): tui core-test 855/999 (144 skipped), shell-test 1035/1038, pane-test 183/184, term-test 15/15, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds 0 failures, process-test 3 of 144 (lspcomplete and lspcompletemoved, the base's, and headersweep-restored, which passes alone), gui unit-test 1633/1637 with the base's BaselineHarnessMismatch; replicas --clients 5 and --seeds 8: diverged 0, unequal 0, deltas wrong 0, quiet checks differed 0, unlisted stops 0, corpus 22 of 22, no leak report; the walk over every word and key passes; frame and perf gate against tree1 (farfaults): frames 77/77 byte-identical in Debug, unit-test 1633/1637, perfab corpus2x -0.087% (noise 0.092%, bar 0.4%, pictures identical), perfops 97 counts within 0.1% (largest +0.0329%)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | core/Effect.zig | 2 | ||||
| -rw-r--r-- | core/Stream.zig | 34 | ||||
| -rw-r--r-- | core/replica.zig | 62 | ||||
| -rw-r--r-- | core/tape.zig | 4 | ||||
| -rw-r--r-- | dev/gui/gui.zig | 2 | ||||
| -rw-r--r-- | dev/tui/tui.zig | 2 |
6 files changed, 77 insertions, 29 deletions
diff --git a/core/Effect.zig b/core/Effect.zig index 7166294f..9b00d8dc 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/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/replica.zig b/core/replica.zig index bc5eafd1..13c1fe46 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -5353,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" }, @@ -6277,3 +6274,60 @@ test "a client joined from a dump lands a click on a rail's tick as the session 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); +} diff --git a/core/tape.zig b/core/tape.zig index 00486666..cc4b21b8 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/gui/gui.zig b/dev/gui/gui.zig index c147c2e2..1dfc6336 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 5ba31bd9..d7ea8ed6 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -2216,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. |
