summaryrefslogtreecommitdiff
path: root/core/tape.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 12:01:49 -0300
committerGabriel Schneider <[email protected]>2026-11-20 13:53:22 -0300
commit579763e3aaca684ef638d621fe1b427ae96743df (patch)
treec89954221d124a2def34891ee9127f638c240740 /core/tape.zig
parent1d92d0151bf8206823074f73b9fa90e0220bff15 (diff)
downloadpardes-579763e3aaca684ef638d621fe1b427ae96743df.tar.gz
pardes-579763e3aaca684ef638d621fe1b427ae96743df.zip
tape: a session's tape is handed in by whoever starts it, step 9c (reports/pardes-handle-69-design.md section 3.4, P33's lean 5): PARDES_RECORD is read by the starter (tape.fromEnv, the old startFromEnv returning the tape: runtime/session.zig's start, one line, and the Mac's, one line) and handed in Options.tape, so Pardes.init and dump.initFromDump no longer start a tape and Pardes.create takes its options' tape or none, never the global; current, forget and adopt are the field's (deinit and restoreInner call p.tape's; the three free ones are deleted); restoreInner loads the replacement on the session's own tape and does not leave it in the replacement's kept options (a session with clients has its tape from no options, and Peers.stop puts the options' back); Authority.init hands its tape in the options; the in-process runner (test/session.zig) keeps the tape recordTape starts and hands it to each session it makes; the global is still set beside a recording tape (fromEnv, recordTape, Stepping, Peers) while the terminal's questions read it: after this change those are its only readers, 18 calls in 12 functions (core/panes.zig scrollBy, feedOutput, followRows, the positions value, feedLost, followOutput, resizeGrid x4, reloadTerminals x3, emulatorGpa; core/term Term.digest, Term.media; core/edit.zig shellRows; core/ninep/pty.zig finish's prompt value), besides Stepping, Peers and enter's safe-build check; the tape's bytes do not move (semantics df1f0502317ed362, cross_replay both ways against step 7 agree); a real session still records from its first call (process-test --replay 0 of 102 failed, behaviour-test --replay 275/275); tui core-test 857/1008 (151 skipped), shell-test 1048/1051, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275, process-test 1 of 144 (delask, passes alone), both soaks diverged 0 unequal 0 corpus 22 of 22 (bytes: the base's one now stop at 30 ms), daemon.py plain, --far (the Find: 0 mispredicted), --games, --window-clients, --restore (a Restore with a client attached), --upgrade both ways against merge31 (both failed once at the Adopt race in the chain and pass alone), addon-test 5/5; the macOS library (x86_64, aarch64) and FreeBSD build; gui unit-test 1645/1649 (the perf check's BaselineHarnessMismatch)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/tape.zig')
-rw-r--r--core/tape.zig38
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" },