summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Core.zig15
-rw-r--r--core/dump.zig7
-rw-r--r--core/replica.zig1
-rw-r--r--core/tape.zig38
-rw-r--r--runtime/macos.zig1
-rw-r--r--runtime/session.zig1
-rw-r--r--test/session.zig15
7 files changed, 38 insertions, 40 deletions
diff --git a/core/Core.zig b/core/Core.zig
index e2f8cd8a..a92d35ae 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -528,9 +528,9 @@ pub const perform = @import("Effect.zig").perform;
/// second copy of this drifted once, leaving restored tags without an
/// allocator and every 9P mtime 0.
pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes {
- // The global still set beside the field (P20): a core made while
- // a tape records (PARDES_RECORD, a replica's step) is its.
- const tape = opts.tape orelse pardes.tape.on orelse &pardes.tape.none;
+ // Its options' (a recording session's, an authority's, a replay's), or
+ // the one nobody records.
+ const tape = opts.tape orelse &pardes.tape.none;
const p = try gpa.create(Pardes);
p.* = .{
.gpa = gpa,
@@ -561,10 +561,9 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes {
return p;
}
-/// A new session, its tape written from here when PARDES_RECORD asks.
+/// A new session, recorded from here on its options' tape.
pub fn init(gpa: std.mem.Allocator, opts: Options) !*Pardes {
// By hand, not `taped`: no core yet to enter on; the tape adopts the one made.
- pardes.tape.startFromEnv();
const taped = pardes.tape.enter(null, .{ .init = opts });
// The tape adopts the core made, none on a failure.
var made: ?*Pardes = null;
@@ -821,8 +820,8 @@ fn recentFound(p: *Pardes, hash: u64) ?recent_files.Entry {
pub fn deinit(p: *Pardes) void {
// By hand, not `taped`: what it records is no argument (`current`), and it leaves on no core.
- const taped = pardes.tape.enter(p, .{ .deinit = pardes.tape.current(p) });
- pardes.tape.forget(p);
+ const taped = pardes.tape.enter(p, .{ .deinit = p.tape.current(p) });
+ p.tape.forget(p);
defer pardes.tape.leave(null, taped);
if (std.c.getenv("PARDES_FRAMES")) |path| p.frames.dump(std.mem.span(path));
// Every file open now is closed with its dot, and the list kept.
@@ -2290,7 +2289,7 @@ pub const Options = struct {
/// A client's: the kinds it caught breaking PA_PLAIN, its frontend's
/// list, which outlives each core it joins with. In no tape and no dump.
distrusted: ?*pardes.Addon.Distrusted = null,
- /// The core's tape (`Pardes.tape`); null: `tape.on`'s, or `tape.none`.
+ /// The core's tape (`Pardes.tape`); null: `tape.none`.
tape: ?*pardes.tape.Tape = null,
/// What the host's scan of the addon directories found (Addon.scan).
addons: []const pardes.Kind.Loaded = &.{},
diff --git a/core/dump.zig b/core/dump.zig
index eb0ef263..3d248010 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -532,17 +532,20 @@ fn restoreInner(p: *Pardes, bytes: []const u8, from: []const u8) !*Pardes {
var opts = p.opts;
opts.cols = p.view().screen_w;
opts.rows = p.view().screen_h;
+ // Loaded on the session's tape (one with clients has it from no
+ // options), which the replacement's options do not keep.
+ opts.tape = p.tape;
const replacement = try loadAndRevive(p.gpa, opts, bytes, p, null);
+ replacement.opts.tape = p.opts.tape;
replacement.pointRestoreAt(from);
// The tape follows the replacement from here (it is the session).
- pardes.tape.adopt(replacement);
+ p.tape.adopt(replacement);
pardes.ctlfs.events.notePath(replacement, "restore", from);
return replacement;
}
pub fn initFromDump(gpa: std.mem.Allocator, opts: Options, bytes: []const u8) !*Pardes {
// By hand, not `taped`: no core yet to enter on, as `Pardes.init`.
- pardes.tape.startFromEnv();
const taped = pardes.tape.enter(null, .{ .init_from_dump = .{ .opts = opts, .bytes = bytes } });
// The tape adopts the core made, none on a failure.
var made: ?*Pardes = null;
diff --git a/core/replica.zig b/core/replica.zig
index 31e16f46..14f441b3 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -182,6 +182,7 @@ pub const Authority = struct {
a.t.whole_digest = screens and std.c.getenv("PARDES_REPLICA_TRACE") == null;
// A digest at a unit's end, as the session's (Peers.unit).
a.t.no_digest = true;
+ opts.tape = &a.t;
const was = Stepping.begin(&a.t, null);
defer was.end();
a.core = try Pardes.init(gpa, opts);
diff --git a/core/tape.zig b/core/tape.zig
index 1c9368d0..34c9f1da 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -1043,7 +1043,7 @@ pub inline fn enter(p: ?*Pardes, input: Input) Entered {
}
/// The tape an entry steps: its core's; for a session not made yet, the one
-/// its options name, or the one `Pardes.create` takes.
+/// its options name (`Pardes.create`'s).
fn tapeOf(p: ?*Pardes, input: *const Input) *Tape {
if (p) |core| return core.tape;
const opts = switch (input.*) {
@@ -1051,7 +1051,7 @@ fn tapeOf(p: ?*Pardes, input: *const Input) *Tape {
.init_from_dump => |d| d.opts,
else => return &none,
};
- return opts.tape orelse on orelse &none;
+ return opts.tape orelse &none;
}
/// Whether an entry on `t` is recorded: not on the tape nobody records, nor
@@ -1064,20 +1064,6 @@ pub inline fn leave(p: ?*Pardes, e: Entered) void {
if (e.tape) |t| t.leaveInput(p);
}
-// The entry points on `on`, the methods' (`Tape.site` and the rest).
-
-pub fn adopt(p: *Pardes) void {
- (on orelse &none).adopt(p);
-}
-
-pub fn current(p: *const Pardes) bool {
- return (on orelse &none).current(p);
-}
-
-pub fn forget(p: *Pardes) void {
- (on orelse &none).forget(p);
-}
-
/// An entry written once (P22): its public name made from the private
/// body directly under it, `pub const setCwd = pardes.tape.taped(setCwdInner);`.
/// The same parameters; the call recorded as the variant of `Input` whose
@@ -1593,19 +1579,21 @@ pub fn digestOf(p: *const Pardes) u64 {
return walk.digest(Pardes, p);
}
-/// PARDES_RECORD set: the tape is written from the session's first call.
-pub fn startFromEnv() void {
- if (on != null) return;
- const prefix = std.mem.span(libc.getenv("PARDES_RECORD") orelse return);
- if (prefix.len == 0) return;
+/// PARDES_RECORD set: the tape a session is written to from its first
+/// call, which whoever starts it hands in `Options.tape` (runtime/session.zig,
+/// the Mac's start). `on` too, while the terminal's questions read it (P20).
+pub fn fromEnv() ?*Tape {
+ const prefix = std.mem.span(libc.getenv("PARDES_RECORD") orelse return null);
+ if (prefix.len == 0) return null;
const gpa = std.heap.c_allocator;
var path_buf: [4096]u8 = undefined;
- const path = std.fmt.bufPrintSentinel(&path_buf, "{s}{d}.tape", .{ prefix, libc.getpid() }, 0) catch return;
+ const path = std.fmt.bufPrintSentinel(&path_buf, "{s}{d}.tape", .{ prefix, libc.getpid() }, 0) catch return null;
const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true, .CLOEXEC = true }, @as(libc.mode_t, 0o644));
- if (fd < 0) return;
- const t = gpa.create(Tape) catch return;
+ if (fd < 0) return null;
+ const t = gpa.create(Tape) catch return null;
t.* = .{ .gpa = gpa, .replay = false, .fd = fd, .scratch = .init(gpa), .arena = .init(gpa), .every = libc.getenv("PARDES_RECORD_EVERY") != null };
on = t;
+ return t;
}
/// `PARDES_REPLAY=<tape>`: the tape replayed into three replicas, each
@@ -1704,7 +1692,7 @@ test "a replay that finds no answer where its core reads one diverges, and the r
/// The functions of core/ that set `on` and leave a core's field be, each
/// with why the field is that tape already.
const sets_on_alone = [_]struct { []const u8, []const u8, []const u8 }{
- .{ "tape.zig", "startFromEnv", "no core yet: the one made next takes `on` (Pardes.create)" },
+ .{ "tape.zig", "fromEnv", "no core yet: its starter hands the tape in Options.tape" },
.{ "tape.zig", "replayBytes", "its replay's core is made with this tape in its options (apply)" },
.{ "replica.zig", "begin", "Stepping: the core stepped holds this tape already (adoptCore), which `enter` checks in a safe build" },
.{ "replica.zig", "end", "Stepping: `on` put back as `begin` found it" },
diff --git a/runtime/macos.zig b/runtime/macos.zig
index cfe93b13..4f9a9c33 100644
--- a/runtime/macos.zig
+++ b/runtime/macos.zig
@@ -348,6 +348,7 @@ fn initCore(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void {
pardes.syntax.start(allocs.tree_sitter);
errdefer pardes.syntax.stop();
+ opts.tape = pardes.tape.fromEnv();
const core = try pardes.Pardes.init(allocs.pardes, opts);
errdefer core.deinit();
// The workspace tag row is the macOS menu bar's business here (see
diff --git a/runtime/session.zig b/runtime/session.zig
index fdd72c2b..b1558d9f 100644
--- a/runtime/session.zig
+++ b/runtime/session.zig
@@ -75,6 +75,7 @@ pub fn Loop(comptime Frontend: type) type {
o.tree_sitter_allocator = l.allocs.tree_sitter;
o.frame_allocator = l.allocs.frame;
fe.options(&o);
+ o.tape = pardes.tape.fromEnv();
l.core = if (upgrade.resumed) |*rec|
try upgrade.load(l.gpa, l.allocs.pardes, o, rec)
else if (o.load_path) |lp| blk: {
diff --git a/test/session.zig b/test/session.zig
index 1cbee9df..d437ecf2 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -53,7 +53,7 @@ pub const Session = struct {
/// A session showing one file pane holding `text`, keeping what outlives
/// it in a database in memory (core/Db.zig).
pub fn initFile(gpa: std.mem.Allocator, text: []const u8) !Session {
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory });
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .tape = recording });
errdefer p.deinit();
_ = try p.setTestFile(text);
var s: Session = .{ .core = p, .arena = .init(gpa) };
@@ -75,7 +75,7 @@ pub const Session = struct {
/// A session showing one file pane, its startup file `init` (as
/// `~/.config/pardes/init` is read) applied first.
pub fn initStartup(gpa: std.mem.Allocator, init: []const u8) !Session {
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .startup_config = init });
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .startup_config = init, .tape = recording });
errdefer p.deinit();
_ = try p.setTestFile("x\n");
var s: Session = .{ .core = p, .arena = .init(gpa) };
@@ -85,7 +85,7 @@ pub const Session = struct {
/// A session showing its terminal pane, as `pardes` starts.
pub fn initTerm(gpa: std.mem.Allocator) !Session {
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory });
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .tape = recording });
var s: Session = .{ .core = p, .arena = .init(gpa) };
s.drain();
return s;
@@ -99,7 +99,7 @@ pub const Session = struct {
var arena: std.heap.ArenaAllocator = .init(gpa);
errdefer arena.deinit();
const config = try std.fmt.allocPrint(arena.allocator(), "DumpDir {s}\n", .{dir});
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .disk, .startup_config = config });
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .disk, .startup_config = config, .tape = recording });
var s: Session = .{ .core = p, .arena = arena };
s.drain();
return s;
@@ -206,12 +206,16 @@ pub const Session = struct {
s.drain();
}
+ /// The tape `recordTape` started: every session made after it records on it.
+ var recording: ?*pardes.tape.Tape = null;
+
/// Every session started from here on records what it consumes as a
/// tape in memory, as PARDES_RECORD has a real one record it
/// (core/tape.zig); `replayTape` replays it once the session is gone.
pub fn recordTape(gpa: std.mem.Allocator) !void {
const t = try gpa.create(pardes.tape.Tape);
t.* = pardes.tape.memory(gpa);
+ recording = t;
pardes.tape.on = t;
}
@@ -221,7 +225,8 @@ pub const Session = struct {
/// its end loaded to its digest and dumped to its bytes again. False
/// when a replica diverged (said on stderr). After `deinit`.
pub fn replayTape(gpa: std.mem.Allocator) bool {
- const t = pardes.tape.on orelse return true;
+ const t = recording orelse return true;
+ recording = null;
pardes.tape.on = null;
defer {
pardes.tape.release(t);