diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 17:33:23 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 19:32:42 -0300 |
| commit | f8e9b68309f657ce2cd3de0d2070fb70dc525339 (patch) | |
| tree | 64c41c2af6713a77791544d5fd03d39d3addd514 /core/draw.zig | |
| parent | 3ad8138b483031aeb9a406f1928891631e7e7833 (diff) | |
| download | pardes-f8e9b68309f657ce2cd3de0d2070fb70dc525339.tar.gz pardes-f8e9b68309f657ce2cd3de0d2070fb70dc525339.zip | |
replicas: a markdown text's tables are the whole text's, read at once by whoever asks first, never a reading under way that a frame moved (the audit of what a frame writes and a step reads, after Pane.notices): a step read a big text's table pads (a click's byte, a `j` over a table, through File.geometry -> Tables.ensure) from `File.State.tables`, which is derived (in no digest, no dump) yet carried a reading's progress: the first look read 4096 lines, the session's ticks read on 4 ms at a time, and an edit after a look took the short way past the read point; so a core that drew a frame before an edit (the frame's geometry made the first look at that revision) read on past line 4096 where one that had not drew began again and stopped there, and a client joined from a dump began from nothing where its session had read the text whole (then its tick asked the tape for a budget its session never read); the test `tables: a click on a big text's table is the same state whichever frame this process drew last` (a session that drew once and a replica joined from its dump that drew nothing, the same paste and a click on each cell of a table at line 5001) failed on the base (`expected 4, found 5`: the click put the caret on another byte) and passes; the fix reads the whole text at once in `Tables.ensure` (an edit still reflows only its block), deleting the budgeted reading (`pending`, `step`, `busy`, `frame_ns`, `first_lines`, the tick's call and `nextWake`'s, the key's word): its cost is the read at open, measured in ReleaseFast at 40 ns a line of prose and 18 ms for 2.7 MB of 2000 tables (docs/next-tables.md's stress text, generated), where it was 4096 lines then 4 ms a frame; and the class is kept closed two ways: `root.zig`'s `kept_out` names every `.local` and `.derived` field of core/ (68) with who writes it and why a step's read of it is the step's, a test failing on a new one not listed, and `draw.zig`'s `a frame changes nothing a step reads` steps a core that draws after every input (each frame at its own later time, and `presented`) and one joined from its dump that never draws through 600 random keys, clicks, wheels, pastes, commands, ticks and disk changes over a 4500-line markdown text with a table and a second pane, their digests equal after every step (16 seeds of 3000 steps agree); the audit's table is in the report (.scratch/sketch/reports/pardes-draw-2.md); the gates on this change: tui core-test 841/984 (143 skipped), shell-test 1020/1023, term 15/15, pane 183/184, kitty 45/45, behaviour-test 275/275 and --replay 275/275, process-test the base's two (lspcomplete, lspcompletemoved), gui unit-test 1618/1622 + BaselineHarnessMismatch (the base's); replicas --clients 5, the session drawing after every pump: diverged 0/0/0, unequal 0/0/0, deltas checked/wrong 2113/0, 1773/0, 1775/0, quiet checks 800/0, 794/0, 893/0, stops not on may_wait 0/0/0 (rtt 30/80/207), corpus through a client 22/22; daemon.py plain, --far, --games, --window-clients, --upgrade both ways (against pardes-tree/pfx-base) pass; cross_replay 28 digests agree each; macOS lib and FreeBSD rc 0; the frame and perf gate ran on the three changes together (d2-i3): frames 77/77 byte-identical, corpus2x +0.005% (noise 0.044%, bar 0.4%), the 97 per-operation counts within 0.1% (largest +0.031%)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/draw.zig')
| -rw-r--r-- | core/draw.zig | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/core/draw.zig b/core/draw.zig index dac6673e..88011373 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -1337,3 +1337,152 @@ test "a body with context rows is painted once, and the grid's rows are what a p // The layer's own rows run past the grid's. try std.testing.expect(layer.rows > body.rect.h); } + +// The class kept closed: a frame changes nothing a step reads. What a frame +// writes of a core is `.local` or `.derived` (in no digest and no dump: a +// pane's notice bands, the geometry's wrap map and context rows, a markdown +// text's tables), so a step that reads one must find what its own state +// makes. Here one core draws after every input, each frame at its own time +// after its step's, and one joined from its dump never draws: each input's +// step leaves the two with one digest. A field a frame leaves that a step +// then reads otherwise than a core that did not draw makes it, differs here. +// Not seen: a core joined later (its authority's reads are the tape's, which +// this has none of: the soak's late joins), and what no input here reaches. +test "a frame changes nothing a step reads: a core drawing after every input and one never drawing agree" { + const gpa = std.testing.allocator; + const steps: usize = if (std.c.getenv("PARDES_FUZZ_STEPS")) |v| std.fmt.parseInt(usize, std.mem.span(v), 10) catch 600 else 600; + const seed: u64 = if (std.c.getenv("PARDES_FUZZ_SEED")) |v| std.fmt.parseInt(u64, std.mem.span(v), 10) catch 11 else 11; + var prng = std.Random.DefaultPrng.init(seed); + const random = prng.random(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + for (0..4500) |i| try text.print(gpa, "line {d} {s}\n", .{ i, std.mem.asBytes(&@as([20][6]u8, @splat("words ".*)))[0 .. 6 * (i % 20)] }); + try text.appendSlice(gpa, "\n| name | qty | note |\n|:--|--:|:-:|\n| fig | 1 | ripe |\n| apple || |\n| a longer name | 12345 | x |\n\n## end\n"); + const metrics: pardes.RowMetrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 }; + const a = try Pardes.init(gpa, .{ .tty_only = true, .cols = 90, .rows = 30 }); + defer a.deinit(); + a.update(.{ .resize = .{ .cols = 90, .rows = 30, .row_metrics = metrics } }); + const pane = try a.setTestFile(text.items); + a.gpa.free(pane.file.?.path); + pane.file.?.path = try a.gpa.dupe(u8, "/notes.md"); + a.newScratchBelow(0); + a.view().active = 0; + pane.file.?.scroll = 4490; + pane.body.cur_row = 4502; + a.sync(); + const first = try pardes.dump.dumpBytes(a); + defer gpa.free(first); + const b = try pardes.dump.load(gpa, a.opts, first, null); + defer b.deinit(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const commands = [_][]const u8{ "Wrap", "Collapse", "Del", "Undo", "Redo" }; + var now: u64 = std.time.ns_per_s; + for (0..steps) |i| { + const v = a.view(); + // Most presses on the body around the table at the text's end. + const body = v.rects[0]; + const ev: pardes.Event = switch (random.uintLessThan(u8, 13)) { + 0...4 => .{ .key = .{ .cp = switch (random.uintLessThan(u8, 16)) { + 0 => pardes.Key.escape, + 1 => 'i', + 2 => 'G', + 3 => 'g', + 4 => ' ', + 5 => 'd', + 6 => 'w', + 7 => 'b', + 8 => 'u', + 9, 10 => 'j', + 11, 12 => 'k', + 13 => 'h', + 14 => 'l', + else => 'x', + } } }, + 5...7 => .{ .mouse = .{ + .button = if (random.uintLessThan(u8, 4) == 0) .wheel_up else if (random.uintLessThan(u8, 4) == 0) .wheel_down else .left, + .kind = switch (random.uintLessThan(u8, 3)) { + 0 => .press, + 1 => .drag, + else => .release, + }, + .col = if (random.boolean()) random.uintLessThan(u16, v.screen_w) else body.x + random.uintLessThan(u16, @max(1, @min(body.w, 40))), + .row = if (random.boolean()) random.uintLessThan(u16, v.screen_h) else body.y + random.uintLessThan(u16, @max(1, body.h)), + } }, + 8 => .{ .command = commands[random.uintLessThan(usize, commands.len)] }, + 9 => .{ .paste = "| new | row |\n" }, + // The text changed on disk: a step changes it whole. + 10 => .{ .file_changed = .{ .pane = 0, .bytes = text.items[0 .. text.items.len - random.uintLessThan(usize, 40)] } }, + else => blk: { + now += random.uintLessThan(u64, 2 * std.time.ns_per_s); + break :blk .tick; + }, + }; + for ([_]*Pardes{ a, b }) |p| { + p.clock.now_ns = now; + p.clock.stepped_ns = now; + p.update(ev); + } + // A frame is drawn at its own time, after its step's. + now += random.uintLessThan(u64, std.time.ns_per_s); + a.clock.now_ns = now; + b.clock.now_ns = now; + _ = arena.reset(.retain_capacity); + _ = try a.render(arena.allocator()); + a.presented(); + b.presented(); + if (apart(a, b)) { + std.debug.print("seed {d}, step {d}: a {s} left them apart\n", .{ seed, i, @tagName(ev) }); + return error.DigestsDiffer; + } + } +} + +/// Whether two cores' digests differ, field by field (the panes' and their +/// files' too), the fields that do named; but for the three that differ +/// between two cores in one test process whatever they do: a message's +/// stamp and a text's mtime, read off the wall clock with no tape, and a +/// scratch pane's cwd, inherited by pointer on one and owned bytes on one +/// loaded from a dump. +fn apart(a: *const Pardes, b: *const Pardes) bool { + var any = false; + const names = comptime pardes.walk.fieldNames(Pardes); + var da: [names.len]u64 = undefined; + var db: [names.len]u64 = undefined; + _ = pardes.walk.fieldDigests(Pardes, a, &da); + _ = pardes.walk.fieldDigests(Pardes, b, &db); + for (names, da, db) |name, x, y| if (x != y and !std.mem.eql(u8, name, "panes")) { + std.debug.print(" {s}\n", .{name}); + any = true; + }; + const pane_names = comptime pardes.walk.fieldNames(Pane); + for (a.panes, b.panes, 0..) |pa, pb, id| { + if ((pa == null) != (pb == null)) { + std.debug.print(" pane {d} open on one\n", .{id}); + any = true; + } + const x = pa orelse continue; + const y = pb orelse continue; + var pda: [pane_names.len]u64 = undefined; + var pdb: [pane_names.len]u64 = undefined; + _ = pardes.walk.fieldDigests(Pane, x, &pda); + _ = pardes.walk.fieldDigests(Pane, y, &pdb); + for (pane_names, pda, pdb) |name, u, v| if (u != v and !std.mem.eql(u8, name, "msg_said_ms") and !std.mem.eql(u8, name, "cwd")) { + if (std.mem.eql(u8, name, "file")) if (x.file) |*fx| if (y.file) |*fy| { + const file_names = comptime pardes.walk.fieldNames(panes.File.State); + var fda: [file_names.len]u64 = undefined; + var fdb: [file_names.len]u64 = undefined; + _ = pardes.walk.fieldDigests(panes.File.State, fx, &fda); + _ = pardes.walk.fieldDigests(panes.File.State, fy, &fdb); + for (file_names, fda, fdb) |file_name, q, r| if (q != r and !std.mem.eql(u8, file_name, "mtime")) { + std.debug.print(" pane {d}.file.{s}\n", .{ id, file_name }); + any = true; + }; + continue; + }; + std.debug.print(" pane {d}.{s}\n", .{ id, name }); + any = true; + }; + } + return any; +} |
