summaryrefslogtreecommitdiff
path: root/src/rollback.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/rollback.zig')
-rw-r--r--src/rollback.zig51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/rollback.zig b/src/rollback.zig
index b0394d22..bb3ac2dc 100644
--- a/src/rollback.zig
+++ b/src/rollback.zig
@@ -399,7 +399,7 @@ pub const Copy = struct {
const s = @typeInfo(T).@"struct";
inline for (s.field_names, s.field_types, s.field_attrs) |name, F, attr| {
if (attr.@"comptime") continue;
- if (comptime (annotated(T, "local", name) or annotated(T, "derived", name)) and unsaved(name)) continue;
+ if (comptime (annotated(T, "local", name) or annotated(T, "derived", name) or annotated(T, "authority", name)) and unsaved(name)) continue;
const at = @intFromPtr(&@field(v, name));
if (comptime walk.lengthOf(T, name) != null and @typeInfo(F) == .array) {
try c.save(at, walk.lengthIn(v, comptime walk.lengthOf(T, name).?) * @sizeOf(@typeInfo(F).array.child));
@@ -436,10 +436,15 @@ fn annotatedStruct(comptime T: type) bool {
/// (numbers, and a static name), and the rows a terminal was last read as
/// (a grid's worth of text, emptied when a copy is taken and when it is
/// put back: src/replica.zig), and a replica's predicted echo (src/echo.zig:
-/// the replica's, never its core's).
+/// the replica's, never its core's). And the store and Recent, a replica's
+/// own: on the host's heap (Pardes.recentGpa), which the epoch never puts a
+/// free off for, so their bytes put back would point at what is freed. A
+/// step reads what the authority holds of them off the tape
+/// (tape.authority), never a replica's.
fn unsaved(comptime name: []const u8) bool {
return std.mem.eql(u8, name, "effects") or std.mem.eql(u8, name, "in_q") or std.mem.eql(u8, name, "frames") or
- std.mem.eql(u8, name, "shell_rows") or std.mem.eql(u8, name, "echo");
+ std.mem.eql(u8, name, "shell_rows") or std.mem.eql(u8, name, "echo") or std.mem.eql(u8, name, "store") or
+ std.mem.eql(u8, name, "recent");
}
fn annotated(comptime T: type, comptime kind: []const u8, comptime name: []const u8) bool {
@@ -601,3 +606,43 @@ test "a file's location rows are pinned whole, with what they own, and come back
p.deinit();
try std.testing.expectEqual(@as(usize, 0), e.live.count());
}
+
+/// `Look <name>`, the name a file of the repository's, absolute.
+fn lookAt(buf: []u8, name: []const u8) ![]const u8 {
+ var cwd: [std.fs.max_path_bytes]u8 = undefined;
+ const dir = std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd;
+ return std.fmt.bufPrint(buf, "Look {s}/{s}", .{ std.mem.span(@as([*:0]u8, @ptrCast(dir))), name });
+}
+
+test "a rollback leaves the store and Recent as a speculation left them: they live on the host's heap, which no copy holds" {
+ var e: Epoch = .{ .child = std.testing.allocator };
+ defer e.deinit();
+ const gpa = e.allocator();
+ const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml", .image_allocator = gpa, .pdf_allocator = gpa, .tree_sitter_allocator = gpa, .frame_allocator = gpa });
+ p.pump(.{}) catch {};
+ var line: [std.fs.max_path_bytes + 16]u8 = undefined;
+ p.update(.{ .command = try lookAt(&line, "build.zig.zon") });
+ p.update(.{ .command = "Del" });
+ p.pump(.{}) catch {};
+ try std.testing.expectEqual(@as(usize, 1), p.store.closed.items.len);
+ // Both lists full to what they hold: the next of each moves them.
+ p.store.closed.shrinkAndFree(p.recentGpa(), p.store.closed.items.len);
+ p.recent.entries.shrinkAndFree(p.recentGpa(), p.recent.entries.items.len);
+ const recents = p.recent.entries.items.len;
+ var c: Copy = .{};
+ defer c.deinit();
+ try c.take(&e, p);
+ // A speculation opens a file and closes it (a Del a replica applies at
+ // once), and is undone.
+ p.update(.{ .command = try lookAt(&line, "build.zig") });
+ p.update(.{ .command = "Del" });
+ p.pump(.{}) catch {};
+ c.restore();
+ // What the store and Recent hold is where they say it is.
+ try std.testing.expectEqual(@as(usize, 2), p.store.closed.items.len);
+ try std.testing.expect(std.mem.endsWith(u8, p.store.closed.items[1].name, "build.zig"));
+ try std.testing.expectEqual(recents + 1, p.recent.entries.items.len);
+ p.deinit();
+ try std.testing.expectEqual(@as(usize, 0), e.live.count());
+}
+