From 4e28df7f8e02ceec66a9d62ca75f8ec006e26d7c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 05:28:45 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/walk.zig | 55 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'core/walk.zig') 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); -- cgit v1.3