diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 12:50:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 12:54:16 -0300 |
| commit | a355c7fee38bd940da12f330408639fc3875234b (patch) | |
| tree | 00afa5180d1d58d2c10b9e67d2c9b58de75d99ce /core/tape.zig | |
| parent | ea833164aa83d02119301a204b91ff9a8eeff27a (diff) | |
| download | pardes-a355c7fee38bd940da12f330408639fc3875234b.tar.gz pardes-a355c7fee38bd940da12f330408639fc3875234b.zip | |
tape: the two rules the global was hiding, as tests (the handle's step 3, its first part; pardes-handle-1's reading): every place that sets the global tape aside sets the core's field aside, a source check at the end of core/tape.zig over every function of core/ outside tests that writes `on` (`tape.on = `, or `on = ` in tape.zig), which must write a core's `tape` too (`p.tape = `, never an options' `opts.tape`) or be on `sets_on_alone` with why (startFromEnv: no core yet, the next one made takes `on`; replayBytes: its core is made with the tape in its options; Stepping's begin and end: the core stepped holds the tape already, which `enter` checks in a safe build), a listed function that writes none named stale; shown failing with dumpRoundTrip's two field lines taken out ("core/tape.zig: dumpRoundTrip sets tape.on and no core's `tape`"); and the idle tape: a client draws its own frame between its steps with `on` null and its core's field its own tape, neither replaying nor speculating, so `enter` must not record into an idle replica's tape when it reads the field (step 9's): the rule written at `enter`, and a test (a replica joined from a core's dump, Replica.draw twice) that its tape holds the bytes it held, not stepping, the host's side; shown failing with `enter` and `leave` made to read the field ("expected 0, found 6795"); no product line changed; core-test 840/983 (143 skipped; rollback's "a copy put back is the core as it was" failed once in the first run, an edit's second crossing a clock second, and its next test crashed on the epoch it left held; both passed in the next run), shell-test 1018/1021
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.zig | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/core/tape.zig b/core/tape.zig index bb55ce5a..a2cd1e3d 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -1009,6 +1009,14 @@ pub inline fn enter(p: ?*Pardes, input: Input) Entered { // goes at the last step): every entry a safe build makes checks it. // With none on, a client's core is entered between its steps (its own // frame drawn, Replica.draw), its tape idle. + // + // The idle tape, the rule for the step that has this read the field + // (P20's last): a client's tape between its steps is neither replaying + // nor speculating, and its core is entered all the same (its frame); + // `enter` must not record into an idle replica's tape. Only a tape + // stepping its core records. The test "a client's frame drawn between + // its steps records nothing into its idle tape" (this file's end) + // fails when it does. if (std.debug.runtime_safety) if (p) |core| if (if (on) |t| core.tape != t else core.tape.stepping()) @panic("tape: a core's field is not the tape being stepped (tape.on)"); const t = on orelse return .{}; @@ -1675,3 +1683,109 @@ test "a replay that finds no answer where its core reads one diverges, and the r try std.testing.expect(t.diverged != null); try std.testing.expect(!value(.denied, read, .{})); } + +/// 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", "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" }, +}; + +/// The function a line of code declares, or null. +fn declares(code: []const u8) ?[]const u8 { + var words = std.mem.tokenizeScalar(u8, code, ' '); + while (words.next()) |w| { + if (std.mem.eql(u8, w, "pub") or std.mem.eql(u8, w, "inline") or std.mem.eql(u8, w, "export")) continue; + if (!std.mem.eql(u8, w, "fn")) return null; + const rest = words.rest(); + return rest[0 .. std.mem.indexOfScalar(u8, rest, '(') orelse return null]; + } + return null; +} + +test "every place that sets the global tape aside sets the core's field aside: a function of core/ that writes `on` writes a core's `tape` too, or is listed with why" { + const gpa = std.testing.allocator; + const io = std.testing.io; + var dir = try std.Io.Dir.cwd().openDir(io, "core", .{ .iterate = true }); + defer dir.close(io); + var walker = try dir.walk(gpa); + defer walker.deinit(); + var wrong: usize = 0; + var seen: [sets_on_alone.len]bool = @splat(false); + var writers: usize = 0; + while (try walker.next(io)) |e| { + if (e.kind != .file or !std.mem.endsWith(u8, e.basename, ".zig")) continue; + const src = try e.dir.readFileAlloc(io, e.basename, gpa, .limited(16 << 20)); + defer gpa.free(src); + const own = std.mem.eql(u8, e.path, "tape.zig"); + var name: []const u8 = ""; + var sets_on = false; + var sets_field = false; + var in_test = false; + var lines = std.mem.splitScalar(u8, src, '\n'); + while (true) { + const line = lines.next(); + const text = line orelse ""; + if (std.mem.startsWith(u8, text, "test ")) in_test = true; + if (in_test) { + if (std.mem.eql(u8, text, "}")) in_test = false; + if (line != null) continue; + } + const code = std.mem.trim(u8, text[0 .. std.mem.indexOf(u8, text, "//") orelse text.len], " \t"); + const next = declares(code); + if (next != null or line == null) { + // The function before, judged. + if (sets_on) { + writers += 1; + const listed = for (sets_on_alone, 0..) |a, i| { + if (std.mem.eql(u8, a[0], e.path) and std.mem.eql(u8, a[1], name)) { + seen[i] = true; + break true; + } + } else false; + if (!sets_field and !listed) { + wrong += 1; + std.debug.print("core/{s}: {s} sets tape.on and no core's `tape`: put the core's field aside with it (as dumpRoundTrip does), or list it in tape.zig's sets_on_alone with why\n", .{ e.path, name }); + } + } + if (line == null) break; + name = next.?; + sets_on = false; + sets_field = false; + } + // A core's field: `p.tape = `, never an options' (`opts.tape`). + if (std.mem.indexOf(u8, code, ".tape = ")) |at| if (!std.mem.endsWith(u8, code[0..at], "opts")) { + sets_field = true; + }; + if (std.mem.indexOf(u8, code, "tape.on = ") != null) sets_on = true; + if (own) if (std.mem.indexOf(u8, code, "on = ")) |at| if (at == 0 or code[at - 1] == ' ') { + sets_on = true; + }; + } + } + for (sets_on_alone, seen) |a, s| if (!s) { + wrong += 1; + std.debug.print("core/{s}: {s} is on sets_on_alone and sets no tape.on: delete its line\n", .{ a[0], a[1] }); + }; + try std.testing.expect(writers >= sets_on_alone.len + 3); + try std.testing.expectEqual(@as(usize, 0), wrong); +} + +test "a client's frame drawn between its steps records nothing into its idle tape" { + const gpa = std.testing.allocator; + const p = try @import("ninep/testing.zig").withFile(gpa, "x\n"); + defer p.deinit(); + const bytes = try pardes.dump.dumpBytes(p); + defer p.gpa.free(bytes); + const r = try pardes.replica.Replica.initDump(gpa, 1, 0, bytes, .{ .cols = 80, .rows = 24 }); + defer r.deinit(); + // Between its steps: no tape on, its core's field its own tape, idle. + try std.testing.expect(on == null and r.core().tape == &r.t and !r.t.stepping()); + const was = r.t.buf.items.len; + _ = r.draw(.{ .ctx = null, .f = null }); + _ = r.draw(.{ .ctx = null, .f = null }); + try std.testing.expectEqual(was, r.t.buf.items.len); + try std.testing.expect(!r.t.stepping() and r.t.host_side); +} |
