summaryrefslogtreecommitdiff
path: root/core/rollback.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/rollback.zig')
-rw-r--r--core/rollback.zig37
1 files changed, 35 insertions, 2 deletions
diff --git a/core/rollback.zig b/core/rollback.zig
index a6c6e5bd..53c7b210 100644
--- a/core/rollback.zig
+++ b/core/rollback.zig
@@ -523,11 +523,12 @@ fn annotatedStruct(comptime T: type) bool {
/// 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.
+/// (tape.authority), never a replica's. And the core's tape (`Pardes.tape`,
+/// `Options.tape`): the process's, which a rollback leaves where it is.
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, "own_frames") or
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");
+ std.mem.eql(u8, name, "recent") or std.mem.eql(u8, name, "tape");
}
fn annotated(comptime T: type, comptime kind: []const u8, comptime name: []const u8) bool {
@@ -801,3 +802,35 @@ test "a rollback leaves the store and Recent as a speculation left them: they li
p.deinit();
try std.testing.expectEqual(@as(usize, 0), e.live.count());
}
+
+test "a core's tape is this process's own: no digest or dump holds it, and a rollback leaves it where it was set" {
+ 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, .tree_sitter_allocator = gpa, .frame_allocator = gpa });
+ p.pump(.{}) catch {};
+ // Given none, a core's tape is the one nobody records.
+ try std.testing.expect(p.tape == &pardes.tape.none);
+ var other = pardes.tape.memory(std.testing.allocator);
+ defer pardes.tape.release(&other);
+ const digest = walk.digest(Pardes, p);
+ const dumped = try pardes.dump.byteDump(p);
+ p.tape = &other;
+ try std.testing.expectEqual(digest, walk.digest(Pardes, p));
+ const again = try pardes.dump.byteDump(p);
+ try std.testing.expectEqualSlices(u8, dumped, again);
+ gpa.free(again);
+ gpa.free(dumped);
+ p.tape = &pardes.tape.none;
+ // Handed another while a copy is held (a client joins: replica.zig's
+ // Peers), it keeps it when the copy is put back.
+ var c: Copy = .{};
+ defer c.deinit();
+ try c.take(&e, p);
+ p.tape = &other;
+ try std.testing.expect(c.restore());
+ try std.testing.expect(p.tape == &other);
+ p.tape = &pardes.tape.none;
+ p.deinit();
+ try std.testing.expectEqual(@as(usize, 0), e.live.count());
+}