authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-09 14:29:15-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-12-09 14:29:15-05:00
logf2911948341e1ba1fc03ba2678eaf0a3c4508fa3
tree7a32f0ddd22c822456ae360f73ff7f51dbe023df
parent676e416c86e2977f76b0cc1b9d3bc2b7ac6d7936
parent7e30e8390044fbd396966b6e21d2de980d6f915f
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #7362 from Vexu/std

zig fmt improvement and small miscellaneous fixes

25 files changed, 251 insertions(+), 215 deletions(-)

lib/std/auto_reset_event.zig+6-8
...@@ -30,10 +30,8 @@ pub const AutoResetEvent = struct {...@@ -30,10 +30,8 @@ pub const AutoResetEvent = struct {
30 // std.ResetEvent.wait() |30 // std.ResetEvent.wait() |
31 // | std.ResetEvent.set()31 // | std.ResetEvent.set()
32 // | std.ResetEvent.set()32 // | std.ResetEvent.set()
33 // std.ResetEvent.reset() | 33 // std.ResetEvent.reset() |
34 // std.ResetEvent.wait() | (missed the second .set() notification above)34 // std.ResetEvent.wait() | (missed the second .set() notification above)
35
36
37 state: usize = UNSET,35 state: usize = UNSET,
3836
39 const UNSET = 0;37 const UNSET = 0;
...@@ -70,7 +68,7 @@ pub const AutoResetEvent = struct {...@@ -70,7 +68,7 @@ pub const AutoResetEvent = struct {
70 if (state != UNSET) {68 if (state != UNSET) {
71 unreachable; // multiple waiting threads on the same AutoResetEvent69 unreachable; // multiple waiting threads on the same AutoResetEvent
72 }70 }
73 71
74 // lazily initialize the ResetEvent if it hasn't been already72 // lazily initialize the ResetEvent if it hasn't been already
75 if (!has_reset_event) {73 if (!has_reset_event) {
76 has_reset_event = true;74 has_reset_event = true;
...@@ -78,7 +76,7 @@ pub const AutoResetEvent = struct {...@@ -78,7 +76,7 @@ pub const AutoResetEvent = struct {
78 }76 }
7977
80 // Since the AutoResetEvent currently isnt set,78 // Since the AutoResetEvent currently isnt set,
81 // try to register our ResetEvent on it to wait 79 // try to register our ResetEvent on it to wait
82 // for a set() call from another thread.80 // for a set() call from another thread.
83 if (@cmpxchgWeak(81 if (@cmpxchgWeak(
84 usize,82 usize,
...@@ -121,7 +119,7 @@ pub const AutoResetEvent = struct {...@@ -121,7 +119,7 @@ pub const AutoResetEvent = struct {
121 unreachable; // multiple waiting threads on the same AutoResetEvent observed when timing out119 unreachable; // multiple waiting threads on the same AutoResetEvent observed when timing out
122 }120 }
123121
124 // This menas a set() thread saw our ResetEvent pointer, acquired it, and is trying to wake it up. 122 // This menas a set() thread saw our ResetEvent pointer, acquired it, and is trying to wake it up.
125 // We need to wait for it to wake up our ResetEvent before we can return and invalidate it.123 // We need to wait for it to wake up our ResetEvent before we can return and invalidate it.
126 // We don't return error.TimedOut here as it technically notified us while we were "timing out".124 // We don't return error.TimedOut here as it technically notified us while we were "timing out".
127 reset_event.wait();125 reset_event.wait();
...@@ -137,7 +135,7 @@ pub const AutoResetEvent = struct {...@@ -137,7 +135,7 @@ pub const AutoResetEvent = struct {
137 return;135 return;
138 }136 }
139137
140 // If the AutoResetEvent isn't set, 138 // If the AutoResetEvent isn't set,
141 // then try to leave a notification for the wait() thread that we set() it.139 // then try to leave a notification for the wait() thread that we set() it.
142 if (state == UNSET) {140 if (state == UNSET) {
143 state = @cmpxchgWeak(141 state = @cmpxchgWeak(
...@@ -226,4 +224,4 @@ test "std.AutoResetEvent" {...@@ -226,4 +224,4 @@ test "std.AutoResetEvent" {
226224
227 send_thread.wait();225 send_thread.wait();
228 recv_thread.wait();226 recv_thread.wait();
229}
\ No newline at end of file
227}
lib/std/c/openbsd.zig-1
...@@ -34,4 +34,3 @@ pub const pthread_attr_t = extern struct {...@@ -34,4 +34,3 @@ pub const pthread_attr_t = extern struct {
34};34};
3535
36pub extern "c" fn posix_memalign(memptr: *?*c_void, alignment: usize, size: usize) c_int;36pub extern "c" fn posix_memalign(memptr: *?*c_void, alignment: usize, size: usize) c_int;
37
lib/std/compress/deflate.zig+1-1
...@@ -316,7 +316,7 @@ pub fn InflateStream(comptime ReaderType: type) type {...@@ -316,7 +316,7 @@ pub fn InflateStream(comptime ReaderType: type) type {
316 comptime {316 comptime {
317 @setEvalBranchQuota(100000);317 @setEvalBranchQuota(100000);
318318
319 const len_lengths = //319 const len_lengths =
320 [_]u16{8} ** 144 ++320 [_]u16{8} ** 144 ++
321 [_]u16{9} ** 112 ++321 [_]u16{9} ** 112 ++
322 [_]u16{7} ** 24 ++322 [_]u16{7} ** 24 ++
lib/std/hash_map.zig+1-1
...@@ -1127,7 +1127,7 @@ test "std.hash_map put" {...@@ -1127,7 +1127,7 @@ test "std.hash_map put" {
1127test "std.hash_map putAssumeCapacity" {1127test "std.hash_map putAssumeCapacity" {
1128 var map = AutoHashMap(u32, u32).init(std.testing.allocator);1128 var map = AutoHashMap(u32, u32).init(std.testing.allocator);
1129 defer map.deinit();1129 defer map.deinit();
1130 1130
1131 try map.ensureCapacity(20);1131 try map.ensureCapacity(20);
1132 var i: u32 = 0;1132 var i: u32 = 0;
1133 while (i < 20) : (i += 1) {1133 while (i < 20) : (i += 1) {
lib/std/heap/general_purpose_allocator.zig+8-4
...@@ -184,8 +184,12 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -184,8 +184,12 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
184 const total_requested_bytes_init = if (config.enable_memory_limit) @as(usize, 0) else {};184 const total_requested_bytes_init = if (config.enable_memory_limit) @as(usize, 0) else {};
185 const requested_memory_limit_init = if (config.enable_memory_limit) @as(usize, math.maxInt(usize)) else {};185 const requested_memory_limit_init = if (config.enable_memory_limit) @as(usize, math.maxInt(usize)) else {};
186186
187 const mutex_init = if (config.MutexType) |T| T{} else187 const mutex_init = if (config.MutexType) |T|
188 if (config.thread_safe) std.Mutex{} else std.mutex.Dummy{};188 T{}
189 else if (config.thread_safe)
190 std.Mutex{}
191 else
192 std.mutex.Dummy{};
189193
190 const stack_n = config.stack_trace_frames;194 const stack_n = config.stack_trace_frames;
191 const one_trace_size = @sizeOf(usize) * stack_n;195 const one_trace_size = @sizeOf(usize) * stack_n;
...@@ -865,9 +869,9 @@ test "realloc large object to small object" {...@@ -865,9 +869,9 @@ test "realloc large object to small object" {
865}869}
866870
867test "overrideable mutexes" {871test "overrideable mutexes" {
868 var gpa = GeneralPurposeAllocator(.{.MutexType = std.Mutex}){872 var gpa = GeneralPurposeAllocator(.{ .MutexType = std.Mutex }){
869 .backing_allocator = std.testing.allocator,873 .backing_allocator = std.testing.allocator,
870 .mutex = std.Mutex{}874 .mutex = std.Mutex{},
871 };875 };
872 defer std.testing.expect(!gpa.deinit());876 defer std.testing.expect(!gpa.deinit());
873 const allocator = &gpa.allocator;877 const allocator = &gpa.allocator;
lib/std/macho.zig-1
...@@ -42,7 +42,6 @@ pub const uuid_command = extern struct {...@@ -42,7 +42,6 @@ pub const uuid_command = extern struct {
42 uuid: [16]u8,42 uuid: [16]u8,
43};43};
4444
45
46/// The version_min_command contains the min OS version on which this45/// The version_min_command contains the min OS version on which this
47/// binary was built to run.46/// binary was built to run.
48pub const version_min_command = extern struct {47pub const version_min_command = extern struct {
lib/std/meta.zig+51-39
...@@ -226,43 +226,55 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -226,43 +226,55 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
226 switch (@typeInfo(T)) {226 switch (@typeInfo(T)) {
227 .Pointer => |info| switch (info.size) {227 .Pointer => |info| switch (info.size) {
228 .One => switch (@typeInfo(info.child)) {228 .One => switch (@typeInfo(info.child)) {
229 .Array => |array_info| return @Type(.{ .Pointer = .{229 .Array => |array_info| return @Type(.{
230 .Pointer = .{
231 .size = info.size,
232 .is_const = info.is_const,
233 .is_volatile = info.is_volatile,
234 .alignment = info.alignment,
235 .child = @Type(.{
236 .Array = .{
237 .len = array_info.len,
238 .child = array_info.child,
239 .sentinel = sentinel_val,
240 },
241 }),
242 .is_allowzero = info.is_allowzero,
243 .sentinel = info.sentinel,
244 },
245 }),
246 else => {},
247 },
248 .Many, .Slice => return @Type(.{
249 .Pointer = .{
230 .size = info.size,250 .size = info.size,
231 .is_const = info.is_const,251 .is_const = info.is_const,
232 .is_volatile = info.is_volatile,252 .is_volatile = info.is_volatile,
233 .alignment = info.alignment,253 .alignment = info.alignment,
234 .child = @Type(.{ .Array = .{254 .child = info.child,
235 .len = array_info.len,
236 .child = array_info.child,
237 .sentinel = sentinel_val,
238 }}),
239 .is_allowzero = info.is_allowzero,255 .is_allowzero = info.is_allowzero,
240 .sentinel = info.sentinel,256 .sentinel = sentinel_val,
241 }}),257 },
242 else => {},258 }),
243 },
244 .Many, .Slice => return @Type(.{ .Pointer = .{
245 .size = info.size,
246 .is_const = info.is_const,
247 .is_volatile = info.is_volatile,
248 .alignment = info.alignment,
249 .child = info.child,
250 .is_allowzero = info.is_allowzero,
251 .sentinel = sentinel_val,
252 }}),
253 else => {},259 else => {},
254 },260 },
255 .Optional => |info| switch (@typeInfo(info.child)) {261 .Optional => |info| switch (@typeInfo(info.child)) {
256 .Pointer => |ptr_info| switch (ptr_info.size) {262 .Pointer => |ptr_info| switch (ptr_info.size) {
257 .Many => return @Type(.{ .Optional = .{ .child = @Type(.{ .Pointer = .{263 .Many => return @Type(.{
258 .size = ptr_info.size,264 .Optional = .{
259 .is_const = ptr_info.is_const,265 .child = @Type(.{
260 .is_volatile = ptr_info.is_volatile,266 .Pointer = .{
261 .alignment = ptr_info.alignment,267 .size = ptr_info.size,
262 .child = ptr_info.child,268 .is_const = ptr_info.is_const,
263 .is_allowzero = ptr_info.is_allowzero,269 .is_volatile = ptr_info.is_volatile,
264 .sentinel = sentinel_val,270 .alignment = ptr_info.alignment,
265 }})}}),271 .child = ptr_info.child,
272 .is_allowzero = ptr_info.is_allowzero,
273 .sentinel = sentinel_val,
274 },
275 }),
276 },
277 }),
266 else => {},278 else => {},
267 },279 },
268 else => {},280 else => {},
...@@ -296,17 +308,17 @@ pub fn assumeSentinel(p: anytype, comptime sentinel_val: Elem(@TypeOf(p))) Senti...@@ -296,17 +308,17 @@ pub fn assumeSentinel(p: anytype, comptime sentinel_val: Elem(@TypeOf(p))) Senti
296}308}
297309
298test "std.meta.assumeSentinel" {310test "std.meta.assumeSentinel" {
299 testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8 , undefined), 0)));311 testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
300 testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8 , undefined), 0)));312 testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
301 testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));313 testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));
302 testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8 , undefined), 0)));314 testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
303 testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16 , undefined), 0)));315 testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
304 testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));316 testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
305 testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8 , undefined), 3)));317 testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
306 testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8 , undefined), null)));318 testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
307 testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8 , undefined), null)));319 testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
308 testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8 , undefined), 0)));320 testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
309 testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8 , undefined), 0)));321 testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
310}322}
311323
312pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {324pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
lib/std/mutex.zig+1-1
...@@ -38,7 +38,7 @@ pub const Mutex = if (builtin.single_threaded)...@@ -38,7 +38,7 @@ pub const Mutex = if (builtin.single_threaded)
38else if (builtin.os.tag == .windows)38else if (builtin.os.tag == .windows)
39 WindowsMutex39 WindowsMutex
40else if (builtin.link_libc or builtin.os.tag == .linux)40else if (builtin.link_libc or builtin.os.tag == .linux)
41// stack-based version of https://github.com/Amanieu/parking_lot/blob/master/core/src/word_lock.rs41 // stack-based version of https://github.com/Amanieu/parking_lot/blob/master/core/src/word_lock.rs
42 struct {42 struct {
43 state: usize = 0,43 state: usize = 0,
4444
lib/std/os/linux.zig+1-1
...@@ -50,7 +50,7 @@ pub fn getauxval(index: usize) usize {...@@ -50,7 +50,7 @@ pub fn getauxval(index: usize) usize {
5050
51// Some architectures (and some syscalls) require 64bit parameters to be passed51// Some architectures (and some syscalls) require 64bit parameters to be passed
52// in a even-aligned register pair.52// in a even-aligned register pair.
53const require_aligned_register_pair = //53const require_aligned_register_pair =
54 std.Target.current.cpu.arch.isMIPS() or54 std.Target.current.cpu.arch.isMIPS() or
55 std.Target.current.cpu.arch.isARM() or55 std.Target.current.cpu.arch.isARM() or
56 std.Target.current.cpu.arch.isThumb();56 std.Target.current.cpu.arch.isThumb();
lib/std/os/linux/io_uring.zig+77-79
...@@ -31,7 +31,7 @@ pub const IO_Uring = struct {...@@ -31,7 +31,7 @@ pub const IO_Uring = struct {
31 pub fn init(entries: u12, flags: u32) !IO_Uring {31 pub fn init(entries: u12, flags: u32) !IO_Uring {
32 var params = mem.zeroInit(io_uring_params, .{32 var params = mem.zeroInit(io_uring_params, .{
33 .flags = flags,33 .flags = flags,
34 .sq_thread_idle = 100034 .sq_thread_idle = 1000,
35 });35 });
36 return try IO_Uring.init_params(entries, &params);36 return try IO_Uring.init_params(entries, &params);
37 }37 }
...@@ -69,7 +69,7 @@ pub const IO_Uring = struct {...@@ -69,7 +69,7 @@ pub const IO_Uring = struct {
69 // or a container seccomp policy prohibits io_uring syscalls:69 // or a container seccomp policy prohibits io_uring syscalls:
70 linux.EPERM => return error.PermissionDenied,70 linux.EPERM => return error.PermissionDenied,
71 linux.ENOSYS => return error.SystemOutdated,71 linux.ENOSYS => return error.SystemOutdated,
72 else => |errno| return os.unexpectedErrno(errno)72 else => |errno| return os.unexpectedErrno(errno),
73 }73 }
74 const fd = @intCast(os.fd_t, res);74 const fd = @intCast(os.fd_t, res);
75 assert(fd >= 0);75 assert(fd >= 0);
...@@ -117,12 +117,12 @@ pub const IO_Uring = struct {...@@ -117,12 +117,12 @@ pub const IO_Uring = struct {
117 assert(cq.overflow.* == 0);117 assert(cq.overflow.* == 0);
118 assert(cq.cqes.len == p.cq_entries);118 assert(cq.cqes.len == p.cq_entries);
119119
120 return IO_Uring {120 return IO_Uring{
121 .fd = fd,121 .fd = fd,
122 .sq = sq,122 .sq = sq,
123 .cq = cq,123 .cq = cq,
124 .flags = p.flags,124 .flags = p.flags,
125 .features = p.features125 .features = p.features,
126 };126 };
127 }127 }
128128
...@@ -207,7 +207,7 @@ pub const IO_Uring = struct {...@@ -207,7 +207,7 @@ pub const IO_Uring = struct {
207 // The operation was interrupted by a delivery of a signal before it could complete.207 // The operation was interrupted by a delivery of a signal before it could complete.
208 // This can happen while waiting for events with IORING_ENTER_GETEVENTS:208 // This can happen while waiting for events with IORING_ENTER_GETEVENTS:
209 linux.EINTR => return error.SignalInterrupt,209 linux.EINTR => return error.SignalInterrupt,
210 else => |errno| return os.unexpectedErrno(errno)210 else => |errno| return os.unexpectedErrno(errno),
211 }211 }
212 return @intCast(u32, res);212 return @intCast(u32, res);
213 }213 }
...@@ -369,7 +369,7 @@ pub const IO_Uring = struct {...@@ -369,7 +369,7 @@ pub const IO_Uring = struct {
369 user_data: u64,369 user_data: u64,
370 fd: os.fd_t,370 fd: os.fd_t,
371 buffer: []u8,371 buffer: []u8,
372 offset: u64372 offset: u64,
373 ) !*io_uring_sqe {373 ) !*io_uring_sqe {
374 const sqe = try self.get_sqe();374 const sqe = try self.get_sqe();
375 io_uring_prep_read(sqe, fd, buffer, offset);375 io_uring_prep_read(sqe, fd, buffer, offset);
...@@ -384,7 +384,7 @@ pub const IO_Uring = struct {...@@ -384,7 +384,7 @@ pub const IO_Uring = struct {
384 user_data: u64,384 user_data: u64,
385 fd: os.fd_t,385 fd: os.fd_t,
386 buffer: []const u8,386 buffer: []const u8,
387 offset: u64387 offset: u64,
388 ) !*io_uring_sqe {388 ) !*io_uring_sqe {
389 const sqe = try self.get_sqe();389 const sqe = try self.get_sqe();
390 io_uring_prep_write(sqe, fd, buffer, offset);390 io_uring_prep_write(sqe, fd, buffer, offset);
...@@ -401,7 +401,7 @@ pub const IO_Uring = struct {...@@ -401,7 +401,7 @@ pub const IO_Uring = struct {
401 user_data: u64,401 user_data: u64,
402 fd: os.fd_t,402 fd: os.fd_t,
403 iovecs: []const os.iovec,403 iovecs: []const os.iovec,
404 offset: u64404 offset: u64,
405 ) !*io_uring_sqe {405 ) !*io_uring_sqe {
406 const sqe = try self.get_sqe();406 const sqe = try self.get_sqe();
407 io_uring_prep_readv(sqe, fd, iovecs, offset);407 io_uring_prep_readv(sqe, fd, iovecs, offset);
...@@ -418,7 +418,7 @@ pub const IO_Uring = struct {...@@ -418,7 +418,7 @@ pub const IO_Uring = struct {
418 user_data: u64,418 user_data: u64,
419 fd: os.fd_t,419 fd: os.fd_t,
420 iovecs: []const os.iovec_const,420 iovecs: []const os.iovec_const,
421 offset: u64421 offset: u64,
422 ) !*io_uring_sqe {422 ) !*io_uring_sqe {
423 const sqe = try self.get_sqe();423 const sqe = try self.get_sqe();
424 io_uring_prep_writev(sqe, fd, iovecs, offset);424 io_uring_prep_writev(sqe, fd, iovecs, offset);
...@@ -434,7 +434,7 @@ pub const IO_Uring = struct {...@@ -434,7 +434,7 @@ pub const IO_Uring = struct {
434 fd: os.fd_t,434 fd: os.fd_t,
435 addr: *os.sockaddr,435 addr: *os.sockaddr,
436 addrlen: *os.socklen_t,436 addrlen: *os.socklen_t,
437 flags: u32437 flags: u32,
438 ) !*io_uring_sqe {438 ) !*io_uring_sqe {
439 const sqe = try self.get_sqe();439 const sqe = try self.get_sqe();
440 io_uring_prep_accept(sqe, fd, addr, addrlen, flags);440 io_uring_prep_accept(sqe, fd, addr, addrlen, flags);
...@@ -449,7 +449,7 @@ pub const IO_Uring = struct {...@@ -449,7 +449,7 @@ pub const IO_Uring = struct {
449 user_data: u64,449 user_data: u64,
450 fd: os.fd_t,450 fd: os.fd_t,
451 addr: *const os.sockaddr,451 addr: *const os.sockaddr,
452 addrlen: os.socklen_t452 addrlen: os.socklen_t,
453 ) !*io_uring_sqe {453 ) !*io_uring_sqe {
454 const sqe = try self.get_sqe();454 const sqe = try self.get_sqe();
455 io_uring_prep_connect(sqe, fd, addr, addrlen);455 io_uring_prep_connect(sqe, fd, addr, addrlen);
...@@ -464,7 +464,7 @@ pub const IO_Uring = struct {...@@ -464,7 +464,7 @@ pub const IO_Uring = struct {
464 user_data: u64,464 user_data: u64,
465 fd: os.fd_t,465 fd: os.fd_t,
466 buffer: []u8,466 buffer: []u8,
467 flags: u32467 flags: u32,
468 ) !*io_uring_sqe {468 ) !*io_uring_sqe {
469 const sqe = try self.get_sqe();469 const sqe = try self.get_sqe();
470 io_uring_prep_recv(sqe, fd, buffer, flags);470 io_uring_prep_recv(sqe, fd, buffer, flags);
...@@ -479,7 +479,7 @@ pub const IO_Uring = struct {...@@ -479,7 +479,7 @@ pub const IO_Uring = struct {
479 user_data: u64,479 user_data: u64,
480 fd: os.fd_t,480 fd: os.fd_t,
481 buffer: []const u8,481 buffer: []const u8,
482 flags: u32482 flags: u32,
483 ) !*io_uring_sqe {483 ) !*io_uring_sqe {
484 const sqe = try self.get_sqe();484 const sqe = try self.get_sqe();
485 io_uring_prep_send(sqe, fd, buffer, flags);485 io_uring_prep_send(sqe, fd, buffer, flags);
...@@ -495,7 +495,7 @@ pub const IO_Uring = struct {...@@ -495,7 +495,7 @@ pub const IO_Uring = struct {
495 fd: os.fd_t,495 fd: os.fd_t,
496 path: [*:0]const u8,496 path: [*:0]const u8,
497 flags: u32,497 flags: u32,
498 mode: os.mode_t498 mode: os.mode_t,
499 ) !*io_uring_sqe {499 ) !*io_uring_sqe {
500 const sqe = try self.get_sqe();500 const sqe = try self.get_sqe();
501 io_uring_prep_openat(sqe, fd, path, flags, mode);501 io_uring_prep_openat(sqe, fd, path, flags, mode);
...@@ -529,7 +529,7 @@ pub const IO_Uring = struct {...@@ -529,7 +529,7 @@ pub const IO_Uring = struct {
529 self.fd,529 self.fd,
530 .REGISTER_FILES,530 .REGISTER_FILES,
531 @ptrCast(*const c_void, fds.ptr),531 @ptrCast(*const c_void, fds.ptr),
532 @intCast(u32, fds.len)532 @intCast(u32, fds.len),
533 );533 );
534 switch (linux.getErrno(res)) {534 switch (linux.getErrno(res)) {
535 0 => {},535 0 => {},
...@@ -548,7 +548,7 @@ pub const IO_Uring = struct {...@@ -548,7 +548,7 @@ pub const IO_Uring = struct {
548 linux.ENOMEM => return error.SystemResources,548 linux.ENOMEM => return error.SystemResources,
549 // Attempt to register files on a ring already registering files or being torn down:549 // Attempt to register files on a ring already registering files or being torn down:
550 linux.ENXIO => return error.RingShuttingDownOrAlreadyRegisteringFiles,550 linux.ENXIO => return error.RingShuttingDownOrAlreadyRegisteringFiles,
551 else => |errno| return os.unexpectedErrno(errno)551 else => |errno| return os.unexpectedErrno(errno),
552 }552 }
553 }553 }
554554
...@@ -559,7 +559,7 @@ pub const IO_Uring = struct {...@@ -559,7 +559,7 @@ pub const IO_Uring = struct {
559 switch (linux.getErrno(res)) {559 switch (linux.getErrno(res)) {
560 0 => {},560 0 => {},
561 linux.ENXIO => return error.FilesNotRegistered,561 linux.ENXIO => return error.FilesNotRegistered,
562 else => |errno| return os.unexpectedErrno(errno)562 else => |errno| return os.unexpectedErrno(errno),
563 }563 }
564 }564 }
565};565};
...@@ -581,13 +581,13 @@ pub const SubmissionQueue = struct {...@@ -581,13 +581,13 @@ pub const SubmissionQueue = struct {
581 // This allows us to amortize the cost of the @atomicStore to `tail` across multiple SQEs.581 // This allows us to amortize the cost of the @atomicStore to `tail` across multiple SQEs.
582 sqe_head: u32 = 0,582 sqe_head: u32 = 0,
583 sqe_tail: u32 = 0,583 sqe_tail: u32 = 0,
584 584
585 pub fn init(fd: os.fd_t, p: io_uring_params) !SubmissionQueue {585 pub fn init(fd: os.fd_t, p: io_uring_params) !SubmissionQueue {
586 assert(fd >= 0);586 assert(fd >= 0);
587 assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0);587 assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0);
588 const size = std.math.max(588 const size = std.math.max(
589 p.sq_off.array + p.sq_entries * @sizeOf(u32),589 p.sq_off.array + p.sq_entries * @sizeOf(u32),
590 p.cq_off.cqes + p.cq_entries * @sizeOf(io_uring_cqe)590 p.cq_off.cqes + p.cq_entries * @sizeOf(io_uring_cqe),
591 );591 );
592 const mmap = try os.mmap(592 const mmap = try os.mmap(
593 null,593 null,
...@@ -620,9 +620,9 @@ pub const SubmissionQueue = struct {...@@ -620,9 +620,9 @@ pub const SubmissionQueue = struct {
620 // see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L7843-L7844.620 // see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L7843-L7844.
621 assert(621 assert(
622 p.sq_entries ==622 p.sq_entries ==
623 @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_entries])).*623 @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_entries])).*,
624 );624 );
625 return SubmissionQueue {625 return SubmissionQueue{
626 .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.head])),626 .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.head])),
627 .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.tail])),627 .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.tail])),
628 .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_mask])).*,628 .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_mask])).*,
...@@ -631,7 +631,7 @@ pub const SubmissionQueue = struct {...@@ -631,7 +631,7 @@ pub const SubmissionQueue = struct {
631 .array = array[0..p.sq_entries],631 .array = array[0..p.sq_entries],
632 .sqes = sqes[0..p.sq_entries],632 .sqes = sqes[0..p.sq_entries],
633 .mmap = mmap,633 .mmap = mmap,
634 .mmap_sqes = mmap_sqes634 .mmap_sqes = mmap_sqes,
635 };635 };
636 }636 }
637637
...@@ -654,18 +654,16 @@ pub const CompletionQueue = struct {...@@ -654,18 +654,16 @@ pub const CompletionQueue = struct {
654 const mmap = sq.mmap;654 const mmap = sq.mmap;
655 const cqes = @ptrCast(655 const cqes = @ptrCast(
656 [*]io_uring_cqe,656 [*]io_uring_cqe,
657 @alignCast(@alignOf(io_uring_cqe), &mmap[p.cq_off.cqes])657 @alignCast(@alignOf(io_uring_cqe), &mmap[p.cq_off.cqes]),
658 );658 );
659 assert(659 assert(p.cq_entries ==
660 p.cq_entries ==660 @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_entries])).*);
661 @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_entries])).*661 return CompletionQueue{
662 );
663 return CompletionQueue {
664 .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.head])),662 .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.head])),
665 .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.tail])),663 .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.tail])),
666 .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_mask])).*,664 .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_mask])).*,
667 .overflow = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.overflow])),665 .overflow = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.overflow])),
668 .cqes = cqes[0..p.cq_entries]666 .cqes = cqes[0..p.cq_entries],
669 };667 };
670 }668 }
671669
...@@ -689,7 +687,7 @@ pub fn io_uring_prep_nop(sqe: *io_uring_sqe) void {...@@ -689,7 +687,7 @@ pub fn io_uring_prep_nop(sqe: *io_uring_sqe) void {
689 .buf_index = 0,687 .buf_index = 0,
690 .personality = 0,688 .personality = 0,
691 .splice_fd_in = 0,689 .splice_fd_in = 0,
692 .__pad2 = [2]u64{ 0, 0 }690 .__pad2 = [2]u64{ 0, 0 },
693 };691 };
694}692}
695693
...@@ -707,7 +705,7 @@ pub fn io_uring_prep_fsync(sqe: *io_uring_sqe, fd: os.fd_t, flags: u32) void {...@@ -707,7 +705,7 @@ pub fn io_uring_prep_fsync(sqe: *io_uring_sqe, fd: os.fd_t, flags: u32) void {
707 .buf_index = 0,705 .buf_index = 0,
708 .personality = 0,706 .personality = 0,
709 .splice_fd_in = 0,707 .splice_fd_in = 0,
710 .__pad2 = [2]u64{ 0, 0 }708 .__pad2 = [2]u64{ 0, 0 },
711 };709 };
712}710}
713711
...@@ -717,7 +715,7 @@ pub fn io_uring_prep_rw(...@@ -717,7 +715,7 @@ pub fn io_uring_prep_rw(
717 fd: os.fd_t,715 fd: os.fd_t,
718 addr: anytype,716 addr: anytype,
719 len: usize,717 len: usize,
720 offset: u64718 offset: u64,
721) void {719) void {
722 sqe.* = .{720 sqe.* = .{
723 .opcode = op,721 .opcode = op,
...@@ -732,7 +730,7 @@ pub fn io_uring_prep_rw(...@@ -732,7 +730,7 @@ pub fn io_uring_prep_rw(
732 .buf_index = 0,730 .buf_index = 0,
733 .personality = 0,731 .personality = 0,
734 .splice_fd_in = 0,732 .splice_fd_in = 0,
735 .__pad2 = [2]u64{ 0, 0 }733 .__pad2 = [2]u64{ 0, 0 },
736 };734 };
737}735}
738736
...@@ -748,7 +746,7 @@ pub fn io_uring_prep_readv(...@@ -748,7 +746,7 @@ pub fn io_uring_prep_readv(
748 sqe: *io_uring_sqe,746 sqe: *io_uring_sqe,
749 fd: os.fd_t,747 fd: os.fd_t,
750 iovecs: []const os.iovec,748 iovecs: []const os.iovec,
751 offset: u64749 offset: u64,
752) void {750) void {
753 io_uring_prep_rw(.READV, sqe, fd, iovecs.ptr, iovecs.len, offset);751 io_uring_prep_rw(.READV, sqe, fd, iovecs.ptr, iovecs.len, offset);
754}752}
...@@ -757,7 +755,7 @@ pub fn io_uring_prep_writev(...@@ -757,7 +755,7 @@ pub fn io_uring_prep_writev(
757 sqe: *io_uring_sqe,755 sqe: *io_uring_sqe,
758 fd: os.fd_t,756 fd: os.fd_t,
759 iovecs: []const os.iovec_const,757 iovecs: []const os.iovec_const,
760 offset: u64758 offset: u64,
761) void {759) void {
762 io_uring_prep_rw(.WRITEV, sqe, fd, iovecs.ptr, iovecs.len, offset);760 io_uring_prep_rw(.WRITEV, sqe, fd, iovecs.ptr, iovecs.len, offset);
763}761}
...@@ -767,7 +765,7 @@ pub fn io_uring_prep_accept(...@@ -767,7 +765,7 @@ pub fn io_uring_prep_accept(
767 fd: os.fd_t,765 fd: os.fd_t,
768 addr: *os.sockaddr,766 addr: *os.sockaddr,
769 addrlen: *os.socklen_t,767 addrlen: *os.socklen_t,
770 flags: u32768 flags: u32,
771) void {769) void {
772 // `addr` holds a pointer to `sockaddr`, and `addr2` holds a pointer to socklen_t`.770 // `addr` holds a pointer to `sockaddr`, and `addr2` holds a pointer to socklen_t`.
773 // `addr2` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32).771 // `addr2` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32).
...@@ -779,7 +777,7 @@ pub fn io_uring_prep_connect(...@@ -779,7 +777,7 @@ pub fn io_uring_prep_connect(
779 sqe: *io_uring_sqe,777 sqe: *io_uring_sqe,
780 fd: os.fd_t,778 fd: os.fd_t,
781 addr: *const os.sockaddr,779 addr: *const os.sockaddr,
782 addrlen: os.socklen_t780 addrlen: os.socklen_t,
783) void {781) void {
784 // `addrlen` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32).782 // `addrlen` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32).
785 io_uring_prep_rw(.CONNECT, sqe, fd, addr, 0, addrlen);783 io_uring_prep_rw(.CONNECT, sqe, fd, addr, 0, addrlen);
...@@ -800,7 +798,7 @@ pub fn io_uring_prep_openat(...@@ -800,7 +798,7 @@ pub fn io_uring_prep_openat(
800 fd: os.fd_t,798 fd: os.fd_t,
801 path: [*:0]const u8,799 path: [*:0]const u8,
802 flags: u32,800 flags: u32,
803 mode: os.mode_t801 mode: os.mode_t,
804) void {802) void {
805 io_uring_prep_rw(.OPENAT, sqe, fd, path, mode, 0);803 io_uring_prep_rw(.OPENAT, sqe, fd, path, mode, 0);
806 sqe.rw_flags = flags;804 sqe.rw_flags = flags;
...@@ -820,7 +818,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void {...@@ -820,7 +818,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void {
820 .buf_index = 0,818 .buf_index = 0,
821 .personality = 0,819 .personality = 0,
822 .splice_fd_in = 0,820 .splice_fd_in = 0,
823 .__pad2 = [2]u64{ 0, 0 }821 .__pad2 = [2]u64{ 0, 0 },
824 };822 };
825}823}
826824
...@@ -845,7 +843,7 @@ test "nop" {...@@ -845,7 +843,7 @@ test "nop" {
845 var ring = IO_Uring.init(1, 0) catch |err| switch (err) {843 var ring = IO_Uring.init(1, 0) catch |err| switch (err) {
846 error.SystemOutdated => return error.SkipZigTest,844 error.SystemOutdated => return error.SkipZigTest,
847 error.PermissionDenied => return error.SkipZigTest,845 error.PermissionDenied => return error.SkipZigTest,
848 else => return err846 else => return err,
849 };847 };
850 defer {848 defer {
851 ring.deinit();849 ring.deinit();
...@@ -853,7 +851,7 @@ test "nop" {...@@ -853,7 +851,7 @@ test "nop" {
853 }851 }
854852
855 const sqe = try ring.nop(0xaaaaaaaa);853 const sqe = try ring.nop(0xaaaaaaaa);
856 testing.expectEqual(io_uring_sqe {854 testing.expectEqual(io_uring_sqe{
857 .opcode = .NOP,855 .opcode = .NOP,
858 .flags = 0,856 .flags = 0,
859 .ioprio = 0,857 .ioprio = 0,
...@@ -866,7 +864,7 @@ test "nop" {...@@ -866,7 +864,7 @@ test "nop" {
866 .buf_index = 0,864 .buf_index = 0,
867 .personality = 0,865 .personality = 0,
868 .splice_fd_in = 0,866 .splice_fd_in = 0,
869 .__pad2 = [2]u64{ 0, 0 }867 .__pad2 = [2]u64{ 0, 0 },
870 }, sqe.*);868 }, sqe.*);
871869
872 testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);870 testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
...@@ -883,10 +881,10 @@ test "nop" {...@@ -883,10 +881,10 @@ test "nop" {
883 testing.expectEqual(@as(u32, 0), ring.cq.head.*);881 testing.expectEqual(@as(u32, 0), ring.cq.head.*);
884 testing.expectEqual(@as(u32, 0), ring.sq_ready());882 testing.expectEqual(@as(u32, 0), ring.sq_ready());
885883
886 testing.expectEqual(io_uring_cqe {884 testing.expectEqual(io_uring_cqe{
887 .user_data = 0xaaaaaaaa,885 .user_data = 0xaaaaaaaa,
888 .res = 0,886 .res = 0,
889 .flags = 0887 .flags = 0,
890 }, try ring.copy_cqe());888 }, try ring.copy_cqe());
891 testing.expectEqual(@as(u32, 1), ring.cq.head.*);889 testing.expectEqual(@as(u32, 1), ring.cq.head.*);
892 testing.expectEqual(@as(u32, 0), ring.cq_ready());890 testing.expectEqual(@as(u32, 0), ring.cq_ready());
...@@ -894,10 +892,10 @@ test "nop" {...@@ -894,10 +892,10 @@ test "nop" {
894 const sqe_barrier = try ring.nop(0xbbbbbbbb);892 const sqe_barrier = try ring.nop(0xbbbbbbbb);
895 sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;893 sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;
896 testing.expectEqual(@as(u32, 1), try ring.submit());894 testing.expectEqual(@as(u32, 1), try ring.submit());
897 testing.expectEqual(io_uring_cqe {895 testing.expectEqual(io_uring_cqe{
898 .user_data = 0xbbbbbbbb,896 .user_data = 0xbbbbbbbb,
899 .res = 0,897 .res = 0,
900 .flags = 0898 .flags = 0,
901 }, try ring.copy_cqe());899 }, try ring.copy_cqe());
902 testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);900 testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
903 testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);901 testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
...@@ -911,7 +909,7 @@ test "readv" {...@@ -911,7 +909,7 @@ test "readv" {
911 var ring = IO_Uring.init(1, 0) catch |err| switch (err) {909 var ring = IO_Uring.init(1, 0) catch |err| switch (err) {
912 error.SystemOutdated => return error.SkipZigTest,910 error.SystemOutdated => return error.SkipZigTest,
913 error.PermissionDenied => return error.SkipZigTest,911 error.PermissionDenied => return error.SkipZigTest,
914 else => return err912 else => return err,
915 };913 };
916 defer ring.deinit();914 defer ring.deinit();
917915
...@@ -930,14 +928,14 @@ test "readv" {...@@ -930,14 +928,14 @@ test "readv" {
930 try ring.register_files(registered_fds[0..]);928 try ring.register_files(registered_fds[0..]);
931929
932 var buffer = [_]u8{42} ** 128;930 var buffer = [_]u8{42} ** 128;
933 var iovecs = [_]os.iovec{ os.iovec { .iov_base = &buffer, .iov_len = buffer.len } };931 var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};
934 const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0);932 const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0);
935 testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);933 testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
936 sqe.flags |= linux.IOSQE_FIXED_FILE;934 sqe.flags |= linux.IOSQE_FIXED_FILE;
937935
938 testing.expectError(error.SubmissionQueueFull, ring.nop(0));936 testing.expectError(error.SubmissionQueueFull, ring.nop(0));
939 testing.expectEqual(@as(u32, 1), try ring.submit());937 testing.expectEqual(@as(u32, 1), try ring.submit());
940 testing.expectEqual(linux.io_uring_cqe {938 testing.expectEqual(linux.io_uring_cqe{
941 .user_data = 0xcccccccc,939 .user_data = 0xcccccccc,
942 .res = buffer.len,940 .res = buffer.len,
943 .flags = 0,941 .flags = 0,
...@@ -953,10 +951,10 @@ test "writev/fsync/readv" {...@@ -953,10 +951,10 @@ test "writev/fsync/readv" {
953 var ring = IO_Uring.init(4, 0) catch |err| switch (err) {951 var ring = IO_Uring.init(4, 0) catch |err| switch (err) {
954 error.SystemOutdated => return error.SkipZigTest,952 error.SystemOutdated => return error.SkipZigTest,
955 error.PermissionDenied => return error.SkipZigTest,953 error.PermissionDenied => return error.SkipZigTest,
956 else => return err954 else => return err,
957 };955 };
958 defer ring.deinit();956 defer ring.deinit();
959 957
960 const path = "test_io_uring_writev_fsync_readv";958 const path = "test_io_uring_writev_fsync_readv";
961 const file = try std.fs.cwd().createFile(path, .{ .read = true, .truncate = true });959 const file = try std.fs.cwd().createFile(path, .{ .read = true, .truncate = true });
962 defer file.close();960 defer file.close();
...@@ -964,19 +962,19 @@ test "writev/fsync/readv" {...@@ -964,19 +962,19 @@ test "writev/fsync/readv" {
964 const fd = file.handle;962 const fd = file.handle;
965963
966 const buffer_write = [_]u8{42} ** 128;964 const buffer_write = [_]u8{42} ** 128;
967 const iovecs_write = [_]os.iovec_const {965 const iovecs_write = [_]os.iovec_const{
968 os.iovec_const { .iov_base = &buffer_write, .iov_len = buffer_write.len }966 os.iovec_const{ .iov_base = &buffer_write, .iov_len = buffer_write.len },
969 };967 };
970 var buffer_read = [_]u8{0} ** 128;968 var buffer_read = [_]u8{0} ** 128;
971 var iovecs_read = [_]os.iovec {969 var iovecs_read = [_]os.iovec{
972 os.iovec { .iov_base = &buffer_read, .iov_len = buffer_read.len }970 os.iovec{ .iov_base = &buffer_read, .iov_len = buffer_read.len },
973 };971 };
974972
975 const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);973 const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);
976 testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);974 testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
977 testing.expectEqual(@as(u64, 17), sqe_writev.off);975 testing.expectEqual(@as(u64, 17), sqe_writev.off);
978 sqe_writev.flags |= linux.IOSQE_IO_LINK;976 sqe_writev.flags |= linux.IOSQE_IO_LINK;
979 977
980 const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);978 const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);
981 testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);979 testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
982 testing.expectEqual(fd, sqe_fsync.fd);980 testing.expectEqual(fd, sqe_fsync.fd);
...@@ -991,21 +989,21 @@ test "writev/fsync/readv" {...@@ -991,21 +989,21 @@ test "writev/fsync/readv" {
991 testing.expectEqual(@as(u32, 0), ring.sq_ready());989 testing.expectEqual(@as(u32, 0), ring.sq_ready());
992 testing.expectEqual(@as(u32, 3), ring.cq_ready());990 testing.expectEqual(@as(u32, 3), ring.cq_ready());
993991
994 testing.expectEqual(linux.io_uring_cqe {992 testing.expectEqual(linux.io_uring_cqe{
995 .user_data = 0xdddddddd,993 .user_data = 0xdddddddd,
996 .res = buffer_write.len,994 .res = buffer_write.len,
997 .flags = 0,995 .flags = 0,
998 }, try ring.copy_cqe());996 }, try ring.copy_cqe());
999 testing.expectEqual(@as(u32, 2), ring.cq_ready());997 testing.expectEqual(@as(u32, 2), ring.cq_ready());
1000 998
1001 testing.expectEqual(linux.io_uring_cqe {999 testing.expectEqual(linux.io_uring_cqe{
1002 .user_data = 0xeeeeeeee,1000 .user_data = 0xeeeeeeee,
1003 .res = 0,1001 .res = 0,
1004 .flags = 0,1002 .flags = 0,
1005 }, try ring.copy_cqe());1003 }, try ring.copy_cqe());
1006 testing.expectEqual(@as(u32, 1), ring.cq_ready());1004 testing.expectEqual(@as(u32, 1), ring.cq_ready());
10071005
1008 testing.expectEqual(linux.io_uring_cqe {1006 testing.expectEqual(linux.io_uring_cqe{
1009 .user_data = 0xffffffff,1007 .user_data = 0xffffffff,
1010 .res = buffer_read.len,1008 .res = buffer_read.len,
1011 .flags = 0,1009 .flags = 0,
...@@ -1021,10 +1019,10 @@ test "write/read" {...@@ -1021,10 +1019,10 @@ test "write/read" {
1021 var ring = IO_Uring.init(2, 0) catch |err| switch (err) {1019 var ring = IO_Uring.init(2, 0) catch |err| switch (err) {
1022 error.SystemOutdated => return error.SkipZigTest,1020 error.SystemOutdated => return error.SkipZigTest,
1023 error.PermissionDenied => return error.SkipZigTest,1021 error.PermissionDenied => return error.SkipZigTest,
1024 else => return err1022 else => return err,
1025 };1023 };
1026 defer ring.deinit();1024 defer ring.deinit();
1027 1025
1028 const path = "test_io_uring_write_read";1026 const path = "test_io_uring_write_read";
1029 const file = try std.fs.cwd().createFile(path, .{ .read = true, .truncate = true });1027 const file = try std.fs.cwd().createFile(path, .{ .read = true, .truncate = true });
1030 defer file.close();1028 defer file.close();
...@@ -1048,12 +1046,12 @@ test "write/read" {...@@ -1048,12 +1046,12 @@ test "write/read" {
1048 // https://lwn.net/Articles/809820/1046 // https://lwn.net/Articles/809820/
1049 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;1047 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
1050 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;1048 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
1051 testing.expectEqual(linux.io_uring_cqe {1049 testing.expectEqual(linux.io_uring_cqe{
1052 .user_data = 0x11111111,1050 .user_data = 0x11111111,
1053 .res = buffer_write.len,1051 .res = buffer_write.len,
1054 .flags = 0,1052 .flags = 0,
1055 }, cqe_write);1053 }, cqe_write);
1056 testing.expectEqual(linux.io_uring_cqe {1054 testing.expectEqual(linux.io_uring_cqe{
1057 .user_data = 0x22222222,1055 .user_data = 0x22222222,
1058 .res = buffer_read.len,1056 .res = buffer_read.len,
1059 .flags = 0,1057 .flags = 0,
...@@ -1067,7 +1065,7 @@ test "openat" {...@@ -1067,7 +1065,7 @@ test "openat" {
1067 var ring = IO_Uring.init(1, 0) catch |err| switch (err) {1065 var ring = IO_Uring.init(1, 0) catch |err| switch (err) {
1068 error.SystemOutdated => return error.SkipZigTest,1066 error.SystemOutdated => return error.SkipZigTest,
1069 error.PermissionDenied => return error.SkipZigTest,1067 error.PermissionDenied => return error.SkipZigTest,
1070 else => return err1068 else => return err,
1071 };1069 };
1072 defer ring.deinit();1070 defer ring.deinit();
10731071
...@@ -1077,7 +1075,7 @@ test "openat" {...@@ -1077,7 +1075,7 @@ test "openat" {
1077 const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;1075 const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;
1078 const mode: os.mode_t = 0o666;1076 const mode: os.mode_t = 0o666;
1079 const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode);1077 const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode);
1080 testing.expectEqual(io_uring_sqe {1078 testing.expectEqual(io_uring_sqe{
1081 .opcode = .OPENAT,1079 .opcode = .OPENAT,
1082 .flags = 0,1080 .flags = 0,
1083 .ioprio = 0,1081 .ioprio = 0,
...@@ -1090,7 +1088,7 @@ test "openat" {...@@ -1090,7 +1088,7 @@ test "openat" {
1090 .buf_index = 0,1088 .buf_index = 0,
1091 .personality = 0,1089 .personality = 0,
1092 .splice_fd_in = 0,1090 .splice_fd_in = 0,
1093 .__pad2 = [2]u64{ 0, 0 }1091 .__pad2 = [2]u64{ 0, 0 },
1094 }, sqe_openat.*);1092 }, sqe_openat.*);
1095 testing.expectEqual(@as(u32, 1), try ring.submit());1093 testing.expectEqual(@as(u32, 1), try ring.submit());
10961094
...@@ -1103,7 +1101,7 @@ test "openat" {...@@ -1103,7 +1101,7 @@ test "openat" {
1103 if (cqe_openat.res == -linux.EBADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) {1101 if (cqe_openat.res == -linux.EBADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) {
1104 return error.SkipZigTest;1102 return error.SkipZigTest;
1105 }1103 }
1106 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{ cqe_openat.res });1104 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
1107 testing.expect(cqe_openat.res > 0);1105 testing.expect(cqe_openat.res > 0);
1108 testing.expectEqual(@as(u32, 0), cqe_openat.flags);1106 testing.expectEqual(@as(u32, 0), cqe_openat.flags);
11091107
...@@ -1112,14 +1110,14 @@ test "openat" {...@@ -1112,14 +1110,14 @@ test "openat" {
11121110
1113test "close" {1111test "close" {
1114 if (builtin.os.tag != .linux) return error.SkipZigTest;1112 if (builtin.os.tag != .linux) return error.SkipZigTest;
1115 1113
1116 var ring = IO_Uring.init(1, 0) catch |err| switch (err) {1114 var ring = IO_Uring.init(1, 0) catch |err| switch (err) {
1117 error.SystemOutdated => return error.SkipZigTest,1115 error.SystemOutdated => return error.SkipZigTest,
1118 error.PermissionDenied => return error.SkipZigTest,1116 error.PermissionDenied => return error.SkipZigTest,
1119 else => return err1117 else => return err,
1120 };1118 };
1121 defer ring.deinit();1119 defer ring.deinit();
1122 1120
1123 const path = "test_io_uring_close";1121 const path = "test_io_uring_close";
1124 const file = try std.fs.cwd().createFile(path, .{});1122 const file = try std.fs.cwd().createFile(path, .{});
1125 errdefer file.close();1123 errdefer file.close();
...@@ -1132,7 +1130,7 @@ test "close" {...@@ -1132,7 +1130,7 @@ test "close" {
11321130
1133 const cqe_close = try ring.copy_cqe();1131 const cqe_close = try ring.copy_cqe();
1134 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;1132 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;
1135 testing.expectEqual(linux.io_uring_cqe {1133 testing.expectEqual(linux.io_uring_cqe{
1136 .user_data = 0x44444444,1134 .user_data = 0x44444444,
1137 .res = 0,1135 .res = 0,
1138 .flags = 0,1136 .flags = 0,
...@@ -1145,7 +1143,7 @@ test "accept/connect/send/recv" {...@@ -1145,7 +1143,7 @@ test "accept/connect/send/recv" {
1145 var ring = IO_Uring.init(16, 0) catch |err| switch (err) {1143 var ring = IO_Uring.init(16, 0) catch |err| switch (err) {
1146 error.SystemOutdated => return error.SkipZigTest,1144 error.SystemOutdated => return error.SkipZigTest,
1147 error.PermissionDenied => return error.SkipZigTest,1145 error.PermissionDenied => return error.SkipZigTest,
1148 else => return err1146 else => return err,
1149 };1147 };
1150 defer ring.deinit();1148 defer ring.deinit();
11511149
...@@ -1157,8 +1155,8 @@ test "accept/connect/send/recv" {...@@ -1157,8 +1155,8 @@ test "accept/connect/send/recv" {
1157 try os.bind(server, &address.any, address.getOsSockLen());1155 try os.bind(server, &address.any, address.getOsSockLen());
1158 try os.listen(server, kernel_backlog);1156 try os.listen(server, kernel_backlog);
11591157
1160 const buffer_send = [_]u8{ 1,0,1,0,1,0,1,0,1,0 };1158 const buffer_send = [_]u8{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 };
1161 var buffer_recv = [_]u8{ 0,1,0,1,0 };1159 var buffer_recv = [_]u8{ 0, 1, 0, 1, 0 };
11621160
1163 var accept_addr: os.sockaddr = undefined;1161 var accept_addr: os.sockaddr = undefined;
1164 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));1162 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));
...@@ -1184,10 +1182,10 @@ test "accept/connect/send/recv" {...@@ -1184,10 +1182,10 @@ test "accept/connect/send/recv" {
1184 }1182 }
11851183
1186 testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);1184 testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
1187 if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{ cqe_accept.res });1185 if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});
1188 testing.expect(cqe_accept.res > 0);1186 testing.expect(cqe_accept.res > 0);
1189 testing.expectEqual(@as(u32, 0), cqe_accept.flags);1187 testing.expectEqual(@as(u32, 0), cqe_accept.flags);
1190 testing.expectEqual(linux.io_uring_cqe {1188 testing.expectEqual(linux.io_uring_cqe{
1191 .user_data = 0xcccccccc,1189 .user_data = 0xcccccccc,
1192 .res = 0,1190 .res = 0,
1193 .flags = 0,1191 .flags = 0,
...@@ -1200,7 +1198,7 @@ test "accept/connect/send/recv" {...@@ -1200,7 +1198,7 @@ test "accept/connect/send/recv" {
12001198
1201 const cqe_send = try ring.copy_cqe();1199 const cqe_send = try ring.copy_cqe();
1202 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;1200 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;
1203 testing.expectEqual(linux.io_uring_cqe {1201 testing.expectEqual(linux.io_uring_cqe{
1204 .user_data = 0xeeeeeeee,1202 .user_data = 0xeeeeeeee,
1205 .res = buffer_send.len,1203 .res = buffer_send.len,
1206 .flags = 0,1204 .flags = 0,
...@@ -1208,7 +1206,7 @@ test "accept/connect/send/recv" {...@@ -1208,7 +1206,7 @@ test "accept/connect/send/recv" {
12081206
1209 const cqe_recv = try ring.copy_cqe();1207 const cqe_recv = try ring.copy_cqe();
1210 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;1208 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;
1211 testing.expectEqual(linux.io_uring_cqe {1209 testing.expectEqual(linux.io_uring_cqe{
1212 .user_data = 0xffffffff,1210 .user_data = 0xffffffff,
1213 .res = buffer_recv.len,1211 .res = buffer_recv.len,
1214 .flags = 0,1212 .flags = 0,
lib/std/os/linux/test.zig+1-1
...@@ -24,7 +24,7 @@ test "fallocate" {...@@ -24,7 +24,7 @@ test "fallocate" {
24 0 => {},24 0 => {},
25 linux.ENOSYS => return error.SkipZigTest,25 linux.ENOSYS => return error.SkipZigTest,
26 linux.EOPNOTSUPP => return error.SkipZigTest,26 linux.EOPNOTSUPP => return error.SkipZigTest,
27 else => |errno| std.debug.panic("unhandled errno: {}", .{ errno }),27 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
28 }28 }
2929
30 expect((try file.stat()).size == len);30 expect((try file.stat()).size == len);
lib/std/os/windows.zig+2-2
...@@ -570,13 +570,13 @@ pub fn SetCurrentDirectory(path_name: []const u16) SetCurrentDirectoryError!void...@@ -570,13 +570,13 @@ pub fn SetCurrentDirectory(path_name: []const u16) SetCurrentDirectoryError!void
570 const path_len_bytes = math.cast(u16, path_name.len * 2) catch |err| switch (err) {570 const path_len_bytes = math.cast(u16, path_name.len * 2) catch |err| switch (err) {
571 error.Overflow => return error.NameTooLong,571 error.Overflow => return error.NameTooLong,
572 };572 };
573 573
574 var nt_name = UNICODE_STRING{574 var nt_name = UNICODE_STRING{
575 .Length = path_len_bytes,575 .Length = path_len_bytes,
576 .MaximumLength = path_len_bytes,576 .MaximumLength = path_len_bytes,
577 .Buffer = @intToPtr([*]u16, @ptrToInt(path_name.ptr)),577 .Buffer = @intToPtr([*]u16, @ptrToInt(path_name.ptr)),
578 };578 };
579 579
580 const rc = ntdll.RtlSetCurrentDirectory_U(&nt_name);580 const rc = ntdll.RtlSetCurrentDirectory_U(&nt_name);
581 switch (rc) {581 switch (rc) {
582 .SUCCESS => {},582 .SUCCESS => {},
lib/std/os/windows/ntdll.zig+1-3
...@@ -112,6 +112,4 @@ pub extern "NtDll" fn NtWaitForKeyedEvent(...@@ -112,6 +112,4 @@ pub extern "NtDll" fn NtWaitForKeyedEvent(
112 Timeout: ?*LARGE_INTEGER,112 Timeout: ?*LARGE_INTEGER,
113) callconv(WINAPI) NTSTATUS;113) callconv(WINAPI) NTSTATUS;
114114
115pub extern "NtDll" fn RtlSetCurrentDirectory_U(115pub extern "NtDll" fn RtlSetCurrentDirectory_U(PathName: *UNICODE_STRING) callconv(WINAPI) NTSTATUS;
116 PathName: *UNICODE_STRING
117) callconv(WINAPI) NTSTATUS;
lib/std/priority_queue.zig+1-2
...@@ -468,7 +468,6 @@ test "std.PriorityQueue: update min heap" {...@@ -468,7 +468,6 @@ test "std.PriorityQueue: update min heap" {
468 expectEqual(@as(u32, 5), queue.remove());468 expectEqual(@as(u32, 5), queue.remove());
469}469}
470470
471
472test "std.PriorityQueue: update same min heap" {471test "std.PriorityQueue: update same min heap" {
473 var queue = PQ.init(testing.allocator, lessThan);472 var queue = PQ.init(testing.allocator, lessThan);
474 defer queue.deinit();473 defer queue.deinit();
...@@ -514,4 +513,4 @@ test "std.PriorityQueue: update same max heap" {...@@ -514,4 +513,4 @@ test "std.PriorityQueue: update same max heap" {
514 expectEqual(@as(u32, 4), queue.remove());513 expectEqual(@as(u32, 4), queue.remove());
515 expectEqual(@as(u32, 2), queue.remove());514 expectEqual(@as(u32, 2), queue.remove());
516 expectEqual(@as(u32, 1), queue.remove());515 expectEqual(@as(u32, 1), queue.remove());
517}
\ No newline at end of file
516}
lib/std/zig/parser_test.zig+47-1
...@@ -274,6 +274,51 @@ test "recovery: missing block after for/while loops" {...@@ -274,6 +274,51 @@ test "recovery: missing block after for/while loops" {
274 });274 });
275}275}
276276
277test "zig fmt: respect line breaks after var declarations" {
278 try testCanonical(
279 \\const crc =
280 \\ lookup_tables[0][p[7]] ^
281 \\ lookup_tables[1][p[6]] ^
282 \\ lookup_tables[2][p[5]] ^
283 \\ lookup_tables[3][p[4]] ^
284 \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
285 \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
286 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
287 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];
288 \\
289 );
290}
291
292test "zig fmt: multiline string mixed with comments" {
293 try testCanonical(
294 \\const s1 =
295 \\ //\\one
296 \\ \\two)
297 \\ \\three
298 \\;
299 \\const s2 =
300 \\ \\one
301 \\ \\two)
302 \\ //\\three
303 \\;
304 \\const s3 =
305 \\ \\one
306 \\ //\\two)
307 \\ \\three
308 \\;
309 \\const s4 =
310 \\ \\one
311 \\ //\\two
312 \\ \\three
313 \\ //\\four
314 \\ \\five
315 \\;
316 \\const a =
317 \\ 1;
318 \\
319 );
320}
321
277test "zig fmt: empty file" {322test "zig fmt: empty file" {
278 try testCanonical(323 try testCanonical(
279 \\324 \\
...@@ -3224,7 +3269,8 @@ test "zig fmt: integer literals with underscore separators" {...@@ -3224,7 +3269,8 @@ test "zig fmt: integer literals with underscore separators" {
3224 \\ 1_234_5673269 \\ 1_234_567
3225 \\ +(0b0_1-0o7_0+0xff_FF ) + 0_0;3270 \\ +(0b0_1-0o7_0+0xff_FF ) + 0_0;
3226 ,3271 ,
3227 \\const x = 1_234_567 + (0b0_1 - 0o7_0 + 0xff_FF) + 0_0;3272 \\const x =
3273 \\ 1_234_567 + (0b0_1 - 0o7_0 + 0xff_FF) + 0_0;
3228 \\3274 \\
3229 );3275 );
3230}3276}
lib/std/zig/render.zig+25-19
...@@ -2209,10 +2209,10 @@ fn renderAsmOutput(...@@ -2209,10 +2209,10 @@ fn renderAsmOutput(
2209 try ais.writer().writeAll(" (");2209 try ais.writer().writeAll(" (");
22102210
2211 switch (asm_output.kind) {2211 switch (asm_output.kind) {
2212 ast.Node.Asm.Output.Kind.Variable => |variable_name| {2212 .Variable => |variable_name| {
2213 try renderExpression(allocator, ais, tree, &variable_name.base, Space.None);2213 try renderExpression(allocator, ais, tree, &variable_name.base, Space.None);
2214 },2214 },
2215 ast.Node.Asm.Output.Kind.Return => |return_type| {2215 .Return => |return_type| {
2216 try ais.writer().writeAll("-> ");2216 try ais.writer().writeAll("-> ");
2217 try renderExpression(allocator, ais, tree, return_type, Space.None);2217 try renderExpression(allocator, ais, tree, return_type, Space.None);
2218 },2218 },
...@@ -2304,8 +2304,17 @@ fn renderVarDecl(...@@ -2304,8 +2304,17 @@ fn renderVarDecl(
2304 }2304 }
23052305
2306 if (var_decl.getInitNode()) |init_node| {2306 if (var_decl.getInitNode()) |init_node| {
2307 const s = if (init_node.tag == .MultilineStringLiteral) Space.None else Space.Space;2307 const eq_token = var_decl.getEqToken().?;
2308 try renderToken(tree, ais, var_decl.getEqToken().?, s); // =2308 const eq_space = blk: {
2309 const loc = tree.tokenLocation(tree.token_locs[eq_token].end, tree.nextToken(eq_token));
2310 break :blk if (loc.line == 0) Space.Space else Space.Newline;
2311 };
2312
2313 {
2314 ais.pushIndent();
2315 defer ais.popIndent();
2316 try renderToken(tree, ais, eq_token, eq_space); // =
2317 }
2309 ais.pushIndentOneShot();2318 ais.pushIndentOneShot();
2310 try renderExpression(allocator, ais, tree, init_node, Space.None);2319 try renderExpression(allocator, ais, tree, init_node, Space.None);
2311 }2320 }
...@@ -2470,20 +2479,20 @@ fn renderTokenOffset(...@@ -2470,20 +2479,20 @@ fn renderTokenOffset(
24702479
2471 var loc = tree.tokenLocationLoc(token_loc.end, next_token_loc);2480 var loc = tree.tokenLocationLoc(token_loc.end, next_token_loc);
2472 if (loc.line == 0) {2481 if (loc.line == 0) {
2473 try ais.writer().print(" {}", .{mem.trimRight(u8, tree.tokenSliceLoc(next_token_loc), " ")});2482 if (tree.token_ids[token_index] != .MultilineStringLiteralLine) {
2483 try ais.writer().writeByte(' ');
2484 }
2485 try ais.writer().writeAll(mem.trimRight(u8, tree.tokenSliceLoc(next_token_loc), " "));
2474 offset = 2;2486 offset = 2;
2475 token_loc = next_token_loc;2487 token_loc = next_token_loc;
2476 next_token_loc = tree.token_locs[token_index + offset];2488 next_token_loc = tree.token_locs[token_index + offset];
2477 next_token_id = tree.token_ids[token_index + offset];2489 next_token_id = tree.token_ids[token_index + offset];
2478 if (next_token_id != .LineComment) {2490 if (next_token_id != .LineComment) {
2479 switch (space) {2491 switch (space) {
2480 Space.None, Space.Space => {2492 .None, .Space, .SpaceOrOutdent => {
2481 try ais.insertNewline();
2482 },
2483 Space.SpaceOrOutdent => {
2484 try ais.insertNewline();2493 try ais.insertNewline();
2485 },2494 },
2486 Space.Newline => {2495 .Newline => {
2487 if (next_token_id == .MultilineStringLiteralLine) {2496 if (next_token_id == .MultilineStringLiteralLine) {
2488 return;2497 return;
2489 } else {2498 } else {
...@@ -2491,8 +2500,8 @@ fn renderTokenOffset(...@@ -2491,8 +2500,8 @@ fn renderTokenOffset(
2491 return;2500 return;
2492 }2501 }
2493 },2502 },
2494 Space.NoNewline => {},2503 .NoNewline => {},
2495 Space.NoComment, Space.Comma, Space.BlockStart => unreachable,2504 .NoComment, .Comma, .BlockStart => unreachable,
2496 }2505 }
2497 return;2506 return;
2498 }2507 }
...@@ -2513,7 +2522,7 @@ fn renderTokenOffset(...@@ -2513,7 +2522,7 @@ fn renderTokenOffset(
2513 next_token_id = tree.token_ids[token_index + offset];2522 next_token_id = tree.token_ids[token_index + offset];
2514 if (next_token_id != .LineComment) {2523 if (next_token_id != .LineComment) {
2515 switch (space) {2524 switch (space) {
2516 Space.Newline => {2525 .Newline => {
2517 if (next_token_id == .MultilineStringLiteralLine) {2526 if (next_token_id == .MultilineStringLiteralLine) {
2518 return;2527 return;
2519 } else {2528 } else {
...@@ -2521,14 +2530,11 @@ fn renderTokenOffset(...@@ -2521,14 +2530,11 @@ fn renderTokenOffset(
2521 return;2530 return;
2522 }2531 }
2523 },2532 },
2524 Space.None, Space.Space => {2533 .None, .Space, .SpaceOrOutdent => {
2525 try ais.insertNewline();
2526 },
2527 Space.SpaceOrOutdent => {
2528 try ais.insertNewline();2534 try ais.insertNewline();
2529 },2535 },
2530 Space.NoNewline => {},2536 .NoNewline => {},
2531 Space.NoComment, Space.Comma, Space.BlockStart => unreachable,2537 .NoComment, .Comma, .BlockStart => unreachable,
2532 }2538 }
2533 return;2539 return;
2534 }2540 }
lib/std/zig/system.zig+2-2
...@@ -212,7 +212,7 @@ pub const NativeTargetInfo = struct {...@@ -212,7 +212,7 @@ pub const NativeTargetInfo = struct {
212 const uts = std.os.uname();212 const uts = std.os.uname();
213 const release = mem.spanZ(&uts.release);213 const release = mem.spanZ(&uts.release);
214 // The release field sometimes has a weird format,214 // The release field sometimes has a weird format,
215 // `Version.parse` will attempt to find some meaningful interpretation. 215 // `Version.parse` will attempt to find some meaningful interpretation.
216 if (std.builtin.Version.parse(release)) |ver| {216 if (std.builtin.Version.parse(release)) |ver| {
217 os.version_range.linux.range.min = ver;217 os.version_range.linux.range.min = ver;
218 os.version_range.linux.range.max = ver;218 os.version_range.linux.range.max = ver;
...@@ -237,7 +237,7 @@ pub const NativeTargetInfo = struct {...@@ -237,7 +237,7 @@ pub const NativeTargetInfo = struct {
237 // `---` `` ``--> Sub-version (Starting from Windows 10 onwards)237 // `---` `` ``--> Sub-version (Starting from Windows 10 onwards)
238 // \ `--> Service pack (Always zero in the constants defined)238 // \ `--> Service pack (Always zero in the constants defined)
239 // `--> OS version (Major & minor)239 // `--> OS version (Major & minor)
240 const os_ver: u16 = //240 const os_ver: u16 =
241 @intCast(u16, version_info.dwMajorVersion & 0xff) << 8 |241 @intCast(u16, version_info.dwMajorVersion & 0xff) << 8 |
242 @intCast(u16, version_info.dwMinorVersion & 0xff);242 @intCast(u16, version_info.dwMinorVersion & 0xff);
243 const sp_ver: u8 = 0;243 const sp_ver: u8 = 0;
src/link.zig+2-2
...@@ -572,11 +572,11 @@ pub const File = struct {...@@ -572,11 +572,11 @@ pub const File = struct {
572572
573 if (!base.options.disable_lld_caching) {573 if (!base.options.disable_lld_caching) {
574 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {574 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
575 std.log.warn("failed to save archive hash digest file: {}", .{@errorName(err)});575 log.warn("failed to save archive hash digest file: {}", .{@errorName(err)});
576 };576 };
577577
578 man.writeManifest() catch |err| {578 man.writeManifest() catch |err| {
579 std.log.warn("failed to write cache manifest when archiving: {}", .{@errorName(err)});579 log.warn("failed to write cache manifest when archiving: {}", .{@errorName(err)});
580 };580 };
581581
582 base.lock = man.toOwnedLock();582 base.lock = man.toOwnedLock();
src/link/Coff.zig+3-3
...@@ -1205,7 +1205,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {...@@ -1205,7 +1205,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
1205 }1205 }
12061206
1207 if (stderr.len != 0) {1207 if (stderr.len != 0) {
1208 std.log.warn("unexpected LLD stderr:\n{s}", .{stderr});1208 log.warn("unexpected LLD stderr:\n{s}", .{stderr});
1209 }1209 }
1210 }1210 }
1211 }1211 }
...@@ -1214,11 +1214,11 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {...@@ -1214,11 +1214,11 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
1214 // Update the file with the digest. If it fails we can continue; it only1214 // Update the file with the digest. If it fails we can continue; it only
1215 // means that the next invocation will have an unnecessary cache miss.1215 // means that the next invocation will have an unnecessary cache miss.
1216 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {1216 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
1217 std.log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});1217 log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});
1218 };1218 };
1219 // Again failure here only means an unnecessary cache miss.1219 // Again failure here only means an unnecessary cache miss.
1220 man.writeManifest() catch |err| {1220 man.writeManifest() catch |err| {
1221 std.log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});1221 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});
1222 };1222 };
1223 // We hang on to this lock so that the output file path can be used without1223 // We hang on to this lock so that the output file path can be used without
1224 // other processes clobbering it.1224 // other processes clobbering it.
src/link/Elf.zig+3-3
...@@ -1684,7 +1684,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1684,7 +1684,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1684 }1684 }
16851685
1686 if (stderr.len != 0) {1686 if (stderr.len != 0) {
1687 std.log.warn("unexpected LLD stderr:\n{s}", .{stderr});1687 log.warn("unexpected LLD stderr:\n{s}", .{stderr});
1688 }1688 }
1689 }1689 }
16901690
...@@ -1692,11 +1692,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1692,11 +1692,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1692 // Update the file with the digest. If it fails we can continue; it only1692 // Update the file with the digest. If it fails we can continue; it only
1693 // means that the next invocation will have an unnecessary cache miss.1693 // means that the next invocation will have an unnecessary cache miss.
1694 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {1694 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
1695 std.log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});1695 log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});
1696 };1696 };
1697 // Again failure here only means an unnecessary cache miss.1697 // Again failure here only means an unnecessary cache miss.
1698 man.writeManifest() catch |err| {1698 man.writeManifest() catch |err| {
1699 std.log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});1699 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});
1700 };1700 };
1701 // We hang on to this lock so that the output file path can be used without1701 // We hang on to this lock so that the output file path can be used without
1702 // other processes clobbering it.1702 // other processes clobbering it.
src/link/MachO.zig+10-10
...@@ -673,15 +673,15 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -673,15 +673,15 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
673 self.base.allocator.free(result.stderr);673 self.base.allocator.free(result.stderr);
674 }674 }
675 if (result.stdout.len != 0) {675 if (result.stdout.len != 0) {
676 std.log.warn("unexpected LD stdout: {}", .{result.stdout});676 log.warn("unexpected LD stdout: {}", .{result.stdout});
677 }677 }
678 if (result.stderr.len != 0) {678 if (result.stderr.len != 0) {
679 std.log.warn("unexpected LD stderr: {}", .{result.stderr});679 log.warn("unexpected LD stderr: {}", .{result.stderr});
680 }680 }
681 if (result.term != .Exited or result.term.Exited != 0) {681 if (result.term != .Exited or result.term.Exited != 0) {
682 // TODO parse this output and surface with the Compilation API rather than682 // TODO parse this output and surface with the Compilation API rather than
683 // directly outputting to stderr here.683 // directly outputting to stderr here.
684 std.log.err("{}", .{result.stderr});684 log.err("{}", .{result.stderr});
685 return error.LDReportedFailure;685 return error.LDReportedFailure;
686 }686 }
687 } else {687 } else {
...@@ -738,7 +738,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -738,7 +738,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
738 }738 }
739739
740 if (stderr.len != 0) {740 if (stderr.len != 0) {
741 std.log.warn("unexpected LLD stderr:\n{s}", .{stderr});741 log.warn("unexpected LLD stderr:\n{s}", .{stderr});
742 }742 }
743 }743 }
744744
...@@ -757,10 +757,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -757,10 +757,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
757 // TODO We are in the position to be able to increase the padding by moving all sections757 // TODO We are in the position to be able to increase the padding by moving all sections
758 // by the required offset, but this requires a little bit more thinking and bookkeeping.758 // by the required offset, but this requires a little bit more thinking and bookkeeping.
759 // For now, return an error informing the user of the problem.759 // For now, return an error informing the user of the problem.
760 std.log.err("Not enough padding between load commands and start of __text section:\n", .{});760 log.err("Not enough padding between load commands and start of __text section:\n", .{});
761 std.log.err("Offset after last load command: 0x{x}\n", .{after_last_cmd_offset});761 log.err("Offset after last load command: 0x{x}\n", .{after_last_cmd_offset});
762 std.log.err("Beginning of __text section: 0x{x}\n", .{text_section.offset});762 log.err("Beginning of __text section: 0x{x}\n", .{text_section.offset});
763 std.log.err("Needed size: 0x{x}\n", .{needed_size});763 log.err("Needed size: 0x{x}\n", .{needed_size});
764 return error.NotEnoughPadding;764 return error.NotEnoughPadding;
765 }765 }
766 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;766 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
...@@ -792,11 +792,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -792,11 +792,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
792 // Update the file with the digest. If it fails we can continue; it only792 // Update the file with the digest. If it fails we can continue; it only
793 // means that the next invocation will have an unnecessary cache miss.793 // means that the next invocation will have an unnecessary cache miss.
794 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {794 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
795 std.log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});795 log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});
796 };796 };
797 // Again failure here only means an unnecessary cache miss.797 // Again failure here only means an unnecessary cache miss.
798 man.writeManifest() catch |err| {798 man.writeManifest() catch |err| {
799 std.log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});799 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});
800 };800 };
801 // We hang on to this lock so that the output file path can be used without801 // We hang on to this lock so that the output file path can be used without
802 // other processes clobbering it.802 // other processes clobbering it.
src/link/Wasm.zig+3-3
...@@ -455,7 +455,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -455,7 +455,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
455 }455 }
456456
457 if (stderr.len != 0) {457 if (stderr.len != 0) {
458 std.log.warn("unexpected LLD stderr:\n{s}", .{stderr});458 log.warn("unexpected LLD stderr:\n{s}", .{stderr});
459 }459 }
460 }460 }
461461
...@@ -463,11 +463,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -463,11 +463,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
463 // Update the file with the digest. If it fails we can continue; it only463 // Update the file with the digest. If it fails we can continue; it only
464 // means that the next invocation will have an unnecessary cache miss.464 // means that the next invocation will have an unnecessary cache miss.
465 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {465 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
466 std.log.warn("failed to save linking hash digest symlink: {}", .{@errorName(err)});466 log.warn("failed to save linking hash digest symlink: {}", .{@errorName(err)});
467 };467 };
468 // Again failure here only means an unnecessary cache miss.468 // Again failure here only means an unnecessary cache miss.
469 man.writeManifest() catch |err| {469 man.writeManifest() catch |err| {
470 std.log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});470 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});
471 };471 };
472 // We hang on to this lock so that the output file path can be used without472 // We hang on to this lock so that the output file path can be used without
473 // other processes clobbering it.473 // other processes clobbering it.
src/stage1/analyze.cpp+1-6
...@@ -3936,12 +3936,6 @@ void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {...@@ -3936,12 +3936,6 @@ void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {
39363936
3937void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {3937void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3938 switch (node->type) {3938 switch (node->type) {
3939 case NodeTypeContainerDecl:
3940 for (size_t i = 0; i < node->data.container_decl.decls.length; i += 1) {
3941 AstNode *child = node->data.container_decl.decls.at(i);
3942 scan_decls(g, decls_scope, child);
3943 }
3944 break;
3945 case NodeTypeFnDef:3939 case NodeTypeFnDef:
3946 scan_decls(g, decls_scope, node->data.fn_def.fn_proto);3940 scan_decls(g, decls_scope, node->data.fn_def.fn_proto);
3947 break;3941 break;
...@@ -3986,6 +3980,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3986,6 +3980,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3986 case NodeTypeCompTime:3980 case NodeTypeCompTime:
3987 preview_comptime_decl(g, node, decls_scope);3981 preview_comptime_decl(g, node, decls_scope);
3988 break;3982 break;
3983 case NodeTypeContainerDecl:
3989 case NodeTypeNoSuspend:3984 case NodeTypeNoSuspend:
3990 case NodeTypeParamDecl:3985 case NodeTypeParamDecl:
3991 case NodeTypeReturnExpr:3986 case NodeTypeReturnExpr:
src/stage1/ir.cpp-18
...@@ -25310,24 +25310,6 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -25310,24 +25310,6 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
25310 }25310 }
2531125311
25312 inner_fields[2]->data.x_union.payload = fn_decl_val;25312 inner_fields[2]->data.x_union.payload = fn_decl_val;
25313 break;
25314 }
25315 case TldIdContainer:
25316 {
25317 ZigType *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
25318 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))
25319 return ErrorSemanticAnalyzeFail;
25320
25321 // This is a type.
25322 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
25323
25324 ZigValue *payload = ira->codegen->pass1_arena->create<ZigValue>();
25325 payload->special = ConstValSpecialStatic;
25326 payload->type = ira->codegen->builtin_types.entry_type;
25327 payload->data.x_type = type_entry;
25328
25329 inner_fields[2]->data.x_union.payload = payload;
25330
25331 break;25313 break;
25332 }25314 }
25333 default:25315 default:
test/stage1/behavior/vector.zig+4-4
...@@ -550,8 +550,8 @@ test "vector reduce operation" {...@@ -550,8 +550,8 @@ test "vector reduce operation" {
550 // LLVM 11 ERROR: Cannot select type550 // LLVM 11 ERROR: Cannot select type
551 // https://github.com/ziglang/zig/issues/7138551 // https://github.com/ziglang/zig/issues/7138
552 if (std.builtin.arch != .aarch64) {552 if (std.builtin.arch != .aarch64) {
553 doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386));553 doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386));
554 doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9));554 doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9));
555 }555 }
556556
557 doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386));557 doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386));
...@@ -568,8 +568,8 @@ test "vector reduce operation" {...@@ -568,8 +568,8 @@ test "vector reduce operation" {
568 // LLVM 11 ERROR: Cannot select type568 // LLVM 11 ERROR: Cannot select type
569 // https://github.com/ziglang/zig/issues/7138569 // https://github.com/ziglang/zig/issues/7138
570 if (std.builtin.arch != .aarch64) {570 if (std.builtin.arch != .aarch64) {
571 doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567));571 doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567));
572 doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999));572 doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999));
573 }573 }
574574
575 doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567));575 doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567));