Skip to content

Commit 36b5da3

Browse files
committed
aio: maybe fix macos compilation
1 parent b900fd7 commit 36b5da3

File tree

8 files changed

+32
-27
lines changed

8 files changed

+32
-27
lines changed

src/aio.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub const EventSource = struct {
8585
};
8686

8787
/// Initialize a single operation for a IO function
88-
pub fn op(comptime op_type: Operation, values: Operation.map.getAssertContains(op_type), comptime link: Link) struct {
88+
pub fn op(comptime op_type: Operation, values: op_type.Type(), comptime link: Link) struct {
8989
op: @TypeOf(values),
9090
comptime tag: Operation = op_type,
9191
comptime link: Link = link,
@@ -212,7 +212,7 @@ pub inline fn multi(pairs: anytype) (Error || error{SomeOperationFailed})!void {
212212
}
213213

214214
/// Completes a single operation immediately, blocks until complete
215-
pub inline fn single(comptime op_type: Operation, values: Operation.map.getAssertContains(op_type)) (Error || @TypeOf(values).Error)!void {
215+
pub inline fn single(comptime op_type: Operation, values: op_type.Type()) (Error || op_type.Type().Error)!void {
216216
var cpy: @TypeOf(values) = values;
217217
var err: @TypeOf(values).Error = error.Success;
218218
cpy.out_error = &err;

src/aio/IoUring.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const UringOperation = struct {
4343
// TODO: avoid storing this
4444
timeout: std.os.linux.kernel_timespec,
4545

46-
fn init(comptime op_type: Operation, op: Operation.map.getAssertContains(op_type)) @This() {
46+
fn init(comptime op_type: Operation, op: op_type.Type()) @This() {
4747
return switch (op_type) {
4848
.child_exit => .{
4949
.child_exit = .{
@@ -220,28 +220,28 @@ pub fn complete(self: *@This(), mode: aio.CompletionMode, handler: anytype) aio.
220220
}, state, cqe);
221221
},
222222
inline .socket, .accept => |tag| blk: {
223-
var op: Operation.map.getAssertContains(tag) = undefined;
223+
var op: tag.Type() = undefined;
224224
op.out_id = self.ops.getOne(.out_id, id);
225225
op.out_error = @ptrCast(self.ops.getOne(.out_error, id));
226226
op.out_socket = self.ops.getOne(.out_result, id).cast(*std.posix.socket_t);
227227
break :blk uring_handle_completion(tag, op, undefined, cqe);
228228
},
229229
inline .read, .readv, .read_tty, .recv, .recv_msg => |tag| blk: {
230-
var op: Operation.map.getAssertContains(tag) = undefined;
230+
var op: tag.Type() = undefined;
231231
op.out_id = self.ops.getOne(.out_id, id);
232232
op.out_error = @ptrCast(self.ops.getOne(.out_error, id));
233233
op.out_read = self.ops.getOne(.out_result, id).cast(*usize);
234234
break :blk uring_handle_completion(tag, op, undefined, cqe);
235235
},
236236
inline .write, .writev, .send, .send_msg, .splice => |tag| blk: {
237-
var op: Operation.map.getAssertContains(tag) = undefined;
237+
var op: tag.Type() = undefined;
238238
op.out_id = self.ops.getOne(.out_id, id);
239239
op.out_error = @ptrCast(self.ops.getOne(.out_error, id));
240240
op.out_written = self.ops.getOne(.out_result, id).cast(?*usize);
241241
break :blk uring_handle_completion(tag, op, undefined, cqe);
242242
},
243243
inline .open_at => |tag| blk: {
244-
var op: Operation.map.getAssertContains(tag) = undefined;
244+
var op: tag.Type() = undefined;
245245
op.out_id = self.ops.getOne(.out_id, id);
246246
op.out_error = @ptrCast(self.ops.getOne(.out_error, id));
247247
op.out_file = self.ops.getOne(.out_result, id).cast(*std.fs.File);
@@ -268,7 +268,7 @@ pub fn complete(self: *@This(), mode: aio.CompletionMode, handler: anytype) aio.
268268
.wait_event_source,
269269
.close_event_source,
270270
=> |tag| blk: {
271-
var op: Operation.map.getAssertContains(tag) = undefined;
271+
var op: tag.Type() = undefined;
272272
op.out_id = self.ops.getOne(.out_id, id);
273273
op.out_error = @ptrCast(self.ops.getOne(.out_error, id));
274274
break :blk uring_handle_completion(tag, op, undefined, cqe);
@@ -443,7 +443,7 @@ fn uring_init(n: u16) aio.Error!std.os.linux.IoUring {
443443
return error.SystemOutdated;
444444
}
445445

446-
fn uring_queue(io: *std.os.linux.IoUring, comptime op_type: Operation, op: Operation.map.getAssertContains(op_type), link: aio.Link, user_data: u64, state: *UringOperation.State) aio.Error!void {
446+
fn uring_queue(io: *std.os.linux.IoUring, comptime op_type: Operation, op: op_type.Type(), link: aio.Link, user_data: u64, state: *UringOperation.State) aio.Error!void {
447447
debug("queue: {}: {}", .{ aio.Id.init(user_data), op_type });
448448
const Trash = struct {
449449
var u_64: u64 align(1) = undefined;
@@ -575,7 +575,7 @@ fn uring_copy_cqes(io: *std.os.linux.IoUring, cqes: []std.os.linux.io_uring_cqe,
575575
unreachable;
576576
}
577577

578-
fn uring_handle_completion(comptime op_type: Operation, op: Operation.map.getAssertContains(op_type), state: *UringOperation.State, cqe: *std.os.linux.io_uring_cqe) !void {
578+
fn uring_handle_completion(comptime op_type: Operation, op: op_type.Type(), state: *UringOperation.State, cqe: *std.os.linux.io_uring_cqe) !void {
579579
defer if (op_type == .child_exit and !Supported.waitid) {
580580
var watcher: posix.ChildWatcher = .{ .id = op.child, .fd = state.child_exit.state.fd };
581581
watcher.deinit();

src/aio/Posix.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub fn complete(self: *@This(), mode: aio.CompletionMode, handler: anytype) aio.
183183
if (pfd.revents & std.posix.POLL.ERR != 0) {
184184
switch (op_type) {
185185
inline else => |tag| {
186-
if (hasField(Operation.map.getAssertContains(tag).Error, "BrokenPipe")) {
186+
if (hasField(tag.Type().Error, "BrokenPipe")) {
187187
Uringlator.debug("poll: {}: {} => ERR (BrokenPipe)", .{ id, op_type });
188188
self.uringlator.finish(self, id, error.BrokenPipe, .thread_unsafe);
189189
} else {
@@ -248,7 +248,7 @@ pub fn immediate(pairs: anytype) aio.Error!u16 {
248248
return num_errors;
249249
}
250250

251-
fn blockingPosixExecutor(self: *@This(), comptime op_type: Operation, op: Operation.map.getAssertContains(op_type), id: aio.Id, readiness: posix.Readiness, comptime safety: Uringlator.Safety) void {
251+
fn blockingPosixExecutor(self: *@This(), comptime op_type: Operation, op: op_type.Type(), id: aio.Id, readiness: posix.Readiness, comptime safety: Uringlator.Safety) void {
252252
var failure: Operation.Error = error.Success;
253253
while (true) {
254254
posix.perform(op_type, op, readiness) catch |err| {
@@ -260,7 +260,7 @@ fn blockingPosixExecutor(self: *@This(), comptime op_type: Operation, op: Operat
260260
self.uringlator.finish(self, id, failure, safety);
261261
}
262262

263-
fn posixPerform(self: *@This(), comptime op_type: Operation, op: Operation.map.getAssertContains(op_type), id: aio.Id, readiness: posix.Readiness, kludge: enum { kludge, normal }) !void {
263+
fn posixPerform(self: *@This(), comptime op_type: Operation, op: op_type.Type(), id: aio.Id, readiness: posix.Readiness, kludge: enum { kludge, normal }) !void {
264264
if (needs_kludge and !builtin.single_threaded and kludge == .kludge) {
265265
if (self.in_flight_threaded == 0) {
266266
self.pfd.add(.{ .fd = self.source.fd, .events = std.posix.POLL.IN, .revents = 0 }) catch unreachable;
@@ -280,7 +280,7 @@ fn posixPerform(self: *@This(), comptime op_type: Operation, op: Operation.map.g
280280
}
281281
}
282282

283-
fn nonBlockingPosixExecutor(self: *@This(), comptime op_type: Operation, op: Operation.map.getAssertContains(op_type), id: aio.Id, readiness: posix.Readiness) error{WouldBlock}!void {
283+
fn nonBlockingPosixExecutor(self: *@This(), comptime op_type: Operation, op: op_type.Type(), id: aio.Id, readiness: posix.Readiness) error{WouldBlock}!void {
284284
var failure: Operation.Error = error.Success;
285285
posix.perform(op_type, op, readiness) catch |err| {
286286
if (err == error.WouldBlock) return error.WouldBlock;
@@ -289,7 +289,7 @@ fn nonBlockingPosixExecutor(self: *@This(), comptime op_type: Operation, op: Ope
289289
self.uringlator.finish(self, id, failure, .thread_unsafe);
290290
}
291291

292-
fn nonBlockingPosixExecutorFcntl(self: *@This(), comptime op_type: Operation, op: Operation.map.getAssertContains(op_type), id: aio.Id, readiness: posix.Readiness) error{ WouldBlock, FcntlFailed }!void {
292+
fn nonBlockingPosixExecutorFcntl(self: *@This(), comptime op_type: Operation, op: op_type.Type(), id: aio.Id, readiness: posix.Readiness) error{ WouldBlock, FcntlFailed }!void {
293293
const NONBLOCK = 1 << @bitOffsetOf(std.posix.O, "NONBLOCK");
294294
const old: struct { usize, bool } = blk: {
295295
if (readiness.fd != posix.invalid_fd) {
@@ -313,7 +313,7 @@ fn nonBlockingPosixExecutorFcntl(self: *@This(), comptime op_type: Operation, op
313313
self.uringlator.finish(self, id, failure, .thread_unsafe);
314314
}
315315

316-
fn openReadiness(comptime op_type: Operation, op: Operation.map.getAssertContains(op_type)) !posix.Readiness {
316+
fn openReadiness(comptime op_type: Operation, op: op_type.Type()) !posix.Readiness {
317317
return switch (op_type) {
318318
.nop => .{},
319319
.fsync => .{},
@@ -344,7 +344,7 @@ fn openReadiness(comptime op_type: Operation, op: Operation.map.getAssertContain
344344
};
345345
}
346346

347-
pub fn uringlator_queue(self: *@This(), id: aio.Id, comptime op_type: Operation, op: Operation.map.getAssertContains(op_type)) aio.Error!PosixOperation {
347+
pub fn uringlator_queue(self: *@This(), id: aio.Id, comptime op_type: Operation, op: op_type.Type()) aio.Error!PosixOperation {
348348
comptime {
349349
if (needs_kludge and builtin.single_threaded and op_type == .read_tty) {
350350
@compileError(
@@ -374,7 +374,7 @@ pub fn uringlator_queue(self: *@This(), id: aio.Id, comptime op_type: Operation,
374374
return .{ .readiness = readiness };
375375
}
376376

377-
pub fn uringlator_dequeue(self: *@This(), id: aio.Id, comptime op_type: Operation, op: Operation.map.getAssertContains(op_type)) void {
377+
pub fn uringlator_dequeue(self: *@This(), id: aio.Id, comptime op_type: Operation, op: op_type.Type()) void {
378378
switch (op_type) {
379379
.child_exit => {
380380
const readiness = self.uringlator.ops.getOne(.readiness, id);

src/aio/Windows.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub fn immediate(pairs: anytype) aio.Error!u16 {
217217
return num_errors;
218218
}
219219

220-
fn blockingPosixExecutor(self: *@This(), comptime op_type: Operation, op: Operation.map.getAssertContains(op_type), id: aio.Id, comptime safety: Uringlator.Safety) void {
220+
fn blockingPosixExecutor(self: *@This(), comptime op_type: Operation, op: op_type.Type(), id: aio.Id, comptime safety: Uringlator.Safety) void {
221221
const posix = @import("posix/posix.zig");
222222
var failure: Operation.Error = error.Success;
223223
while (true) {
@@ -251,7 +251,7 @@ fn getHandleAccessInfo(handle: HANDLE) !fs.FILE_ACCESS_FLAGS {
251251
return @bitCast(access.AccessFlags);
252252
}
253253

254-
pub fn uringlator_queue(_: *@This(), _: aio.Id, comptime op_type: Operation, op: Operation.map.getAssertContains(op_type)) aio.Error!WindowsOperation {
254+
pub fn uringlator_queue(_: *@This(), _: aio.Id, comptime op_type: Operation, op: op_type.Type()) aio.Error!WindowsOperation {
255255
switch (op_type) {
256256
.accept => op.out_socket.* = INVALID_SOCKET,
257257
else => {},
@@ -267,7 +267,7 @@ pub fn uringlator_queue(_: *@This(), _: aio.Id, comptime op_type: Operation, op:
267267
};
268268
}
269269

270-
pub fn uringlator_dequeue(_: *@This(), _: aio.Id, comptime op_type: Operation, _: Operation.map.getAssertContains(op_type)) void {}
270+
pub fn uringlator_dequeue(_: *@This(), _: aio.Id, comptime op_type: Operation, _: op_type.Type()) void {}
271271

272272
pub fn uringlator_start(self: *@This(), id: aio.Id, op_type: Operation) !void {
273273
switch (op_type) {

src/aio/ops.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,11 @@ pub const Operation = enum {
592592
.splice = Splice,
593593
});
594594

595+
pub fn Type(self: @This()) type {
596+
@setEvalBranchQuota(std.meta.fields(@This()).len * 1_000);
597+
return map.getAssertContains(self);
598+
}
599+
595600
pub const required: []const @This() = &.{
596601
.nop, .fsync, .poll, .read_tty, .read, .write, .readv, .writev, .accept, .connect,
597602
.bind, .listen, .recv, .send, .recv_msg, .send_msg, .shutdown, .open_at, .close_file, .close_dir,
@@ -610,7 +615,7 @@ pub const Operation = enum {
610615
return @alignCast(@ptrCast(self));
611616
}
612617

613-
pub fn init(comptime op_type: Operation, op: map.getAssertContains(op_type)) *@This() {
618+
pub fn init(comptime op_type: Operation, op: op_type.Type()) *@This() {
614619
@setRuntimeSafety(false);
615620
return switch (op_type) {
616621
.nop,

src/aio/posix/posix.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn symlinkAtUring(target: [*:0]const u8, dir: std.fs.Dir, link_path: [*:0]co
268268
};
269269
}
270270

271-
pub fn perform(comptime op_type: Operation, op: Operation.map.getAssertContains(op_type), readiness: Readiness) Operation.Error!void {
271+
pub fn perform(comptime op_type: Operation, op: op_type.Type(), readiness: Readiness) Operation.Error!void {
272272
switch (op_type) {
273273
.fsync => _ = try fsync(op.file.handle),
274274
.read_tty => op.out_read.* = try readTty(op.tty.handle, op.buffer, op.mode),

src/aio/uringlator.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ const UringlatorOperation = struct {
154154
flags: aio.Splice.Flags,
155155
},
156156

157-
fn init(comptime op_type: Operation, op: Operation.map.getAssertContains(op_type)) @This() {
157+
fn init(comptime op_type: Operation, op: op_type.Type()) @This() {
158158
var v: @FieldType(@This(), @tagName(op_type)) = undefined;
159159
inline for (std.meta.fields(@TypeOf(v))) |field| @field(v, field.name) = @field(op, field.name);
160160
return @unionInit(@This(), @tagName(op_type), v);
161161
}
162162

163-
pub fn toOp(self: @This(), comptime op_type: Operation, result: *Operation.anyresult) Operation.map.getAssertContains(op_type) {
164-
var op: Operation.map.getAssertContains(op_type) = undefined;
163+
pub fn toOp(self: @This(), comptime op_type: Operation, result: *Operation.anyresult) op_type.Type() {
164+
var op: op_type.Type() = undefined;
165165
inline for (std.meta.fields(@FieldType(@This(), @tagName(op_type)))) |field| {
166166
@field(op, field.name) = @field(@field(self, @tagName(op_type)), field.name);
167167
}

src/coro.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub const io = struct {
5757

5858
/// Completes a single operation immediately, blocks the coroutine until complete
5959
/// The IO operation can be cancelled by calling `wakeupFromIo`, or doing `aio.Cancel`
60-
pub inline fn single(comptime op_type: Operation, values: Operation.map.getAssertContains(op_type)) (Error || @TypeOf(values).Error)!void {
60+
pub inline fn single(comptime op_type: Operation, values: op_type.Type()) (Error || op_type.Type().Error)!void {
6161
var cpy: @TypeOf(values) = values;
6262
var err: @TypeOf(values).Error = error.Success;
6363
cpy.out_error = &err;

0 commit comments

Comments
 (0)