summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 05:28:45 -0300
committerGabriel Schneider <[email protected]>2026-11-24 05:49:28 -0300
commit4e28df7f8e02ceec66a9d62ca75f8ec006e26d7c (patch)
treeeeee707f41a480fdcf038179ff1a527105b620c1
parentda985ae98180c2394ccdf48cf8bdf5bd85873c2f (diff)
downloadpardes-4e28df7f8e02ceec66a9d62ca75f8ec006e26d7c.tar.gz
pardes-4e28df7f8e02ceec66a9d62ca75f8ec006e26d7c.zip
layout: a view's geometry is read back as its session holds it, never laid out again at a load, and held to its screen (walk.zig `.within`): a dump whose rect or column is off its screen is REFUSED, the field named: RUN FIRST (the soak, `replicas -- --clients 5`, Debug): `rpplxwst` ALONE diverged 124 at rtt 30 (225 clients parted at their first unit after a join, `addon pdf: its state after view is not the session's (it breaks PA_PLAIN)` and `the tape's answer to addon is short`; then 532 keys into the pdf's pane stopped at `a key into a kind's pane`, the kind distrusted; the witness's replay past a divergence panicked, `integer overflow` in Core.advanceInner), `pardes-merge67` 0 at 30, 80 and 207 ms; THE CAUSE: a join opens its client a view (views.zig `open`: the live one's screen and columns, NO rects: laid out at that view's first input), and rpplxwst's load (dump.zig `afterLoad`) laid every view out again, so the client had rects for its own view the session had not, told its plain kinds a view the session never told them (Kind.zig `step`, `viewOf`), and parted at the session's next step; a join's dump is the session: THE FIX: `rects`, `col_x`, `col_w` back in the digest, the dump and the copy as merge67 had them, `afterLoad`'s relayout gone (and walk.zig `pastHeld`'s pass over a derived buffer with it), and where a value read back may be is declared beside the field: `replica.within` (a predicate of the struct by the entry's place in the field, as far as its length says), checked with the indexes (`heldIndexes`) in all three decoders (a tape's `decode`, a byte dump's and an image's `holdTo`): `View.rects` on its screen (`onScreen`: x + w <= screen_w, y + h <= screen_h, as the layout pass puts every one, and a view not laid out yet has empty ones), a column's edge with its width (`columnOnScreen`, declared on `col_w`), refused in words (`Core.View.rects[0] is not within Core.View.onScreen: refused`), never clamped (a clamped rect is a state no session had); `cols` stays held to `ncol` (a column past `ncol` is a dropped one's, which the index rule would read); TESTS FIRST: replica.zig "a client joins with its session's geometry as the session holds it ..." (a plain kind keeping the rows its view was told; on pardes-load-index: `expected 0, found 5`, the joined view's rect, and without that line `the tape's answer to addon is short (tape byte 241, in tick)`), dump.zig "a view's geometry is read back as the session holds it, never laid out again; a rect or a column off its screen is refused, the field named" (the fuzz's restore seed 589: a pane 534 rows tall on a 24-row screen; a column 900 wide; a column's edge at 900), walk.zig's index test gains an entry not where it may be (`S.edges[1] is not within`, a tape, a dump and an image)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--core/Core.zig23
-rw-r--r--core/dump.zig59
-rw-r--r--core/replica.zig39
-rw-r--r--core/walk.zig55
4 files changed, 133 insertions, 43 deletions
diff --git a/core/Core.zig b/core/Core.zig
index b2f96886..6c981adf 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -87,16 +87,18 @@ const Pardes = @This();
/// One client's view of the session (views.zig): its screen and layout,
/// its focus, its pointer and gestures, its jumps, its key prefixes.
pub const View = struct {
- /// Its geometry (`rects`, `col_x`, `col_w`) is the layout pass's over
- /// its columns and screen: never dumped, laid out again at a load
- /// (dump.afterLoad), as a resize lays it out.
pub const replica = .{
.len = .{ .{ "leader_keys", "leader_n" }, .{ "cols", "ncol" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" } },
- .derived = .{ "rects", "col_x", "col_w" },
// What its keyboard is on: a pane there; window mode's outline and
// a kind's press and hover, slots; its screen, a grid a frontend
// sizes (walk.zig `.index`).
.index = .{ .{ "active", Pardes, "focusPanes" }, .{ "window_pick", Pardes, "panes" }, .{ "kind_grab", Pardes, "panes" }, .{ "kind_hover", Pardes, "panes" }, .{ "screen_w", "grids" }, .{ "screen_h", "grids" } },
+ // Its geometry, read back as the session holds it (a view opened
+ // and not laid out yet has none, on a join's client too, whose
+ // kinds are told its views as the session's are): on its screen,
+ // a pane's rect and a column's `col_x` with its width (walk.zig
+ // `.within`).
+ .within = .{ .{ "rects", "onScreen" }, .{ "col_w", "columnOnScreen" } },
};
/// A view's slot in `Pardes.views`, as it crosses the core's edge: an
/// entry's argument or answer, the wire's welcome. A type of its own,
@@ -221,6 +223,19 @@ pub const View = struct {
return n >= 1 and n <= max_grid;
}
pub const max_grid = 4096;
+
+ /// Pane slot `id`'s rect on the screen, where the layout pass puts
+ /// every one (a frame is the screen's cells: one past it, drawn, is a
+ /// cell outside the frame).
+ pub fn onScreen(v: *const View, id: usize) bool {
+ const r = v.rects[id];
+ return @as(u32, r.x) + r.w <= v.screen_w and @as(u32, r.y) + r.h <= v.screen_h;
+ }
+
+ /// Column `c` on the screen: its left edge and its width.
+ pub fn columnOnScreen(v: *const View, c: usize) bool {
+ return @as(u32, v.col_x[c]) + v.col_w[c] <= v.screen_w;
+ }
};
gpa: std.mem.Allocator,
diff --git a/core/dump.zig b/core/dump.zig
index 9dcc076e..b4561ae2 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -143,14 +143,6 @@ pub fn dumpExit(p: *Pardes) !void {
/// view showed in a dump made before the layer's lines were the buffer's
/// (wire 31 and older: a view's bit, no lines), its lines in it (jj.loaded).
fn afterLoad(p: *Pardes) void {
- // Each view laid out again over its columns and its screen, as a resize
- // lays it out: its geometry is derived, never read (View.replica).
- const live = p.live;
- for (p.views, 0..) |slot, k| if (slot != null) {
- p.live = @intCast(k);
- layout.compute(p);
- };
- p.live = live;
for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| {
const text = pardes.panes.File.fileText(f, p.scratch.allocator()) catch continue;
f.context.reload(p.tree_sitter_gpa, f.path, text, f.revision);
@@ -1036,24 +1028,45 @@ test "a dump keeps the session's settings, and a restore applies them" {
try std.testing.expect(!restored.settings.wrap);
}
-test "a view's geometry is laid out again at a load, never read: a pane's rect past its screen in a dump is the layout's after it" {
- // The fuzz's restore road, seed 589: an image whose pane 0 said 534
- // rows on a 24-row screen, drawn: surface.zig's `at` asserted.
+test "a view's geometry is read back as the session holds it, never laid out again; a rect or a column off its screen is refused, the field named" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
- const want = p.view().rects[0];
- p.view().rects[0].h = 534;
- p.view().col_w[0] = 900;
- const dumped = try dumpBytes(p);
- defer gpa.free(dumped);
- p.view().rects[0] = want;
- const q = try load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, dumped, null);
- defer q.deinit();
- try std.testing.expectEqual(want, q.view().rects[0]);
- try std.testing.expectEqual(@as(u16, 80), q.view().col_w[0]);
- _ = q.frame_arena.reset(.retain_capacity);
- _ = try q.render(q.frame_arena.allocator());
+ // Not what the layout pass would make of its columns (a view opened
+ // and not laid out yet has no rects at all): as the session has it.
+ p.view().rects[0].h -= 1;
+ const held = p.view().rects[0];
+ inline for (.{ byteDump, dumpBytes }) |dumpOf| {
+ const bytes = try dumpOf(p);
+ defer gpa.free(bytes);
+ const q = try load(gpa, p.opts, bytes, null);
+ defer q.deinit();
+ try std.testing.expectEqual(held, q.view().rects[0]);
+ }
+ // The fuzz's restore road, seed 589: an image whose pane 0 said 534
+ // rows on a 24-row screen, drawn: surface.zig's `at` asserted.
+ const Off = struct { at: *u16, to: u16, why: []const u8 };
+ for ([_]Off{
+ .{ .at = &p.view().rects[0].h, .to = 534, .why = "View.rects[0] is not within" },
+ .{ .at = &p.view().col_w[0], .to = 900, .why = "View.col_w[0] is not within" },
+ // A column's edge is held with its width.
+ .{ .at = &p.view().col_x[0], .to = 900, .why = "View.col_w[0] is not within" },
+ }) |off| {
+ const was = off.at.*;
+ off.at.* = off.to;
+ defer off.at.* = was;
+ inline for (.{ byteDump, dumpBytes }) |dumpOf| {
+ const bytes = try dumpOf(p);
+ defer gpa.free(bytes);
+ var notes: std.ArrayList(u8) = .empty;
+ defer notes.deinit(gpa);
+ try std.testing.expectError(error.BadDump, load(gpa, p.opts, bytes, &notes));
+ std.testing.expect(std.mem.indexOf(u8, notes.items, off.why) != null) catch |err| {
+ std.debug.print("refused, but not by {s}: {s}\n", .{ off.why, notes.items });
+ return err;
+ };
+ }
+ }
}
test "a dump whose index names no view or pane there is refused, the field named; a top past its text is its last line; a key's replay is not dumped" {
diff --git a/core/replica.zig b/core/replica.zig
index 46320fea..4126972a 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -6615,6 +6615,45 @@ test "a kind's place moved in a step of another view's: a replica's key that rea
try agrees(a, r);
}
+/// Placed, plain (PA_PLAIN): a client runs it, and its state is the rows
+/// its last view was told.
+const Viewed = struct {
+ const pa = pardes.Kind.c;
+ const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Viewed", .opens = 1, .doc = "the rows its view was told" })};
+ 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 = "viewed".* ++ @as([10]u8, @splat(0)), .version = 1, .exts = "", .flags = pa.PA_PLAIN, .words = &words, .nwords = 1 }),
+ .open = Placed.open,
+ .paint = Placed.paint,
+ .view = Placed.view,
+ });
+};
+
+test "a client joins with its session's geometry as the session holds it: the view opened for it, not laid out yet, is not laid out in the client either, and a plain kind is told the same views on both" {
+ // The soak's (test/replicas.zig): a client parted at its first unit
+ // after its join, `addon pdf: its state after view is not the
+ // session's`: it had laid every view out at its load, its own new one
+ // too, which the session lays out at that view's first input.
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host());
+ defer a.deinit();
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ const viewed = pardes.Kind.loadedOf(&Viewed.ops, "/x/viewed.so", @splat(7), &words);
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &viewed } });
+ _ = try a.local(.{ .command = "Viewed" });
+ const kid = a.core.view().active;
+ const joined = (try a.join(1, null)).?;
+ defer gpa.free(joined.dump);
+ const r = try Replica.initDump(gpa, 1, joined.view, joined.dump, .{ .cols = 80, .rows = 24 });
+ defer r.deinit();
+ try std.testing.expect(r.loaded(joined.digest));
+ try runsHere(r, kid, &Viewed.ops);
+ try std.testing.expectEqual(a.core.views[joined.view].?.rects[kid], r.core().views[joined.view].?.rects[kid]);
+ // The session's own step tells the kind each view whose facts changed.
+ r.confirm(try a.local(.tick));
+ r.settle();
+ try agrees(a, r);
+}
+
/// A kind whose every key asks a job, for the job tokens' test.
const Jobber = struct {
const pa = pardes.Kind.c;
diff --git a/core/walk.zig b/core/walk.zig
index 25e4bdc3..51b0a384 100644
--- a/core/walk.zig
+++ b/core/walk.zig
@@ -249,8 +249,6 @@ const Past = struct { name: []const u8, says: usize, holds: usize };
/// its own.
fn pastHeld(comptime T: type, v: *const T, held: ?*const [pairs(T)]usize) ?Past {
inline for (0..comptime pairs(T)) |i| {
- // A buffer no dump carries (derived) is made again, not read.
- if (comptime excluded(T, T.replica.len[i][0])) continue;
const buffer = @field(v, T.replica.len[i][0]);
const holds = if (comptime @typeInfo(@TypeOf(buffer)) == .array) (if (held) |h| @min(h[i], buffer.len) else buffer.len) else buffer.len;
const says = lengthIn(v, T.replica.len[i][1]);
@@ -276,6 +274,10 @@ fn pastHeld(comptime T: type, v: *const T, held: ?*const [pairs(T)]usize) ?Past
// // Its last place, a function of the struct (`fn (*const T) usize`),
// // or its first and last (`[2]usize`).
// .place = .{ .{ "scroll", "lastLine" } },
+// // Where each of its entries (as far as its length says) may be,
+// // a predicate of the struct by the entry's place in the field
+// // (`fn (*const T, usize) bool`): a view's rects on its screen.
+// .within = .{ .{ "rects", "onScreen" } },
// // What a load that left one of its things out (another build's
// // pane) does to what names it (`fn (*T) void`), before its indexes
// // are held.
@@ -286,18 +288,20 @@ fn pastHeld(comptime T: type, v: *const T, held: ?*const [pairs(T)]usize) ?Past
// the disk) is held to them where its fields end, beside its lengths
// (`pastHeld`), every declaration of every type at once: an index that names
// none is REFUSED, its field named (the dump is not the session: the view,
-// the pane it names is not there); a place past its thing's last is that
-// LAST (the session is there, its view a line off). A field that names a
-// slot by its type (`Pane.Id`, `View.Id`) and says nothing is a compile
-// error (`checkSlots`); a bare integer that does is found by reading, as
-// the lengths' were, until it is typed as its slot.
+// the pane it names is not there), and so is an entry that is not where it
+// may be (no session's: a rect past its screen); a place past its thing's
+// last is that LAST (the session is there, its view a line off). A field
+// that names a slot by its type (`Pane.Id`, `View.Id`) and says nothing is
+// a compile error (`checkSlots`); a bare integer that does is found by
+// reading, as the lengths' were, until it is typed as its slot.
fn declared(comptime T: type, comptime kind: []const u8) usize {
return if (@hasDecl(T, "replica") and @hasField(@TypeOf(T.replica), kind)) @field(T.replica, kind).len else 0;
}
-/// An index read back that names none of what it says it indexes.
-const Unnamed = struct { holder: []const u8, name: []const u8, says: usize, of: []const u8 };
+/// An index read back that names none of what it says it indexes, or
+/// (`within`) the entry `says` of a field that is not where it may be.
+const Unnamed = struct { holder: []const u8, name: []const u8, says: usize, of: []const u8, within: bool = false };
/// What an index field says, as a number: an integer, an optional one's (null
/// names nothing), a slot's enum's (`Pane.Id`).
@@ -395,6 +399,11 @@ fn heldIndexes(comptime T: type, v: *T) ?Unnamed {
if (comptime d.len == 2) if (firstUnnamed(T, v, d[0], T, v, d[1])) |i|
return .{ .holder = @typeName(T), .name = d[0], .says = i, .of = @typeName(T) ++ "." ++ d[1] };
}
+ inline for (0..comptime declared(T, "within")) |k| {
+ const d = T.replica.within[k];
+ for (0..heldOf(T, v, d[0])) |i| if (!@field(T, d[1])(v, i))
+ return .{ .holder = @typeName(T), .name = d[0], .says = i, .of = @typeName(T) ++ "." ++ d[1], .within = true };
+ }
inline for (comptime heldIn(T)) |U| if (visit(T, v, U, T, v, 0)) |bad| return bad;
return null;
}
@@ -461,7 +470,10 @@ fn holdTo(l: anytype, comptime T: type, out: *T, held: *const [pairs(T)]usize, d
}
if (comptime @hasDecl(T, "replica")) if (comptime @hasField(@TypeOf(T.replica), "left_out")) if (l.dropped != dropped) @field(T, T.replica.left_out)(out);
if (heldIndexes(T, out)) |bad| {
- l.note("{s}.{s} says {d}, which names none of {s}: refused", .{ bad.holder, bad.name, bad.says, bad.of });
+ if (bad.within)
+ l.note("{s}.{s}[{d}] is not within {s}: refused", .{ bad.holder, bad.name, bad.says, bad.of })
+ else
+ l.note("{s}.{s} says {d}, which names none of {s}: refused", .{ bad.holder, bad.name, bad.says, bad.of });
return error.BadDump;
}
}
@@ -499,10 +511,11 @@ fn checkAnnotations(comptime T: type) void {
continue;
}
inline for (@field(T.replica, kind)) |entry| {
- const pair = comptime std.mem.eql(u8, kind, "len") or std.mem.eql(u8, kind, "alloc") or std.mem.eql(u8, kind, "index") or std.mem.eql(u8, kind, "place");
+ const held = comptime std.mem.eql(u8, kind, "index") or std.mem.eql(u8, kind, "place") or std.mem.eql(u8, kind, "within");
+ const pair = comptime held or std.mem.eql(u8, kind, "len") or std.mem.eql(u8, kind, "alloc");
const name = if (pair) entry[0] else entry;
if (!@hasField(T, name)) @compileError("walk: " ++ @typeName(T) ++ " annotates no field " ++ name);
- if (comptime std.mem.eql(u8, kind, "index") or std.mem.eql(u8, kind, "place")) {
+ if (held) {
const H = if (entry.len >= 3) entry[1] else T;
const what = if (entry.len >= 3) entry[2] else entry[1];
if (entry.len == 4) if (!@hasField(T, entry[3])) @compileError("walk: " ++ @typeName(T) ++ " counts its span by no field " ++ entry[3]);
@@ -3146,7 +3159,7 @@ test "a length past what its buffer holds is refused where it is read back (a ta
try std.testing.expectError(error.BadDump, get.get(Room, (try Get.member(root, "room")).?));
}
-test "an index read back that names none of its things is refused, its field named, in a tape, a dump and an image; a place past its thing's last is that last" {
+test "an index read back that names none of its things is refused, its field named, in a tape, a dump and an image, and so is an entry not where it may be; a place past its thing's last is that last" {
const S = struct {
const Self = @This();
const Inner = struct {
@@ -3161,10 +3174,14 @@ test "an index read back that names none of its things is refused, its field nam
slot: ?u16 = null,
scroll: u32 = 0,
inner: [2]?*Inner = @splat(null),
- pub const replica = .{ .index = .{ .{ "live", "there" }, .{ "slot", "things" } }, .place = .{.{ "scroll", "last" }} };
+ edges: [2]u8 = @splat(0),
+ pub const replica = .{ .index = .{ .{ "live", "there" }, .{ "slot", "things" } }, .place = .{.{ "scroll", "last" }}, .within = .{.{ "edges", "inside" }} };
pub fn there(s: *const Self, i: usize) bool {
return i < s.things.len and s.things[i] != null;
}
+ pub fn inside(s: *const Self, i: usize) bool {
+ return s.edges[i] < 8;
+ }
pub fn last(_: *const Self) usize {
return 9;
}
@@ -3200,7 +3217,13 @@ test "an index read back that names none of its things is refused, its field nam
v.inner[1] = &bad_list;
break :blk v;
} },
+ .{ "S.edges[1] is not within", blk: {
+ var v = good;
+ v.edges = .{ 7, 8 };
+ break :blk v;
+ } },
};
+ const n_bad = bad.len;
var notes: std.ArrayList(u8) = .empty;
// A dump.
@@ -3239,14 +3262,14 @@ test "an index read back that names none of its things is refused, its field nam
pub fn run(ctx: @This(), cursor: *Mem.Cursor(.read_write)) !void {
const map = try Mem.HashMap(.read_write).init(cursor.*);
try ctx.put.member(map, "good", S, ctx.good);
- inline for (0..4) |i| try ctx.put.member(map, std.fmt.comptimePrint("bad{d}", .{i}), S, &ctx.bad[i][1]);
+ inline for (0..n_bad) |i| try ctx.put.member(map, std.fmt.comptimePrint("bad{d}", .{i}), S, &ctx.bad[i][1]);
}
}{ .put = &put, .good = &good, .bad = &bad });
var get: Get = .init(a);
defer get.deinit();
const root = db.rootCursor().readOnly();
try std.testing.expectEqual(@as(u32, 9), (try get.get(S, (try Get.member(root, "good")).?)).scroll);
- inline for (0..4) |i| {
+ inline for (0..n_bad) |i| {
get.notes.clearRetainingCapacity();
try std.testing.expectError(error.BadDump, get.get(S, (try Get.member(root, std.fmt.comptimePrint("bad{d}", .{i}))).?));
try std.testing.expect(std.mem.indexOf(u8, get.notes.items, bad[i][0]) != null);