diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Core.zig | 15 | ||||
| -rw-r--r-- | core/dump.zig | 7 | ||||
| -rw-r--r-- | core/replica.zig | 1 | ||||
| -rw-r--r-- | core/tape.zig | 38 |
4 files changed, 26 insertions, 35 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" }, |
