From 1b38ca0aa0bfae1177f80a6713ec6d787d2f77d4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 18:23:20 -0300 Subject: kinds #39, paint writes nothing a step reads and the digest is every Slot field a step reads (ยง17.2 B 2-3): the Slot says what is the kind's own or a frame's (its code and memory, its jobs' inputs, a placeholder's record, the place its kind says, the thumb, the pointer, whether a frame was drawn) and the walker digests the rest, `placed` and the prefix leave the Shadow's frame (the pointer its one byte), the dump carries the cancelled tokens a replica's job answers are dropped by, and a pane test dumps a session with a PDF and a picture, loads it on another core and compares every Slot field the walk does not leave out, so a field added and not dumped fails a test, not a soak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/screen_state.zig | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) (limited to 'src/screen_state.zig') diff --git a/src/screen_state.zig b/src/screen_state.zig index 6bef70a6..70e1614f 100644 --- a/src/screen_state.zig +++ b/src/screen_state.zig @@ -1297,8 +1297,8 @@ test "a replica's terminal pane draws as its authority's does" { // // A replica's core has no code for a library's kind: such a pane is drawn // from the authority's frame of it, painted at the size the peer's view -// gives it. A frame crosses as its size, the prefix the kind gave it and -// whether it placed a picture, each row by its hash (with its cells when +// gives it. A frame crosses as its size and the pointer it asks for, each +// row by its hash (with its cells when // the peer's row there is another), then each placement, with its raster's // bytes when the peer was not sent that key with the frame before. The // stream is ordered and loses nothing, so what the authority last sent a @@ -1317,8 +1317,6 @@ pub const Shadow = struct { places: std.ArrayList(Place) = .empty, /// Each placement's raster, owned, beside it. rasters: std.ArrayList([]u8) = .empty, - prefix: Kind.Buf(96) = .{}, - placed: bool = false, pointer: u8 = 0, pub fn deinit(sh: *Shadow, gpa: std.mem.Allocator) void { @@ -1345,10 +1343,7 @@ pub const Shadow = struct { sh.cols = cols; sh.rows = rows; } - const flags = try r.takeByte(); - sh.placed = flags & 1 != 0; - sh.pointer = flags >> 1; - sh.prefix.set(try r.take(try r.takeByte())); + sh.pointer = try r.takeByte(); for (0..rows) |y| { sh.hashes[y] = try r.takeInt(u64, .little); if (try r.takeByte() == 0) continue; @@ -1397,7 +1392,7 @@ pub const ShadowSent = struct { cols: u16 = 0, hashes: std.ArrayList(Hash) = .empty, keys: std.ArrayList(u64) = .empty, - prefix: Hash = 0, + pointer: u8 = 0, pub fn deinit(s: *ShadowSent, gpa: std.mem.Allocator) void { s.hashes.deinit(gpa); @@ -1406,22 +1401,18 @@ pub const ShadowSent = struct { } }; -/// Frame `f` of a pane (its prefix and `placed` from its slot) for a peer +/// Frame `f` of a pane (the pointer its paint asked for) for a peer /// that was last sent `sent`: false, and nothing written, when it holds /// this frame already. The message is `budget` bytes at most (the wire's /// bound, which a peer's reader takes as the link's end past it): each /// placement the peer holds crosses as its key, and a new one's raster /// only while it fits; one that does not is left out of the frame (the /// peer shows the pane without it) and is not tried again until it moves. -pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Frame, prefix: []const u8, placed: bool, pointer: u8, budget: usize, w: *std.Io.Writer) !bool { +pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Frame, pointer: u8, budget: usize, w: *std.Io.Writer) !bool { var hashes: std.ArrayList(Hash) = .empty; errdefer hashes.deinit(gpa); for (0..f.rows) |y| try hashes.append(gpa, std.hash.Wyhash.hash(0, std.mem.sliceAsBytes(f.cells[y * f.cols ..][0..f.cols]))); const places = f.places[0..f.n]; - const prefix_len = @min(prefix.len, 96); - // Whether it placed a picture, and the pointer it asks for, one byte. - const flags: u8 = @intFromBool(placed) | @as(u8, @min(pointer, 127)) << 1; - const prefix_hash = std.hash.Wyhash.hash(flags, prefix); const rowHeld = struct { fn at(s: *const ShadowSent, cols: u16, hs: []const Hash, y: usize) bool { return s.cols == cols and y < s.hashes.items.len and s.hashes.items[y] == hs[y]; @@ -1429,7 +1420,7 @@ pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Fr }.at; // Its size but for the placements: the head, each row's hash and the // rows the peer does not hold, the placements' count. - var size: usize = 6 + prefix_len + 1; + var size: usize = 6; for (0..f.rows) |y| size += 9 + if (rowHeld(sent, f.cols, hashes.items, y)) 0 else @as(usize, f.cols) * 20; const place_head = 57; var crosses: [64]bool = @splat(false); @@ -1442,7 +1433,7 @@ pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Fr size += more; keys += 1; } - var same = sent.cols == f.cols and std.mem.eql(Hash, sent.hashes.items, hashes.items) and sent.prefix == prefix_hash and sent.keys.items.len == keys; + var same = sent.cols == f.cols and std.mem.eql(Hash, sent.hashes.items, hashes.items) and sent.pointer == pointer and sent.keys.items.len == keys; if (same) { var k: usize = 0; for (places, 0..) |pl, i| if (i < crosses.len and crosses[i]) { @@ -1456,9 +1447,7 @@ pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Fr } try w.writeInt(u16, f.cols, .little); try w.writeInt(u16, f.rows, .little); - try w.writeByte(flags); - try w.writeByte(@intCast(prefix_len)); - try w.writeAll(prefix[0..prefix_len]); + try w.writeByte(pointer); for (hashes.items, 0..) |h, y| { try w.writeInt(u64, h, .little); const held = rowHeld(sent, f.cols, hashes.items, y); @@ -1486,7 +1475,7 @@ pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Fr sent.hashes.deinit(gpa); sent.hashes = hashes; sent.cols = f.cols; - sent.prefix = prefix_hash; + sent.pointer = pointer; sent.keys.clearRetainingCapacity(); for (places, 0..) |pl, i| if (i < crosses.len and crosses[i]) try sent.keys.append(gpa, pl.key); return true; @@ -1507,17 +1496,16 @@ test "a pane of a kind crosses as its frame, a row or a raster the peer holds as defer sh.deinit(gpa); var out: std.Io.Writer.Allocating = .init(gpa); defer out.deinit(); - try std.testing.expect(try encodeShadow(gpa, &sent, &f, "fake", true, 0, 1 << 20, &out.writer)); + try std.testing.expect(try encodeShadow(gpa, &sent, &f, 0, 1 << 20, &out.writer)); try sh.apply(gpa, out.written()); try std.testing.expectEqualStrings("a", sh.cells[0].text[0..1]); - try std.testing.expectEqualStrings("fake", sh.prefix.slice()); try std.testing.expectEqual(@as(u8, 3), sh.rasters.items[0][2]); // The same frame again: nothing to send. out.clearRetainingCapacity(); - try std.testing.expect(!try encodeShadow(gpa, &sent, &f, "fake", true, 0, 1 << 20, &out.writer)); + try std.testing.expect(!try encodeShadow(gpa, &sent, &f, 0, 1 << 20, &out.writer)); // A cell of the second row moves: the first row and the raster go as hashes. cells[4].flags = Kind.c.PA_PAINTED; - try std.testing.expect(try encodeShadow(gpa, &sent, &f, "fake", true, 0, 1 << 20, &out.writer)); + try std.testing.expect(try encodeShadow(gpa, &sent, &f, 0, 1 << 20, &out.writer)); try std.testing.expect(out.written().len < 20 + 2 * 9 + 3 * 20 + 60); try sh.apply(gpa, out.written()); try std.testing.expectEqual(@as(u8, Kind.c.PA_PAINTED), sh.cells[4].flags); @@ -1542,16 +1530,16 @@ test "a pane of a kind's raster past the message's bound is left out of its fram defer out.deinit(); // Room for the frame and the small raster, not the 256-byte one. const budget = 200; - try std.testing.expect(try encodeShadow(gpa, &sent, &f, "p", false, 0, budget, &out.writer)); + try std.testing.expect(try encodeShadow(gpa, &sent, &f, 0, budget, &out.writer)); try std.testing.expect(out.written().len <= budget); try sh.apply(gpa, out.written()); try std.testing.expectEqual(@as(usize, 1), sh.places.items.len); try std.testing.expectEqual(@as(u64, 2), sh.places.items[0].key); // Nothing moved: nothing to send, the big one not tried again. out.clearRetainingCapacity(); - try std.testing.expect(!try encodeShadow(gpa, &sent, &f, "p", false, 0, budget, &out.writer)); + try std.testing.expect(!try encodeShadow(gpa, &sent, &f, 0, budget, &out.writer)); // With room, it crosses, the small one as its key. - try std.testing.expect(try encodeShadow(gpa, &sent, &f, "p", false, 0, 1 << 20, &out.writer)); + try std.testing.expect(try encodeShadow(gpa, &sent, &f, 0, 1 << 20, &out.writer)); try sh.apply(gpa, out.written()); try std.testing.expectEqual(@as(usize, 2), sh.places.items.len); try std.testing.expectEqual(@as(u8, 7), sh.rasters.items[0][5]); -- cgit v1.3