diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Turn.zig | 10 | ||||
| -rw-r--r-- | core/tape.zig | 32 |
2 files changed, 25 insertions, 17 deletions
diff --git a/core/Turn.zig b/core/Turn.zig index 687e287f..249c6795 100644 --- a/core/Turn.zig +++ b/core/Turn.zig @@ -17,7 +17,6 @@ //! come from a shell performing a save between steps -- so a parked request //! is never the syscall's own. const std = @import("std"); -const tape = @import("tape.zig"); const Turn = @This(); @@ -46,6 +45,10 @@ restores: u64 = 0, lsp_answers: u64 = 0, /// All of the above, and `out` reaching zero. settled: std.Io.Condition = .init, +/// Every `yield`, ever: a replica's step makes none (each syscall of its +/// core is a tape site), which its tape checks by this count across a +/// speculation and a replayed input (core/tape.zig `stray`). +yields: u64 = 0, /// The editor's thread takes the turn for good; it has it until `stop`. pub fn start(t: *Turn, io: std.Io) void { @@ -79,10 +82,7 @@ pub fn wake(t: *Turn) void { /// a step. Nests: a directory listing that resolves each entry yields /// inside a yield, and only the outermost one lets go. pub fn yield(t: *Turn) void { - // A replica makes no syscall: each is a site of the tape's. One that - // is none stops a speculation and diverges a replay (it joins - // again), never the process (a window client's `Term fish`, H17). - if (tape.replaying()) tape.stray(); + t.yields +%= 1; const io = t.io orelse return; yield_depth += 1; if (yield_depth != 1) return; diff --git a/core/tape.zig b/core/tape.zig index 934bc499..c32c4453 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -280,6 +280,8 @@ pub const Tape = struct { /// checks. speculating: bool = false, poisoned: bool = false, + /// The turn's yields when the speculation began (`stray`). + yields: u64 = 0, /// What stopped it: a host function's or a site's name, or a poison's /// reason (PARDES_REPLICA_STATS counts them). poisoned_by: []const u8 = "", @@ -664,6 +666,9 @@ pub const Tape = struct { defer t.applying = outer; t.host_side = true; defer t.host_side = true; + // Not at the end: the dump checked there reads through no tape. + const yields = pardes.turn.yields; + defer if (input != .deinit) t.stray(yields); switch (input) { .init, .init_from_dump => { var opts = switch (input) { @@ -858,11 +863,13 @@ pub const Tape = struct { return t.replay or t.speculating; } - /// A syscall of the core's that is no site, made by a replica: what it - /// returns is the authority's to say. A speculation waits for it, and a - /// replay has diverged. - pub fn stray(t: *Tape) void { - if (t.through) return; + /// A syscall of the core's that is no site, made by a replica since the + /// turn's count of yields was `since`: what it returned is the + /// authority's to say. A speculation waits for it, and a replay has + /// diverged (it joins again), never the process (a window client's + /// `Term fish`, H17). + fn stray(t: *Tape, since: u64) void { + if (pardes.turn.yields == since) return; if (t.speculating) t.poisoned = true else t.diverge("a syscall that is no tape site, made replaying", .{}); } @@ -1328,10 +1335,6 @@ pub fn replaying() bool { return (on orelse &none).replaying(); } -pub fn stray() void { - (on orelse &none).stray(); -} - /// A replica speculating (core/replica.zig): state only the authority /// changes (a terminal's emulator) is left alone, and the input waits. pub fn speculating() bool { @@ -1462,12 +1465,14 @@ pub fn beginSpeculation(t: *Tape) void { t.poisoned_by = ""; t.touched = false; t.no_digest = true; + t.yields = pardes.turn.yields; t.buf.clearRetainingCapacity(); t.seeFields(); } /// Whether it stayed clean (no host call, no syscall, no authority state). pub fn endSpeculation(t: *Tape) bool { + t.stray(t.yields); t.speculating = false; t.no_digest = false; return !t.poisoned; @@ -1642,16 +1647,19 @@ test "a syscall that is no site, made replaying, diverges the replay and poisons defer t.scratch.deinit(); defer t.arena.deinit(); defer if (t.diverged) |why| gpa.free(why); - on = &t; - defer on = null; + const since = pardes.turn.yields; + t.stray(since); + try std.testing.expect(t.diverged == null); pardes.turn.yield(); pardes.turn.back(); + t.stray(since); try std.testing.expect(t.diverged != null); t.replay = false; t.speculating = true; + t.yields = pardes.turn.yields; pardes.turn.yield(); pardes.turn.back(); - try std.testing.expect(t.poisoned); + try std.testing.expect(!endSpeculation(&t)); } test "a replay that finds no answer where its core reads one diverges, and the read goes on harmless" { |
