summaryrefslogtreecommitdiff
path: root/src/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 00:56:57 -0300
committerGabriel Schneider <[email protected]>2026-11-10 01:03:45 -0300
commit428898ae93543ab47f977b2f6f287a6bb9287625 (patch)
tree5ea2153fca819ce79f2688ed9ab74ea9da1e60bc /src/replica.zig
parent4e5e1802f3f685a70740e9527a154544b3588e33 (diff)
downloadpardes-428898ae93543ab47f977b2f6f287a6bb9287625.tar.gz
pardes-428898ae93543ab47f977b2f6f287a6bb9287625.zip
kinds: a kind's place is its last call's outcome, on the tape and in Slot.where_text on every core (digested now), which Jump and Recent read: they asked the kind through a taped placeOf that a Shadow answered from the place it last replayed, so a call in a step of another view's (after a window joined) moved the PDF's place unseen and the window's Esc back to it guessed 16:0.000000 1.000 against the authority's 16:0.000000 0.045
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/replica.zig')
-rw-r--r--src/replica.zig64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/replica.zig b/src/replica.zig
index 8b0f8c8e..330c3204 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -4265,3 +4265,67 @@ test "a replica with no code for a kind draws its pane from the authority's fram
try std.testing.expect(r.diverged == null);
try std.testing.expectEqual(digestOf(a), r.digest());
}
+
+/// A kind whose place (`where`) is the rows its last view was told: a
+/// session's step that tells it moves its place, never a key's.
+const Placed = struct {
+ const pa = pardes.Kind.c;
+ fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque {
+ const n: *u32 = @ptrCast(@alignCast(pardes.Kind.api.alloc.?(4)));
+ n.* = 0;
+ return n;
+ }
+ fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {}
+ fn view(st: ?*anyopaque, v: [*c]const pa.pa_view) callconv(.c) void {
+ const n: *u32 = @ptrCast(@alignCast(st.?));
+ n.* = v.*.rows;
+ }
+ fn where(st: ?*anyopaque, buf: [*c]u8, len: u32) callconv(.c) u32 {
+ const n: *u32 = @ptrCast(@alignCast(st.?));
+ return @intCast((std.fmt.bufPrint(buf[0..len], "1:0 {d}", .{n.*}) catch return 0).len);
+ }
+ const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Placed", .opens = 1, .doc = "a place" })};
+ const ops = std.mem.zeroInit(pardes.Kind.Ops, .{
+ .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "placed".* ++ @as([10]u8, @splat(0)), .version = 1, .exts = "", .words = &words, .nwords = 1 }),
+ .open = open,
+ .paint = paint,
+ .view = view,
+ .where = where,
+ });
+};
+
+test "a kind's place moved in a step of another view's: a replica's key that reads it guesses the authority's" {
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false);
+ defer a.deinit();
+ const r = try Replica.init(gpa, 1, try a.unit(0, 0), false);
+ defer r.deinit();
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words);
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } }));
+ // The replica's view opens the kind's pane, and an Esc goes back to
+ // the file (Last): view 0 has the file.
+ const own = try a.openView(1);
+ r.view = own.view;
+ r.confirm(own.unit);
+ for ([_]pardes.Event{ .{ .command = "Placed" }, .{ .key = .{ .cp = pardes.Key.escape } } }) |ev| {
+ r.confirm(try a.take(try r.input(ev)));
+ r.settle();
+ }
+ // View 0 resized, and a step of the session's own tells the kind: its
+ // place moves in a step whose view has the file, which reads it not.
+ var buf: [256]u8 = undefined;
+ r.confirm(try a.take(try inputOf(&buf, 2, 1, .{ .resize = .{ .cols = 80, .rows = 20 } })));
+ r.confirm(try a.local(.tick));
+ // The replica's Esc back to the kind's pane: its jump reads the place.
+ const fast = r.stats.fast;
+ const missed = r.stats.mispredicted;
+ const msg = try gpa.dupe(u8, try r.input(.{ .key = .{ .cp = pardes.Key.escape } }));
+ defer gpa.free(msg);
+ try std.testing.expectEqual(@as(usize, 1), r.applied);
+ r.confirm(try a.take(msg));
+ r.settle();
+ try std.testing.expectEqual(missed, r.stats.mispredicted);
+ try std.testing.expectEqual(fast + 1, r.stats.fast);
+ try agrees(a, r);
+}