diff options
Diffstat (limited to 'core/tape.zig')
| -rw-r--r-- | core/tape.zig | 38 |
1 files changed, 13 insertions, 25 deletions
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" }, |
