Commit af00afed98

Tadeo Kondrak <me@tadeo.ca>
2020-05-05 13:14:22
zig fmt
1 parent b957dc2
Changed files (9)
lib
test
stage1
standalone
lib/std/event/batch.zig
@@ -75,7 +75,7 @@ pub fn Batch(
             const job = &self.jobs[self.next_job_index];
             self.next_job_index = (self.next_job_index + 1) % max_jobs;
             if (job.frame) |existing| {
-                job.result = if (async_ok) await existing else noasync await existing;
+                job.result = if (async_ok) await existing else nosuspend await existing;
                 if (CollectedResult != void) {
                     job.result catch |err| {
                         self.collected_result = err;
@@ -94,7 +94,7 @@ pub fn Batch(
         /// a time, however, it need not be the same thread.
         pub fn wait(self: *Self) CollectedResult {
             for (self.jobs) |*job| if (job.frame) |f| {
-                job.result = if (async_ok) await f else noasync await f;
+                job.result = if (async_ok) await f else nosuspend await f;
                 if (CollectedResult != void) {
                     job.result catch |err| {
                         self.collected_result = err;
lib/std/event/loop.zig
@@ -195,7 +195,7 @@ pub const Loop = struct {
     const wakeup_bytes = [_]u8{0x1} ** 8;
 
     fn initOsData(self: *Loop, extra_thread_count: usize) InitOsDataError!void {
-        noasync switch (builtin.os.tag) {
+        nosuspend switch (builtin.os.tag) {
             .linux => {
                 errdefer {
                     while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd);
@@ -371,7 +371,7 @@ pub const Loop = struct {
     }
 
     fn deinitOsData(self: *Loop) void {
-        noasync switch (builtin.os.tag) {
+        nosuspend switch (builtin.os.tag) {
             .linux => {
                 os.close(self.os_data.final_eventfd);
                 while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd);
@@ -663,7 +663,7 @@ pub const Loop = struct {
     }
 
     pub fn finishOneEvent(self: *Loop) void {
-        noasync {
+        nosuspend {
             const prev = @atomicRmw(usize, &self.pending_event_count, .Sub, 1, .SeqCst);
             if (prev != 1) return;
 
@@ -1041,7 +1041,7 @@ pub const Loop = struct {
     }
 
     fn posixFsRun(self: *Loop) void {
-        noasync while (true) {
+        nosuspend while (true) {
             self.fs_thread_wakeup.reset();
             while (self.fs_queue.get()) |node| {
                 switch (node.data.msg) {
lib/std/zig/system/macos.zig
@@ -39,7 +39,7 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
             zend += 1;
         }
         if (zend == yindex + 1) return error.InvalidVersion;
-        const z = std.fmt.parseUnsigned(u16, build[yindex + 1..zend], 10) catch return error.InvalidVersion;
+        const z = std.fmt.parseUnsigned(u16, build[yindex + 1 .. zend], 10) catch return error.InvalidVersion;
 
         result.patch = switch (result.minor) {
             // TODO: compiler complains without explicit @as() coercion
@@ -97,7 +97,9 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
             4 => @as(u32, switch (y) { // Tiger: 10.4
                 'A' => 0,
                 'B' => 1,
-                'C', 'E', => 2,
+                'C',
+                'E',
+                => 2,
                 'F' => 3,
                 'G' => @as(u32, block: {
                     if (z >= 1454) break :block 5;
@@ -105,7 +107,10 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
                 }),
                 'H' => 5,
                 'I' => 6,
-                'J', 'K', 'N', => 7,
+                'J',
+                'K',
+                'N',
+                => 7,
                 'L' => 8,
                 'P' => 9,
                 'R' => 10,
@@ -438,7 +443,7 @@ test "version_from_build" {
     for (known) |pair| {
         var buf: [32]u8 = undefined;
         const ver = try version_from_build(pair[0]);
-        const sver = try std.fmt.bufPrint(buf[0..], "{}.{}.{}", .{ver.major, ver.minor, ver.patch});
+        const sver = try std.fmt.bufPrint(buf[0..], "{}.{}.{}", .{ ver.major, ver.minor, ver.patch });
         std.testing.expect(std.mem.eql(u8, sver, pair[1]));
     }
 }
lib/std/debug.zig
@@ -62,7 +62,7 @@ pub fn warn(comptime fmt: []const u8, args: var) void {
     const held = stderr_mutex.acquire();
     defer held.release();
     const stderr = getStderrStream();
-    noasync stderr.print(fmt, args) catch return;
+    nosuspend stderr.print(fmt, args) catch return;
 }
 
 pub fn getStderrStream() *File.OutStream {
@@ -112,7 +112,7 @@ pub fn detectTTYConfig() TTY.Config {
 /// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
 /// TODO multithreaded awareness
 pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
-    noasync {
+    nosuspend {
         const stderr = getStderrStream();
         if (builtin.strip_debug_info) {
             stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
@@ -133,7 +133,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
 /// unbuffered, and ignores any error returned.
 /// TODO multithreaded awareness
 pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
-    noasync {
+    nosuspend {
         const stderr = getStderrStream();
         if (builtin.strip_debug_info) {
             stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
@@ -203,7 +203,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
 /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
 /// TODO multithreaded awareness
 pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
-    noasync {
+    nosuspend {
         const stderr = getStderrStream();
         if (builtin.strip_debug_info) {
             stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
@@ -261,7 +261,7 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
         resetSegfaultHandler();
     }
 
-    noasync switch (panic_stage) {
+    nosuspend switch (panic_stage) {
         0 => {
             panic_stage = 1;
 
@@ -447,7 +447,7 @@ pub const TTY = struct {
         windows_api,
 
         fn setColor(conf: Config, out_stream: var, color: Color) void {
-            noasync switch (conf) {
+            nosuspend switch (conf) {
                 .no_color => return,
                 .escape_codes => switch (color) {
                     .Red => out_stream.writeAll(RED) catch return,
@@ -604,7 +604,7 @@ fn printLineInfo(
     tty_config: TTY.Config,
     comptime printLineFromFile: var,
 ) !void {
-    noasync {
+    nosuspend {
         tty_config.setColor(out_stream, .White);
 
         if (line_info) |*li| {
@@ -651,7 +651,7 @@ pub const OpenSelfDebugInfoError = error{
 
 /// TODO resources https://github.com/ziglang/zig/issues/4353
 pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
-    noasync {
+    nosuspend {
         if (builtin.strip_debug_info)
             return error.MissingDebugInfo;
         if (@hasDecl(root, "os") and @hasDecl(root.os, "debug") and @hasDecl(root.os.debug, "openSelfDebugInfo")) {
@@ -672,7 +672,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
 
 /// TODO resources https://github.com/ziglang/zig/issues/4353
 fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !ModuleDebugInfo {
-    noasync {
+    nosuspend {
         const coff_file = try std.fs.openFileAbsoluteW(coff_file_path, .{ .intended_io_mode = .blocking });
         errdefer coff_file.close();
 
@@ -853,7 +853,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 {
 
 /// TODO resources https://github.com/ziglang/zig/issues/4353
 pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !ModuleDebugInfo {
-    noasync {
+    nosuspend {
         const mapped_mem = try mapWholeFile(elf_file_path);
         const hdr = @ptrCast(*const elf.Ehdr, &mapped_mem[0]);
         if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic;
@@ -1056,7 +1056,7 @@ const MachoSymbol = struct {
 };
 
 fn mapWholeFile(path: []const u8) ![]align(mem.page_size) const u8 {
-    noasync {
+    nosuspend {
         const file = try fs.cwd().openFile(path, .{ .intended_io_mode = .blocking });
         defer file.close();
 
@@ -1418,7 +1418,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
         }
 
         fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo {
-            noasync {
+            nosuspend {
                 // Translate the VA into an address into this object
                 const relocated_address = address - self.base_address;
                 assert(relocated_address >= 0x100000000);
@@ -1643,14 +1643,14 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
             // Translate the VA into an address into this object
             const relocated_address = address - self.base_address;
 
-            if (noasync self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
+            if (nosuspend self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
                 return SymbolInfo{
-                    .symbol_name = noasync self.dwarf.getSymbolName(relocated_address) orelse "???",
+                    .symbol_name = nosuspend self.dwarf.getSymbolName(relocated_address) orelse "???",
                     .compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) {
                         error.MissingDebugInfo, error.InvalidDebugInfo => "???",
                         else => return err,
                     },
-                    .line_info = noasync self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
+                    .line_info = nosuspend self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
                         error.MissingDebugInfo, error.InvalidDebugInfo => null,
                         else => return err,
                     },
lib/std/dwarf.zig
@@ -252,13 +252,13 @@ fn readUnitLength(in_stream: var, endian: builtin.Endian, is_64: *bool) !u64 {
 fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8 {
     const buf = try allocator.alloc(u8, size);
     errdefer allocator.free(buf);
-    if ((try noasync in_stream.read(buf)) < size) return error.EndOfFile;
+    if ((try nosuspend in_stream.read(buf)) < size) return error.EndOfFile;
     return buf;
 }
 
 // TODO the noasyncs here are workarounds
 fn readAddress(in_stream: var, endian: builtin.Endian, is_64: bool) !u64 {
-    return noasync if (is_64)
+    return nosuspend if (is_64)
         try in_stream.readInt(u64, endian)
     else
         @as(u64, try in_stream.readInt(u32, endian));
@@ -271,7 +271,7 @@ fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: var, size: usize
 
 // TODO the noasyncs here are workarounds
 fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, endian: builtin.Endian, size: usize) !FormValue {
-    const block_len = try noasync in_stream.readVarInt(usize, endian, size);
+    const block_len = try nosuspend in_stream.readVarInt(usize, endian, size);
     return parseFormValueBlockLen(allocator, in_stream, block_len);
 }
 
@@ -282,16 +282,16 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
         .Const = Constant{
             .signed = signed,
             .payload = switch (size) {
-                1 => try noasync in_stream.readInt(u8, endian),
-                2 => try noasync in_stream.readInt(u16, endian),
-                4 => try noasync in_stream.readInt(u32, endian),
-                8 => try noasync in_stream.readInt(u64, endian),
+                1 => try nosuspend in_stream.readInt(u8, endian),
+                2 => try nosuspend in_stream.readInt(u16, endian),
+                4 => try nosuspend in_stream.readInt(u32, endian),
+                8 => try nosuspend in_stream.readInt(u64, endian),
                 -1 => blk: {
                     if (signed) {
-                        const x = try noasync leb.readILEB128(i64, in_stream);
+                        const x = try nosuspend leb.readILEB128(i64, in_stream);
                         break :blk @bitCast(u64, x);
                     } else {
-                        const x = try noasync leb.readULEB128(u64, in_stream);
+                        const x = try nosuspend leb.readULEB128(u64, in_stream);
                         break :blk x;
                     }
                 },
@@ -305,11 +305,11 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
 fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, endian: builtin.Endian, size: i32) !FormValue {
     return FormValue{
         .Ref = switch (size) {
-            1 => try noasync in_stream.readInt(u8, endian),
-            2 => try noasync in_stream.readInt(u16, endian),
-            4 => try noasync in_stream.readInt(u32, endian),
-            8 => try noasync in_stream.readInt(u64, endian),
-            -1 => try noasync leb.readULEB128(u64, in_stream),
+            1 => try nosuspend in_stream.readInt(u8, endian),
+            2 => try nosuspend in_stream.readInt(u16, endian),
+            4 => try nosuspend in_stream.readInt(u32, endian),
+            8 => try nosuspend in_stream.readInt(u64, endian),
+            -1 => try nosuspend leb.readULEB128(u64, in_stream),
             else => unreachable,
         },
     };
@@ -323,7 +323,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endia
         FORM_block2 => parseFormValueBlock(allocator, in_stream, endian, 2),
         FORM_block4 => parseFormValueBlock(allocator, in_stream, endian, 4),
         FORM_block => x: {
-            const block_len = try noasync leb.readULEB128(usize, in_stream);
+            const block_len = try nosuspend leb.readULEB128(usize, in_stream);
             return parseFormValueBlockLen(allocator, in_stream, block_len);
         },
         FORM_data1 => parseFormValueConstant(allocator, in_stream, false, endian, 1),
@@ -335,11 +335,11 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endia
             return parseFormValueConstant(allocator, in_stream, signed, endian, -1);
         },
         FORM_exprloc => {
-            const size = try noasync leb.readULEB128(usize, in_stream);
+            const size = try nosuspend leb.readULEB128(usize, in_stream);
             const buf = try readAllocBytes(allocator, in_stream, size);
             return FormValue{ .ExprLoc = buf };
         },
-        FORM_flag => FormValue{ .Flag = (try noasync in_stream.readByte()) != 0 },
+        FORM_flag => FormValue{ .Flag = (try nosuspend in_stream.readByte()) != 0 },
         FORM_flag_present => FormValue{ .Flag = true },
         FORM_sec_offset => FormValue{ .SecOffset = try readAddress(in_stream, endian, is_64) },
 
@@ -350,12 +350,12 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endia
         FORM_ref_udata => parseFormValueRef(allocator, in_stream, endian, -1),
 
         FORM_ref_addr => FormValue{ .RefAddr = try readAddress(in_stream, endian, is_64) },
-        FORM_ref_sig8 => FormValue{ .Ref = try noasync in_stream.readInt(u64, endian) },
+        FORM_ref_sig8 => FormValue{ .Ref = try nosuspend in_stream.readInt(u64, endian) },
 
         FORM_string => FormValue{ .String = try in_stream.readUntilDelimiterAlloc(allocator, 0, math.maxInt(usize)) },
         FORM_strp => FormValue{ .StrPtr = try readAddress(in_stream, endian, is_64) },
         FORM_indirect => {
-            const child_form_id = try noasync leb.readULEB128(u64, in_stream);
+            const child_form_id = try nosuspend leb.readULEB128(u64, in_stream);
             const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64));
             var frame = try allocator.create(F);
             defer allocator.destroy(frame);
test/stage1/behavior/async_fn.zig
@@ -1093,7 +1093,7 @@ test "recursive call of await @asyncCall with struct return type" {
 test "noasync function call" {
     const S = struct {
         fn doTheTest() void {
-            const result = noasync add(50, 100);
+            const result = nosuspend add(50, 100);
             expect(result == 150);
         }
         fn add(a: i32, b: i32) i32 {
@@ -1517,7 +1517,7 @@ test "noasync await" {
 
         fn doTheTest() void {
             var frame = async foo(false);
-            expect(noasync await frame == 42);
+            expect(nosuspend await frame == 42);
             finished = true;
         }
 
@@ -1544,8 +1544,8 @@ test "noasync on function calls" {
             return S0{};
         }
     };
-    expectEqual(@as(i32, 42), noasync S1.c().b);
-    expectEqual(@as(i32, 42), (try noasync S1.d()).b);
+    expectEqual(@as(i32, 42), nosuspend S1.c().b);
+    expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
 }
 
 test "avoid forcing frame alignment resolution implicit cast to *c_void" {
@@ -1561,5 +1561,5 @@ test "avoid forcing frame alignment resolution implicit cast to *c_void" {
     };
     var frame = async S.foo();
     resume @ptrCast(anyframe->bool, @alignCast(@alignOf(@Frame(S.foo)), S.x));
-    expect(noasync await frame);
+    expect(nosuspend await frame);
 }
test/stage1/behavior/cast.zig
@@ -823,7 +823,7 @@ test "peer type resolve array pointer and unknown pointer" {
 
     comptime expect(@TypeOf(&array, const_ptr) == [*]const u8);
     comptime expect(@TypeOf(const_ptr, &array) == [*]const u8);
-    
+
     comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8);
     comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8);
 }
test/standalone/main_return_error/error_u8.zig
@@ -1,6 +1,4 @@
-const Err = error {
-    Foo
-};
+const Err = error{Foo};
 
 pub fn main() !u8 {
     return Err.Foo;
test/standalone/main_return_error/error_u8_non_zero.zig
@@ -1,6 +1,9 @@
-const Err = error { Foo };
+const Err = error{Foo};
 
-fn foo() u8 { var x = @intCast(u8, 9); return x; }
+fn foo() u8 {
+    var x = @intCast(u8, 9);
+    return x;
+}
 
 pub fn main() !u8 {
     if (foo() == 7) return Err.Foo;