summaryrefslogtreecommitdiff
path: root/src/tape.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 15:57:57 -0300
committerGabriel Schneider <[email protected]>2026-10-30 16:29:54 -0300
commitf7a0b6d902f001cff0343e11263868c5356f33c6 (patch)
tree5d063c3f6a7d08a360b7bd3f7955221414101299 /src/tape.zig
parent5b120f481a5e581d5252c41a4ddcc3e28c8a07f3 (diff)
downloadpardes-f7a0b6d902f001cff0343e11263868c5356f33c6.tar.gz
pardes-f7a0b6d902f001cff0343e11263868c5356f33c6.zip
tape: an error crosses by its name, a stat as fs.OsStat, and the tape's shape is in wire.semantics: a replica of another build read its session's units as its own build's, so a window client of a terminal's session, or of the box's, read every error by a number its build gives another (451 of 505 names numbered otherwise in the Linux terminal's and window's builds, 244 between Linux and FreeBSD: pardes-gui replaying a terminal's tape panicked at `unexpected error code, found error.NonLocalPath`, and so did main's window client of a session on the box at its Look of a fifo) and a FreeBSD stat out of step (nlink 8 bytes there, 4 here); a name this build's set lacks is a divergence (error.NoSuchError), never another error; an anyerror (a host's report) reads back as one of tape.Failure's, a Debug build panicking at one outside it as it is taped; tape.shape (each taped type's fields, tags, enum names and numbers) in semantics refuses, in words, builds whose tapes differ (the stat taped as before: the Linux and FreeBSD builds hash to two), and a site whose result tape.results does not list is a compile error; walk's test of an error by its name
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/tape.zig')
-rw-r--r--src/tape.zig52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/tape.zig b/src/tape.zig
index 9f1cde42..3c8dd765 100644
--- a/src/tape.zig
+++ b/src/tape.zig
@@ -20,6 +20,8 @@
const std = @import("std");
const pardes = @import("pardes.zig");
const walk = @import("walk.zig");
+const host_io = @import("host_io.zig");
+const terminal = @import("terminal.zig");
const Pardes = pardes.Pardes;
const VTable = pardes.Host.VTable;
const libc = std.c;
@@ -107,6 +109,50 @@ pub const Site = enum(u16) {
prompt,
};
+/// What the sites return. wire.semantics hashes their shape with the
+/// rest of the tape's (`shape`), so two builds whose tapes differ in it
+/// refuse each other's replicas in words, and a site returning a type not
+/// listed is a compile error (`call`). An error union is listed as
+/// `anyerror!` its payload: an error goes by its name (walk.encode).
+pub const results = .{
+ void, bool,
+ u32, i64,
+ [8]u8, ?u64,
+ []const u8, ?[]const u8,
+ ?std.Io.File.Kind, ?pardes.Presentation.CellPosition,
+ ?pardes.filesystem.Resolved, pardes.filesystem.OsReadWrite,
+ anyerror!pardes.filesystem.OsStat, anyerror![]const u8,
+ anyerror![]u8, anyerror!void,
+ terminal.Told, ?pardes.ctlfs.pty.Printed,
+ @typeInfo(@TypeOf(terminal.greeting)).@"fn".return_type.?,
+};
+
+/// What a host reports to the core as failed (`shell_failed`, `save_failed`,
+/// `dump_failed`, `report_error`), as a replica reads it back: an error is
+/// taped by its name, and `anyerror` keeps no list of names to look one up
+/// in. ponytail: kept by hand, the sets of what a host reports from; one
+/// outside them is a Debug build's panic as it is taped (walk.encode) and a
+/// release build's divergence (the replica joins again). No host, none.
+pub const Failure = if (!pardes.hosted) error{} else ErrorOf(host_io.forkShell) || ErrorOf(pardes.filesystem.write) ||
+ ErrorOf(pardes.filesystem.readRestore) || ErrorOf(pardes.dump.restore) ||
+ @typeInfo(@TypeOf(pardes.config.User.dumpThemes(undefined, undefined, undefined, pardes.themes))).error_union.error_set ||
+ ErrorOf(host_io.Lsp.snapshot) ||
+ ErrorOf(host_io.Inbox.startReader) || std.Io.File.ReadStreamingError ||
+ error{ NoDumpDirectory, ListenFailed, WorkersUnavailable, WorkersBusy };
+
+fn ErrorOf(comptime f: anytype) type {
+ return @typeInfo(@typeInfo(@TypeOf(f)).@"fn".return_type.?).error_union.error_set;
+}
+
+/// Every type the tape carries, as walk.shape says it: wire.semantics's.
+pub const shape = blk: {
+ var types: []const type = &.{ Input, []const u64, struct { u8, u64 } };
+ for (results) |R| types = types ++ .{R};
+ for (host_fns) |f| types = types ++ .{@typeInfo(@typeInfo(@typeInfo(@FieldType(VTable, f)).optional.child).pointer.child).@"fn".return_type.?};
+ for (watched) |name| types = types ++ .{@FieldType(Pardes, name)};
+ break :blk walk.shape(types);
+};
+
/// Fields a host writes straight into the core between its calls.
const watched = .{ "native_images", "native_image_patches", "present_skipped", "shell_continuous", "needs_frame", "quit", "windowed", "active", "unattended" };
@@ -769,6 +815,12 @@ pub fn value(comptime s: Site, comptime f: anytype, args: anytype) @typeInfo(@Ty
fn call(comptime s: Site, a: ?std.mem.Allocator, comptime f: anytype, args: anytype, comptime yields: bool) @typeInfo(@TypeOf(f)).@"fn".return_type.? {
const R = @typeInfo(@TypeOf(f)).@"fn".return_type.?;
+ comptime {
+ const Listed = if (@typeInfo(R) == .error_union) anyerror!@typeInfo(R).error_union.payload else R;
+ for (results) |T| {
+ if (T == Listed) break;
+ } else @compileError("tape: the site ." ++ @tagName(s) ++ " returns " ++ @typeName(R) ++ ", which tape.results does not list");
+ }
// No tape where there is no host to record or replay one.
if (comptime !pardes.hosted) return if (yields) out(f, args) else @call(.auto, f, args);
const t = on orelse return if (yields) out(f, args) else @call(.auto, f, args);