summaryrefslogtreecommitdiff
path: root/core/tape.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/tape.zig')
-rw-r--r--core/tape.zig11
1 files changed, 8 insertions, 3 deletions
diff --git a/core/tape.zig b/core/tape.zig
index 52eb6c03..19fdccd1 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -806,8 +806,13 @@ pub const Tape = struct {
return t.value(.budget, overNow, .{ since_ns, budget_ns });
}
+ /// A body whose first parameter is an `std.Io` its caller does not pass
+ /// is handed the tape's (`args` are the rest): the only way core/ comes
+ /// to hold one.
fn call(t: *Tape, 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.?;
+ const params = @typeInfo(@TypeOf(f)).@"fn".param_types;
+ const full = if (comptime params.len == args.len + 1 and params[0] == std.Io) .{t.io} ++ args else args;
comptime {
const Listed = if (@typeInfo(R) == .error_union) anyerror!@typeInfo(R).error_union.payload else R;
for (results) |T| {
@@ -815,7 +820,7 @@ pub const Tape = struct {
} 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 (t.through) return if (yields) out(f, args) else @call(.auto, f, args);
+ if (t.through) return if (yields) out(f, full) else @call(.auto, f, full);
const id: u16 = @as(u16, host_fns.len) + @backingInt(s);
if (comptime s == .read_file) t.reading = args[1];
defer if (comptime s == .read_file) {
@@ -833,7 +838,7 @@ pub const Tape = struct {
}
// The host's own (a shell's spawn asking the shell), or one inside a
// site's syscall: the outer call is the record.
- if (t.host_side) return if (yields) out(f, args) else @call(.auto, f, args);
+ if (t.host_side) return if (yields) out(f, full) else @call(.auto, f, full);
// A syscall a speculating replica must not make: its input waits for
// the authority's answer.
if (yields and t.speculating) {
@@ -850,7 +855,7 @@ pub const Tape = struct {
t.record(.host, u16, &id);
t.seeFields();
t.host_side = true;
- const r = if (yields) out(f, args) else @call(.auto, f, args);
+ const r = if (yields) out(f, full) else @call(.auto, f, full);
t.host_side = false;
t.noteWrites();
t.record(.ret, R, &r);