From bce88593014a4078dc9259855944f9ddbc19fe54 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 23:14:10 -0300 Subject: views and the rollback copy: a live view's slot keeps no pointer into what the live core owns; a register's texts and a file's location rows are pinned, not copied views.zig: when a view goes live (to, close, drawOthers putting the live one back, only), its parked share is emptied (`emptied`): it was left holding copies of the pointers it handed the live fields (a column tag's text, a chord's argument, the presentation's), stale until it parked again. The rollback copy walks every slot: a stale pointer whose memory the live view had freed and another taken saved that other's bytes and put them back. A pane's share holds no pointer but its selections, which `unpark` already hands over. The test fails without it: a tag's text freed under view 0's stale slot, its memory taken by an allocation the copy has no business with, written under a held copy, and the copy put back. Registers.zig, locations.zig, rollback.zig: a register's values and joined text, and a file's location rows (the dropped ones, a query's saved), are replaced whole and never written, so the copy pins them as it does a file's text, freed raw (a safe build's free would write over one a copy still holds); rows pin whole with what each owns (`pinnedDeep`). In the harness at 30 ms the big copies were a file's location rows, 5-6 MB after the flood, not the register. ReleaseFast, 20 seeds, three clients, p99: copy 5.1 -> 0.22 ms at 30 ms (0.19-0.20 at 80 and 207); rollback 14.9 -> 9.5 ms at 30 ms (1.3-1.4 at 80 and 207), what is left being the replay's digests (half the harness's CPU is Wyhash over the whole core per replayed unit). Tests: a 2 MB register and 500 location rows pinned, not saved, and whole after a speculation drops them and the copy is put back. docs/next-daemon.md: the follow-ups. Co-Authored-By: Claude Opus 5.5 --- src/views.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/views.zig') diff --git a/src/views.zig b/src/views.zig index bf9b9147..b9760143 100644 --- a/src/views.zig +++ b/src/views.zig @@ -215,6 +215,7 @@ pub fn undumped(p: *Pardes, others: []const Dumped) !void { /// for one client (a Restore, `-l`) is one view. pub fn only(p: *Pardes) void { for (0..max) |k| if (k != p.view) close(p, @intCast(k)); + emptied(p, p.view); const k = p.view; if (k == 0) return; std.mem.swap(?*Parked, &p.parked[0], &p.parked[k]); @@ -390,6 +391,19 @@ pub fn to(p: *Pardes, k: u8) void { if (k == p.view) return; park(p); unpark(p, k); + emptied(p, k); +} + +/// View `k` is live: its slot, stale until it parks again (written whole +/// then), keeps no pointer to what it handed the live fields. A rollback +/// copy walks every slot (src/rollback.zig): one left there, freed by the +/// live view and the memory another's since, would be saved and its old +/// bytes put back over the other's. (A pane's share holds no pointer but +/// its selections, which `unpark` hands over.) +fn emptied(p: *Pardes, k: u8) void { + const slot = p.parked[k] orelse return; + slot.view = .{ .screen_w = p.screen_w, .screen_h = p.screen_h }; + slot.view.col_tags = @splat(.{ .what = .column, .gpa = p.gpa }); } /// A new view, as the live one is laid out and focused, with its panes @@ -431,6 +445,7 @@ pub fn close(p: *Pardes, k: u8) void { } else unreachable; park(p); unpark(p, other); + emptied(p, other); } const v = &p.parked[k].?.view; for (&v.col_tags) |*t| t.deinit(p.gpa); @@ -478,6 +493,7 @@ pub fn drawOthers(p: *Pardes, h: pardes.Host) !void { park(p); defer { copy(&fields, p, &p.parked[live].?.view); + emptied(p, live); p.view = live; for (p.panes) |s| if (s) |pane| { const pv = &pane.pv[live]; -- cgit v1.3