diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-29 20:56:03 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 02:12:12 -0300 |
| commit | 57aa8d2f9ae851fa9806abbd1fd04abf1fd2b57f (patch) | |
| tree | ec77e56aa09568b592fbbb28fa2c379df922d922 /src/pardes.zig | |
| parent | 3703c2526fb59708b00e12816bd88ffd8a15fc69 (diff) | |
| download | pardes-57aa8d2f9ae851fa9806abbd1fd04abf1fd2b57f.tar.gz pardes-57aa8d2f9ae851fa9806abbd1fd04abf1fd2b57f.zip | |
replicas' core for a socket: a client's input settles as a `step` (no clock, no wait, no frame) on both sides, every kind of input speculated, the session's clock guessed, views no frontend here draws left undrawn, and a drawn view's selections given back to its slot
pardes.zig: `step`, the middle of a pump, is a client input's own top-level input on the authority and in the replica's speculation, so the two tapes read alike; a pump skips the live view when it is `undrawn` (a replica client's, drawn by its own process); `settle` is the pump's whole middle, the Upgrade's too.
tape.zig: a `.step` input; `unattended` is a watched field; a speculation's clock reads answer a guess of the session's clocks (`Guess`); `resync` says the host and its writes again for a joiner; `adoptCore`; a short ret is shown in a trace.
views.zig: `drawOne` draws a replica client's own view between steps; `drawParked` gives a drawn view's selections back to its slot, for drawOthers too.
rollback.zig: std's lists by walk.isList (a safe build's have a third field).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index 02983c84..cc55d695 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4710,6 +4710,9 @@ pub const Pardes = struct { view: u8 = 0, views_open: u8 = 1, parked: [views.max]?*views.Parked = @splat(null), + /// The views no frontend here draws: a replica client's, which its own + /// process draws (src/replica.zig). A pump skips them. + undrawn: u8 = 0, /// per-update scratch (paneCursorLines, selection text); reset each update scratch: std.heap.ArenaAllocator, /// The arena each frame's Surface text is built in, reset by `pump`. Hosts @@ -4739,7 +4742,7 @@ pub const Pardes = struct { "effects", "effects_head", "effects_len", "in_q", "in_head", "in_len", // The views not live: written whenever one goes out, so the // live one's slot is stale (views.zig). - "parked", + "parked", "undrawn", // How this process was started, and the last dump it made for // its host to write: a session loaded elsewhere has its own. "opts", "dump_out", @@ -6056,13 +6059,6 @@ pub const Pardes = struct { } } - /// What a step leaves queued, its inputs and its effects, taken now: - /// the session at a step boundary (an Upgrade's dump, upgrade.zig). - pub fn settle(p: *Pardes) void { - while (p.nextQueued()) |ev| p.update(ev); - while (p.nextEffect()) |e| p.perform(e); - } - pub fn pump(p: *Pardes, host: Host) !void { p.host = host; const taped = tape.enter(p, .pump); @@ -6087,15 +6083,7 @@ pub const Pardes = struct { } p.frames.mark_start = FrameStats.nowNs(); if (v.now) |clock| p.advance(clock(h.ctx)); - // What a 9P open wrote in a row goes in once the writes pause. - ctlfs.pane.flushPausedBatch(p); - // ...and what a /pager open was written before its close. - ctlfs.ctl.fillClosedPagers(p); - // ...and the last line of an open closed with no newline after it. - ctlfs.runClosedLines(p); - while (p.nextQueued()) |ev| p.update(ev); - while (p.nextEffect()) |e| p.perform(e); - turn.bump(&turn.epoch); + p.settle(); // A quitting frame has already freed what it would draw. if (p.quit) return; if (v.poll_frame) |f| f(h.ctx); @@ -6111,13 +6099,17 @@ pub const Pardes = struct { if (v.watched) |f| if (!f(h.ctx)) return; // The other views first, each into its own window or terminal. if (views.several(p)) try views.drawOthers(p, h); - _ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept }); - p.frames.mark_update = FrameStats.nowNs(); - p.frames.view = if (p.panes[p.active]) |pane| pane.scroll() else 0; - const surface = try p.render(p.frame_arena.allocator()); - p.frames.mark_render = FrameStats.nowNs(); - if (v.present) |f| f(h.ctx, surface); - Stream.askAhead(p); + // A replica client's view live (its input the last): its own + // process draws it. + if (p.undrawn & (@as(u8, 1) << @intCast(p.view)) == 0) { + _ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept }); + p.frames.mark_update = FrameStats.nowNs(); + p.frames.view = if (p.panes[p.active]) |pane| pane.scroll() else 0; + const surface = try p.render(p.frame_arena.allocator()); + p.frames.mark_render = FrameStats.nowNs(); + if (v.present) |f| f(h.ctx, surface); + Stream.askAhead(p); + } // Settled before post_present: a shell ticks there, and what that // tick moves owes the next frame. const skipped = p.present_skipped; @@ -6129,6 +6121,32 @@ pub const Pardes = struct { p.frames.record(FrameStats.nowNs(), owed or p.continuous(), skipped); } + /// What a pump does between its wait and its frame: the queued inputs + /// and the effects. Also the session at a step boundary, taken now (an + /// Upgrade's dump, upgrade.zig). + pub fn settle(p: *Pardes) void { + // What a 9P open wrote in a row goes in once the writes pause. + ctlfs.pane.flushPausedBatch(p); + // ...and what a /pager open was written before its close. + ctlfs.ctl.fillClosedPagers(p); + // ...and the last line of an open closed with no newline after it. + ctlfs.runClosedLines(p); + while (p.nextQueued()) |ev| p.update(ev); + while (p.nextEffect()) |e| p.perform(e); + turn.bump(&turn.epoch); + } + + /// A replica client's input settled on the authority (src/replica.zig): + /// a pump that waits on nothing, reads no clock and draws nothing, so + /// the client's own core can apply the same at once and expect the + /// authority's tape of it to read the same. The session's own pump + /// draws it after. + pub fn step(p: *Pardes) void { + const taped = tape.enter(p, .step); + defer tape.leave(p, taped); + p.settle(); + } + /// One request of the control filesystem, from whichever thread has the /// turn (`pardes.turn`). Not an event: it neither sweeps nor resets /// anything the editor's own step may be in the middle of using, so it |
