summaryrefslogtreecommitdiff
path: root/core/dump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 02:56:05 -0300
committerGabriel Schneider <[email protected]>2026-11-24 04:15:45 -0300
commit2645734806155dac927967289b0f11683eb3a1d0 (patch)
tree069a7d03c2e481d2c232cd26b53ee122a6c09be3 /core/dump.zig
parentf0f2a5125fd4b034ebcd424afd4a55c3185191ab (diff)
downloadpardes-2645734806155dac927967289b0f11683eb3a1d0.tar.gz
pardes-2645734806155dac927967289b0f11683eb3a1d0.zip
walk: a loaded index is held to what it names, and a place to its thing, by a declaration beside the field, read by the comptime walk and checked where `pastHeld` is (the end of a struct's fields in all three decoders: a tape's `decode`, a byte dump's `Loader.fields`, an image's `Get.fields`, through `holdTo`): `replica.index` says what a field names (a field's slots, a predicate's things, or, with a third word, the things of the struct holding it, held where ITS fields end over every value of the type it holds (`heldIn`, `visit`); a fourth word: a span counted from it), and one that names none is REFUSED, the field named, in the words `fromDump` and a Restore say (`Core.live says 9, which names none of Core.openViews: refused`); `replica.place` gives a field's last place (or its first and last) and one past it is that place (the session is there, its view a line off); `replica.left_out` is what a load that left a thing out (another build's pane) does to what named it before the indexes are held (`Pardes.dropMissing`, now every view's); a field that names a slot by its type (`Pane.Id`, `View.Id`) with no declaration is a compile error (`checkSlots`). RUN FIRST, each the dump fuzz with every loaded core drawn at its size, 40x12 and 200x60 and given keys and a wheel notch (core/fuzz.zig `use`), each a panic or an allocation past the fuzz's cap on the tree before: join seed 1761, `Pardes.multi_count` read as 2^30 sized a yank's register array at 17 GB (`d`, Registers.put): a step's own, now not dumped, with `multi_*`, `exec_depth`, `exec_column` (root.zig `kept_out`); join 3682, `File.State.scroll` past its text: `@intCast` into `wrap_line` (File.zig fillBody): clamped to its last line (`lastLine`; a slim dump's file, read again at its revival, to its saved bytes' lines), `scroll_row` to the top line's bytes; join 77, `Messages.head` past its ring (logMessage): clamped (`head`, `len`); restore 1211, `View.screen_h` 0, drawn (draw.zig paintHeaders: surface.zig `at`), and join 24086/28218 a screen sizing a 111 GB frame: a view's screen side is a grid a frontend sizes or the dump is refused: a cell at least (a zero refused, not clamped, as abi/wire.zig `getCols` refuses one), at most 4096 (`View.max_grid`: past any display's; the wire's 512x128 is a client's, and a session's own frontend is wider: a replica test's view is 500 rows); join 14189, `Pane.tag_lead` past i32 (Core.sync): held to the room its prefix is made in (`Pane.prefix_room`); join 18926, an undo's `Journal.done` past its steps (Text.zig `mark`): clamped, `Step.first..n` a span of the journal's entries (refused past them), and join 35489 `Journal.bytes` overflowing (`record`): held to what its entries hold. And a bitset a load made is freed with the rest when the load fails or what held it is let go (`Bits`, on `customs`): the 40,000-seed run's leak (16 KB, `Loader.value` `.bitset`), reached once a refusal came after one was read. Declared beside them, by the brief and by reading: `Pardes.live` (an open view), `theme_file_pane`; `View.active` (a pane there, or any slot in a window with none), `window_pick`, `kind_grab`, `kind_hover`; `Column.panes` (panes there, held as far as `n` now says: a `len` pair, so a digest and a dump take that far); `Pane.sized_by`, `prompt_view`, `search_pane`; `Jump.cur` (place), `Jump.Loc.pane`; the language server's awaited `pane`. TESTS (each site was a failing run first, above): walk.zig "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", "a thing another build's dump left out takes what named it with it (`left_out`), before the indexes are held"; dump.zig "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"
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/dump.zig')
-rw-r--r--core/dump.zig91
1 files changed, 76 insertions, 15 deletions
diff --git a/core/dump.zig b/core/dump.zig
index 10d36350..9dcc076e 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -563,21 +563,25 @@ fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void {
pane.terminal = try pardes.Term.open(&p.outside, pardes.panes.emulatorGpa(p.gpa), @max(1, pane.cols), @max(1, pane.rows));
}
-/// The panes a column lists that are not there (another build's dump left
-/// them out) taken out of it, and the keyboard on one that is.
-fn dropMissing(p: *Pardes) void {
- const v = p.view();
- for (0..p.view().ncol) |c| {
- var n: usize = 0;
- for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (id < MAX_PANES and p.panes[id] != null) {
- v.cols[c].panes[n] = id;
- n += 1;
- };
- v.cols[c].n = n;
- }
- if (v.active >= MAX_PANES or p.panes[v.active] == null) v.active = for (p.panes, 0..) |slot, i| {
- if (slot != null) break i;
- } else 0;
+/// The panes each view's columns list that are not there (another build's
+/// dump left them out) taken out of them, and its keyboard on one that is:
+/// at the load's end, and where the core's fields end (walk.zig
+/// `left_out`), before what names a pane is held to one there. Every view:
+/// the live one may not be one yet then. (Their lengths are held already.)
+pub fn dropMissing(p: *Pardes) void {
+ for (&p.views) |*slot| if (slot.*) |*v| {
+ for (v.cols[0..v.ncol]) |*col| {
+ var n: usize = 0;
+ for (col.panes[0..col.n]) |id| if (id < MAX_PANES and p.panes[id] != null) {
+ col.panes[n] = id;
+ n += 1;
+ };
+ col.n = n;
+ }
+ if (v.active >= MAX_PANES or p.panes[v.active] == null) v.active = for (p.panes, 0..) |s, i| {
+ if (s != null) break i;
+ } else 0;
+ };
}
/// The replacement core for a Restore of the dump at `from`, whose log says
@@ -1052,6 +1056,63 @@ test "a view's geometry is laid out again at a load, never read: a pane's rect p
_ = try q.render(q.frame_arena.allocator());
}
+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" {
+ // The fuzz's join road (core/fuzz.zig): `live` read past the views
+ // (views.zig `bit`), a file's top past its text (File.zig fillBody's
+ // `wrap_line`), and `multi_count` sizing a yank's register at 17 GB.
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\n");
+ const id = p.view().active;
+ const Refused = struct {
+ fn by(q: *Pardes, why: []const u8) !void {
+ inline for (.{ byteDump, dumpBytes }) |dumpOf| {
+ const bytes = try dumpOf(q);
+ defer q.gpa.free(bytes);
+ var notes: std.ArrayList(u8) = .empty;
+ defer notes.deinit(q.gpa);
+ try std.testing.expectError(error.BadDump, load(q.gpa, q.opts, bytes, &notes));
+ std.testing.expect(std.mem.indexOf(u8, notes.items, why) != null) catch |err| {
+ std.debug.print("refused, but not by {s}: {s}\n", .{ why, notes.items });
+ return err;
+ };
+ }
+ }
+ };
+ // No view open to write the shares of (the live one's are its panes').
+ p.live = 9;
+ p.views_open = 0;
+ try Refused.by(p, "live says 9");
+ p.live = 0;
+ p.views_open = 1;
+ p.view().active = 9;
+ try Refused.by(p, ".active says 9");
+ p.view().active = id;
+ const col = &p.view().cols[0].panes[0];
+ col.* = 9;
+ try Refused.by(p, "Column.panes says 9");
+ col.* = id;
+ pane.sized_by = 7;
+ try Refused.by(p, "Pane.sized_by says 7");
+ pane.sized_by = 0;
+ // Where a thing is, past its end: its last place, the session there.
+ pane.file.?.scroll = 1 << 40;
+ p.multi_count = 1 << 30;
+ 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(@as(usize, 2), q.panes[id].?.file.?.scroll);
+ try std.testing.expectEqual(@as(usize, 1), q.multi_count);
+ _ = q.frame_arena.reset(.retain_capacity);
+ _ = try q.render(q.frame_arena.allocator());
+ }
+ pane.file.?.scroll = 0;
+ p.multi_count = 1;
+}
+
test "a session with every column it may hold dumps and restores them all" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 1200, .rows = 24 });