summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 18:22:04 -0300
committerGabriel Schneider <[email protected]>2026-11-06 20:00:43 -0300
commiteeb59b92295e74b956d32e66c3c318e105a391db (patch)
treed7178f0b87c5740a077119705331efa3d0319547
parentb22fa2638bca470bbd8c5ea4768eb0eaaa3e8195 (diff)
downloadpardes-eeb59b92295e74b956d32e66c3c318e105a391db.tar.gz
pardes-eeb59b92295e74b956d32e66c3c318e105a391db.zip
kinds #38, a kind's ticks and views as units of the session's origin (§17.2 B 1): a step of the session's own (a tick, a job's answer, a 9P request, any input no client sends) tells each view whose facts moved and ticks a focus changed or a deadline come, a client's input ticks only the pane its key, click or word went to (which already waits), so a client never guesses a tick and never waits for one; the tick's prefix is in its taped outcome (a Shadow's tag is the authority's from the tape, `told` and the frame's prefix gone, the dump carrying the prefix), Kind.wake says a focus change, the tick wait and Kind.repaint are gone, the post-unit flush stays for the tick after a key; the stall test asserts the replay (0 mispredicted, 0 waited)
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/Core.zig10
-rw-r--r--src/Kind.zig98
-rw-r--r--src/addon_test.zig10
-rw-r--r--src/dump.zig7
-rw-r--r--src/replica.zig6
-rw-r--r--test/panes.zig34
6 files changed, 75 insertions, 90 deletions
diff --git a/src/Core.zig b/src/Core.zig
index 5496a979..65779217 100644
--- a/src/Core.zig
+++ b/src/Core.zig
@@ -1516,7 +1516,7 @@ pub fn serveFs(p: *Pardes, req: ctlfs.Req) ctlfs.Reply {
// step does: the cursor and scroll reconciled, the scripted panes
// told, and the panes it made announced to /log now rather than at
// the end of whatever the editor does next.
- pardes.Kind.step(p);
+ pardes.Kind.step(p, true);
p.sync();
p.fsReport();
// A /focus write moves the keyboard as a click does: the programs
@@ -1642,8 +1642,12 @@ pub fn update(p: *Pardes, ev: Event) void {
look.advanceLookHover(p);
},
}
- // Each kind's pane whose time has come steps, and its jobs' answers land.
- pardes.Kind.step(p);
+ // Each kind's pane a call asked a tick of steps; at a step of the
+ // session's own (an input no client sends), whose time has come too.
+ pardes.Kind.step(p, switch (ev) {
+ .key, .mouse, .resize, .paste, .command, .pointer_leave, .focus, .frontend => false,
+ else => true,
+ });
// Each pane's places find a frame's more on a tick, and on any other
// step the ones an edit or a scroll left unfound in the view.
for (p.panes) |slot| if (slot) |pane| pane.places.settle(p, pane, ev == .tick);
diff --git a/src/Kind.zig b/src/Kind.zig
index e3d74b24..08c04154 100644
--- a/src/Kind.zig
+++ b/src/Kind.zig
@@ -162,13 +162,10 @@ pub const Slot = struct {
/// Its words' last values, a `Word arg` line each, which a kind with
/// no `dump` is given again when its pane comes back.
values: Buf(256) = .{},
- /// Its prefix as its last tick set it; where its window is in its
+ /// Its prefix as its last tick set it (the tick's outcome, on the
+ /// tape: a Shadow's is the authority's); where its window is in its
/// whole (the rail's thumb), 0 and 0 for none, as its last frame says.
prefix: Buf(96) = .{},
- /// Its tag's prefix as the last step read it (the authority's): what a
- /// Shadow says in a step, and what a dump keeps of it, so a replica
- /// joining lays its tag out as the session did.
- told: Buf(400) = .{},
thumb_at: f32 = 0,
thumb_span: f32 = 0,
/// The pointer its last frame asked for over it (PA_POINTER_*), and
@@ -482,20 +479,12 @@ fn colorOf(v: u32, default: surface.Color) surface.Color {
pub fn prefix(p: *const Pardes, arena: std.mem.Allocator, pane: *const Pane) ![]const u8 {
const slot = pane.addon.?;
var buf: [400]u8 = undefined;
- const made = tape.value(.addon, prefixOf, .{ p, slot, &buf });
- if (tape.stepping()) slot.told.set(made);
- return arena.dupe(u8, made);
+ return arena.dupe(u8, tape.value(.addon, prefixOf, .{ p, slot, &buf }));
}
fn prefixOf(p: *const Pardes, slot: *const Slot, buf: *[400]u8) []const u8 {
if (!slot.live) return if (slot.path.len > 0) slot.path else slot.nameOf();
- // A Shadow's is the authority's last step's, never its frames' guess:
- // a speculation, a load and a frame drawn between steps (which lays the
- // tag out too) all lay it out as the session's step did.
- // ponytail: so a window client's page in the tag is the session's last
- // step's, a notch behind its frames until the next step.
- if (slot.ops == null and slot.told.len > 0) return slot.told.slice();
- const own = if (slot.shadow) |sh| sh.prefix.slice() else slot.prefix.slice();
+ const own = slot.prefix.slice();
var w: std.Io.Writer = .fixed(buf);
w.writeAll(if (own.len > 0) own else slot.nameOf()) catch {};
// The same bytes whichever view's step lays the tag out (17.2): glyph
@@ -604,17 +593,22 @@ pub fn mouse(p: *Pardes, id: usize, m: pardes.Mouse, col: u16, row: u16) bool {
return taken(p, slot, cl.end(prev));
}
-/// The end of a step: each pane of a kind told of each view whose facts
-/// changed (17.1), and each whose focus changed, or whose time has come,
-/// ticked (16.2).
-pub fn step(p: *Pardes) void {
+/// The end of a step: each pane of a kind ticked that a call into it in
+/// the step asked for (16.2's rule 2). At a step of the session's own
+/// (`due`: a tick, a job's answer, a 9P request; never a client's input,
+/// which a replica guesses), also each told of each view whose facts
+/// changed (17.1), and ticked when its focus changed or its time came:
+/// units of the session's origin, which a replica replays (17.2).
+pub fn step(p: *Pardes, due: bool) void {
const now = p.clock.stepped_ns;
- // A kind's call is the authority's kind's alone: a speculation whose
- // step would make one waits for the authority's unit (guessed
- // untouched, the unit rolled it back, a visible rollback an input).
- if (tape.speculating()) return if (wouldTick(p, now)) tape.poison("a kind's tick");
+ // A kind's call is the authority's alone: a speculation's tick after a
+ // call into the pane waits with that call's input (it stopped there).
+ if (tape.speculating()) {
+ for (p.panes) |pslot| if (pslot) |pane| if (pane.addon) |slot| if (slot.next_tick == 1) return tape.poison("a kind's tick");
+ return;
+ }
for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
- if (caps(p, slot).view) for (0..views.max) |k| {
+ if (due and caps(p, slot).view) for (0..views.max) |k| {
var v = viewOf(p, @intCast(k), id);
if (seen(&v) == slot.views[k]) continue;
slot.views[k] = seen(&v);
@@ -627,13 +621,11 @@ pub fn step(p: *Pardes) void {
};
if (!caps(p, slot).tick) continue;
const focused = focusedAnywhere(p, id);
- if (focused != slot.focused) {
- slot.focused = focused;
- slot.next_tick = 1;
- }
+ if (due and focused != slot.focused) slot.next_tick = 1;
// 1 is the next step, whatever the clock says (a session whose
// clock has not moved yet reads 0).
- if (slot.next_tick == 0 or (slot.next_tick > 1 and now < slot.next_tick)) continue;
+ if (slot.next_tick == 0 or (slot.next_tick > 1 and (!due or now < slot.next_tick))) continue;
+ slot.focused = focused;
var cl: Call = .{ .p = p, .id = id, .slot = slot };
const prev = cl.begin("tick");
// A frame drawn since its last tick: a fling's frames are counted by them.
@@ -645,11 +637,12 @@ pub fn step(p: *Pardes) void {
if (slot.ops) |o| {
o.tick.?(slot.st, &t);
cl.ret = @bitCast(t.next);
- slot.prefix.set(t.prefix[0..@min(t.prefix_len, t.prefix.len)]);
+ cl.prefix = t.prefix[0..@min(t.prefix_len, t.prefix.len)];
}
- slot.next_tick = @bitCast(cl.end(prev).ret);
+ const o = cl.end(prev);
+ slot.next_tick = @bitCast(o.ret);
+ slot.prefix.set(o.prefix);
p.needs_frame = true;
- repaint(p, slot, id);
};
}
@@ -664,34 +657,6 @@ fn seen(v: *const c.pa_view) u64 {
return if (v.cols == 0) 0 else std.hash.Wyhash.hash(0, std.mem.asBytes(v));
}
-/// Its thumb and pointer as its tick left them, the live view's frame of
-/// it painted and let go; not a frame drawn (`painted` kept).
-fn repaint(p: *Pardes, slot: *Slot, id: usize) void {
- const pane = p.panes[id] orelse return;
- if (slot.ops == null or pane.collapsed) return;
- const r = p.view().rects[id];
- const cols = r.w -| pardes.config.GUTTER;
- const rows = (r.h -| pane.tag_rows) -| pane.notices.span();
- if (cols == 0 or rows == 0) return;
- const drawn = slot.painted;
- defer slot.painted = drawn;
- var arena: std.heap.ArenaAllocator = .init(slot.gpa);
- defer arena.deinit();
- var frame: Frame = .{ .cols = cols, .rows = rows };
- _ = paint(p, slot, id, arena.allocator(), cols, rows, &frame);
-}
-
-/// Whether `step` would call some pane's kind now (its rule, read only).
-fn wouldTick(p: *const Pardes, now: u64) bool {
- for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
- if (viewOwed(p, slot, id)) return true;
- if (!caps(p, slot).tick) continue;
- if (focusedAnywhere(p, id) != slot.focused) return true;
- if (slot.next_tick == 1 or (slot.next_tick > 1 and now >= slot.next_tick)) return true;
- };
- return false;
-}
-
/// Pane `id` as view `k` shows it (its id k + 1): its body below its
/// notices, as draw.zig paints it, a cell's pixels, the theme's colours and
/// the raster that view's frontend wants a picture at; no cells when the
@@ -736,12 +701,14 @@ fn focusedAnywhere(p: *const Pardes, id: usize) bool {
return false;
}
-/// When the kinds next want a step: the soonest deadline (now, for a view
-/// whose facts a step's layout changed after the kind was told them), or null.
+/// When the kinds next want a step of the session's own: the soonest
+/// deadline (now, for a view whose facts changed after the kind was told
+/// them, or a focus), or null.
pub fn wake(p: *const Pardes) ?u64 {
var soonest: ?u64 = null;
for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
- const due = if (viewOwed(p, slot, id)) @max(1, p.clock.stepped_ns) else slot.next_tick;
+ const moved = viewOwed(p, slot, id) or (caps(p, slot).tick and focusedAnywhere(p, id) != slot.focused);
+ const due = if (moved) @max(1, p.clock.stepped_ns) else slot.next_tick;
if (due != 0) soonest = @min(soonest orelse due, due);
};
return soonest;
@@ -866,6 +833,8 @@ pub const Outcome = struct {
exec: []const u8 = "",
selected: ?[]const u8 = null,
rows: []const u8 = "",
+ /// A tick's: the start of its tag (pa_tick.prefix).
+ prefix: []const u8 = "",
/// The jobs it asked for (their tokens, 0 past the last): every core
/// emits them, so a replica's effects are the authority's; and those
/// it cancelled, every core drops.
@@ -895,6 +864,7 @@ const Call = struct {
exec: Buf(256) = .{},
selected: ?[]const u8 = null,
rows: []const u8 = "",
+ prefix: []const u8 = "",
jobs: [8]u32 = @splat(0),
cancels: [4]u32 = @splat(0),
/// Debug: when it began, for the budget.
@@ -913,7 +883,7 @@ const Call = struct {
current = prev;
if (checked) overBudget(cl);
if (cl.quiet) return .{};
- const o = tape.value(.addon, same, .{Outcome{ .ret = cl.ret, .text = cl.refused.slice(), .said = cl.said.slice(), .err = cl.err, .look = cl.look.slice(), .pane_name = cl.pane_name.slice(), .pane_text = cl.pane_text, .exec = cl.exec.slice(), .selected = cl.selected, .rows = cl.rows, .jobs = cl.jobs, .cancels = cl.cancels }});
+ const o = tape.value(.addon, same, .{Outcome{ .ret = cl.ret, .text = cl.refused.slice(), .said = cl.said.slice(), .err = cl.err, .look = cl.look.slice(), .pane_name = cl.pane_name.slice(), .pane_text = cl.pane_text, .exec = cl.exec.slice(), .selected = cl.selected, .rows = cl.rows, .prefix = cl.prefix, .jobs = cl.jobs, .cancels = cl.cancels }});
if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = @intCast(cl.id), .serial = pane.serial, .token = token } });
for (o.cancels) |token| if (token != 0) {
for (&cl.slot.jobs) |*j| if (j.*) |job| if (job.token == token) {
diff --git a/src/addon_test.zig b/src/addon_test.zig
index 7c9950d7..2e673145 100644
--- a/src/addon_test.zig
+++ b/src/addon_test.zig
@@ -138,13 +138,13 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
if (!p.executeBuiltinLine(at, line)) try out.print("not a word here: {s}\n", .{verb});
}
drain(p);
- // A tick owed (a pane opened or loaded here, outside a step) and a
- // view whose facts a frame's layout changed (its tag wrapped), as
- // a host steps for them.
- if (p.panes[id.?]) |pane| if (window(p, id.?) != null and (pane.addon.?.next_tick == 1 or Kind.viewOwed(p, pane.addon.?, id.?))) {
+ // The session's own steps owed (a tick asked outside a step, a view
+ // whose facts moved, a focus), as a host's pump takes them (17.2).
+ var owed: usize = 0;
+ while (owed < 4 and window(p, id.?) != null and (Kind.wake(p) orelse std.math.maxInt(u64)) <= @max(1, p.clock.stepped_ns)) : (owed += 1) {
p.update(.tick);
drain(p);
- };
+ }
try show(p, gpa, id.?, out, opened or is(verb, "size"));
if (Kind.breach.len > 0 and !said) try out.print("addon-test: {s}\n", .{Kind.breach.slice()});
said = Kind.breach.len > 0;
diff --git a/src/dump.zig b/src/dump.zig
index 52002697..2f52d1d9 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -927,7 +927,8 @@ const SlotRecord = struct {
next_tick: u64 = 0,
views: [views.max]u64 = @splat(0),
focused: bool = false,
- told: []const u8 = "",
+ /// Its tick's prefix: a replica's tag laid out as the session's.
+ prefix: []const u8 = "",
/// A placeholder's why (its file not here).
refused: []const u8 = "",
/// What a step reads of it that its kind's open made (Kind.reopen) or
@@ -940,7 +941,7 @@ const SlotRecord = struct {
pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) !void {
var place: [32]u8 = undefined;
- var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .told = s.told.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection };
+ var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .prefix = s.prefix.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection };
var owned: ?[]u8 = null;
defer if (owned) |o| s.gpa.free(o);
if (s.ops != null) {
@@ -977,7 +978,7 @@ pub fn slotRead(out: *Kind.Slot, gpa: std.mem.Allocator, bytes: []const u8) !voi
@memcpy(out.name[0..@min(15, r.name.len)], r.name[0..@min(15, r.name.len)]);
out.path = try gpa.dupe(u8, r.path);
out.where_text.set(r.where);
- out.told.set(r.told);
+ out.prefix.set(r.prefix);
out.refused.set(r.refused);
out.tail.set(r.tail);
out.values.set(r.values);
diff --git a/src/replica.zig b/src/replica.zig
index f2c8f8b4..2a2d2f55 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -1911,9 +1911,9 @@ pub const Peers = struct {
ps.t.stamp = null;
ps.screensOut(core, .fill);
ps.unit(peer.id, in.seq);
- // What the step made of a kind's pane (its tick: another layout,
- // the text layer) goes now, not at the next pump's: one may not
- // come before the client looks.
+ // What the step made of a kind's pane (the tick after a key or a
+ // click into it: another layout) goes now, not at the next pump's:
+ // one may not come before the client looks.
ps.screensOut(core, .flush);
}
diff --git a/test/panes.zig b/test/panes.zig
index 28256495..249ce7eb 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -3902,7 +3902,7 @@ const PdfAddon = struct {
try std.testing.expect(r.diverged == null);
}
- test "a client's input whose session step ticks a PDF's pane waits for that step, never guessed and rolled back" {
+ test "a client's input that moves a PDF's view is guessed right, never waited for, and the session's tick of it is a unit of its own the client replays" {
if (!addons.has_pdf) return error.SkipZigTest;
const R = pardes.replica;
const gpa = std.testing.allocator;
@@ -3917,15 +3917,22 @@ const PdfAddon = struct {
l.r.confirm(try l.a.local(ev));
}
};
- _ = try opened(a, Land{ .a = a, .r = r });
+ const id = try opened(a, Land{ .a = a, .r = r });
const guessed = r.stats.mispredicted;
- // Its window resized: the pane's view moves, and the session's
- // step ticks its kind, which only the session runs.
+ const stopped = r.stats.stopped;
+ const told = a.core.panes[id].?.addon.?.views;
+ // Its window resized: the pane's view moves; the client's input
+ // calls no kind, so its guess is the session's step.
r.confirm(try a.take(try r.input(.{ .resize = .{ .cols = 100, .rows = 30 } })));
r.settle();
- try std.testing.expect(r.diverged == null);
try std.testing.expectEqual(guessed, r.stats.mispredicted);
- try std.testing.expect(r.stats.stopped >= 1);
+ try std.testing.expectEqual(stopped, r.stats.stopped);
+ // The session's own next step tells the kind, ticks it, and the
+ // client replays that unit.
+ r.confirm(try a.local(.tick));
+ try std.testing.expect(r.diverged == null);
+ try std.testing.expect(!std.mem.eql(u64, &told, &a.core.panes[id].?.addon.?.views));
+ try std.testing.expectEqualSlices(u64, &a.core.panes[id].?.addon.?.views, &r.core().panes[id].?.addon.?.views);
}
test "a PDF's tag has the core's art words from its first step, in a view without graphics and with them" {
@@ -3942,14 +3949,14 @@ const PdfAddon = struct {
};
const land: Land = .{ .a = a };
const id = try opened(a, land);
- const slot = a.core.panes[id].?.addon.?;
// A view without graphics: the page's text layer, its pictures'
// words glyph art's (PA_PICTURES: the kind's, not the frame's).
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:on ") != null);
+ const pane = a.core.panes[id].?;
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(a.core, pane), " petscii:on ") != null);
// A window's: the pages as pictures, the same words, its own.
try land.step(.{ .frontend = .{ .windowed = true, .native_images = true } });
try jobs(a.core, land);
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:off ") != null);
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(a.core, pane), " petscii:off ") != null);
}
test "a PDF's pane in a window's view and a terminal's in turn: each is told its view, its tag its page and art words in both" {
@@ -3980,8 +3987,11 @@ const PdfAddon = struct {
const win = try R.Replica.initDump(gpa, 2, k, bytes, .{ .cols = 80, .rows = 24 });
defer win.deinit();
_ = try a.take(try win.input(.{ .frontend = .{ .windowed = true, .native_images = true } }));
+ // Its view's facts are the session's own step's to tell (17.2).
+ try land.step(.tick);
try jobs(a.core, land);
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:on ") != null);
+ const pane = a.core.panes[id].?;
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(a.core, pane), " petscii:on ") != null);
// Both views told (by id, the session's 1 and the window's), each
// with its own frontend's facts.
try std.testing.expect(slot.views[0] != 0 and slot.views[k] != 0 and slot.views[0] != slot.views[k]);
@@ -3991,9 +4001,9 @@ const PdfAddon = struct {
// session's first view's art words, a terminal's: glyph art).
_ = try a.take(try tty.input(.{ .key = .{ .cp = 'j', .text = "j" } }));
try jobs(a.core, land);
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "/16] petscii:on ") != null);
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(a.core, pane), "/16] petscii:on ") != null);
_ = try a.take(try win.input(.{ .key = .{ .cp = 'j', .text = "j" } }));
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "/16] petscii:on ") != null);
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(a.core, pane), "/16] petscii:on ") != null);
try jobs(a.core, land);
}
}