authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-05-05 05:14:22-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-05-05 05:55:25-06:00
logaf00afed9844b9fb17478d33840fb4a312c4f07c
tree2199ced7be5a0234a18bdb57cac9309cd2f16cc0
parentb957dc29a4e3f025e446e717b0ae8c69602545ca
signaturelock-open Commit is signed but in an unrecognized format.

zig fmt


9 files changed, 61 insertions(+), 55 deletions(-)

lib/std/debug.zig+15-15
......@@ -62,7 +62,7 @@ pub fn warn(comptime fmt: []const u8, args: var) void {
6262 const held = stderr_mutex.acquire();
6363 defer held.release();
6464 const stderr = getStderrStream();
65 noasync stderr.print(fmt, args) catch return;
65 nosuspend stderr.print(fmt, args) catch return;
6666}
6767
6868pub fn getStderrStream() *File.OutStream {
......@@ -112,7 +112,7 @@ pub fn detectTTYConfig() TTY.Config {
112112/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
113113/// TODO multithreaded awareness
114114pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
115 noasync {
115 nosuspend {
116116 const stderr = getStderrStream();
117117 if (builtin.strip_debug_info) {
118118 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
......@@ -133,7 +133,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
133133/// unbuffered, and ignores any error returned.
134134/// TODO multithreaded awareness
135135pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
136 noasync {
136 nosuspend {
137137 const stderr = getStderrStream();
138138 if (builtin.strip_debug_info) {
139139 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
203203/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
204204/// TODO multithreaded awareness
205205pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
206 noasync {
206 nosuspend {
207207 const stderr = getStderrStream();
208208 if (builtin.strip_debug_info) {
209209 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
261261 resetSegfaultHandler();
262262 }
263263
264 noasync switch (panic_stage) {
264 nosuspend switch (panic_stage) {
265265 0 => {
266266 panic_stage = 1;
267267
......@@ -447,7 +447,7 @@ pub const TTY = struct {
447447 windows_api,
448448
449449 fn setColor(conf: Config, out_stream: var, color: Color) void {
450 noasync switch (conf) {
450 nosuspend switch (conf) {
451451 .no_color => return,
452452 .escape_codes => switch (color) {
453453 .Red => out_stream.writeAll(RED) catch return,
......@@ -604,7 +604,7 @@ fn printLineInfo(
604604 tty_config: TTY.Config,
605605 comptime printLineFromFile: var,
606606) !void {
607 noasync {
607 nosuspend {
608608 tty_config.setColor(out_stream, .White);
609609
610610 if (line_info) |*li| {
......@@ -651,7 +651,7 @@ pub const OpenSelfDebugInfoError = error{
651651
652652/// TODO resources https://github.com/ziglang/zig/issues/4353
653653pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
654 noasync {
654 nosuspend {
655655 if (builtin.strip_debug_info)
656656 return error.MissingDebugInfo;
657657 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 {
672672
673673/// TODO resources https://github.com/ziglang/zig/issues/4353
674674fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !ModuleDebugInfo {
675 noasync {
675 nosuspend {
676676 const coff_file = try std.fs.openFileAbsoluteW(coff_file_path, .{ .intended_io_mode = .blocking });
677677 errdefer coff_file.close();
678678
......@@ -853,7 +853,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 {
853853
854854/// TODO resources https://github.com/ziglang/zig/issues/4353
855855pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !ModuleDebugInfo {
856 noasync {
856 nosuspend {
857857 const mapped_mem = try mapWholeFile(elf_file_path);
858858 const hdr = @ptrCast(*const elf.Ehdr, &mapped_mem[0]);
859859 if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic;
......@@ -1056,7 +1056,7 @@ const MachoSymbol = struct {
10561056};
10571057
10581058fn mapWholeFile(path: []const u8) ![]align(mem.page_size) const u8 {
1059 noasync {
1059 nosuspend {
10601060 const file = try fs.cwd().openFile(path, .{ .intended_io_mode = .blocking });
10611061 defer file.close();
10621062
......@@ -1418,7 +1418,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
14181418 }
14191419
14201420 fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo {
1421 noasync {
1421 nosuspend {
14221422 // Translate the VA into an address into this object
14231423 const relocated_address = address - self.base_address;
14241424 assert(relocated_address >= 0x100000000);
......@@ -1643,14 +1643,14 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
16431643 // Translate the VA into an address into this object
16441644 const relocated_address = address - self.base_address;
16451645
1646 if (noasync self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
1646 if (nosuspend self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
16471647 return SymbolInfo{
1648 .symbol_name = noasync self.dwarf.getSymbolName(relocated_address) orelse "???",
1648 .symbol_name = nosuspend self.dwarf.getSymbolName(relocated_address) orelse "???",
16491649 .compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) {
16501650 error.MissingDebugInfo, error.InvalidDebugInfo => "???",
16511651 else => return err,
16521652 },
1653 .line_info = noasync self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
1653 .line_info = nosuspend self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
16541654 error.MissingDebugInfo, error.InvalidDebugInfo => null,
16551655 else => return err,
16561656 },
lib/std/dwarf.zig+19-19
......@@ -252,13 +252,13 @@ fn readUnitLength(in_stream: var, endian: builtin.Endian, is_64: *bool) !u64 {
252252fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8 {
253253 const buf = try allocator.alloc(u8, size);
254254 errdefer allocator.free(buf);
255 if ((try noasync in_stream.read(buf)) < size) return error.EndOfFile;
255 if ((try nosuspend in_stream.read(buf)) < size) return error.EndOfFile;
256256 return buf;
257257}
258258
259259// TODO the noasyncs here are workarounds
260260fn readAddress(in_stream: var, endian: builtin.Endian, is_64: bool) !u64 {
261 return noasync if (is_64)
261 return nosuspend if (is_64)
262262 try in_stream.readInt(u64, endian)
263263 else
264264 @as(u64, try in_stream.readInt(u32, endian));
......@@ -271,7 +271,7 @@ fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: var, size: usize
271271
272272// TODO the noasyncs here are workarounds
273273fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, endian: builtin.Endian, size: usize) !FormValue {
274 const block_len = try noasync in_stream.readVarInt(usize, endian, size);
274 const block_len = try nosuspend in_stream.readVarInt(usize, endian, size);
275275 return parseFormValueBlockLen(allocator, in_stream, block_len);
276276}
277277
......@@ -282,16 +282,16 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
282282 .Const = Constant{
283283 .signed = signed,
284284 .payload = switch (size) {
285 1 => try noasync in_stream.readInt(u8, endian),
286 2 => try noasync in_stream.readInt(u16, endian),
287 4 => try noasync in_stream.readInt(u32, endian),
288 8 => try noasync in_stream.readInt(u64, endian),
285 1 => try nosuspend in_stream.readInt(u8, endian),
286 2 => try nosuspend in_stream.readInt(u16, endian),
287 4 => try nosuspend in_stream.readInt(u32, endian),
288 8 => try nosuspend in_stream.readInt(u64, endian),
289289 -1 => blk: {
290290 if (signed) {
291 const x = try noasync leb.readILEB128(i64, in_stream);
291 const x = try nosuspend leb.readILEB128(i64, in_stream);
292292 break :blk @bitCast(u64, x);
293293 } else {
294 const x = try noasync leb.readULEB128(u64, in_stream);
294 const x = try nosuspend leb.readULEB128(u64, in_stream);
295295 break :blk x;
296296 }
297297 },
......@@ -305,11 +305,11 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
305305fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, endian: builtin.Endian, size: i32) !FormValue {
306306 return FormValue{
307307 .Ref = switch (size) {
308 1 => try noasync in_stream.readInt(u8, endian),
309 2 => try noasync in_stream.readInt(u16, endian),
310 4 => try noasync in_stream.readInt(u32, endian),
311 8 => try noasync in_stream.readInt(u64, endian),
312 -1 => try noasync leb.readULEB128(u64, in_stream),
308 1 => try nosuspend in_stream.readInt(u8, endian),
309 2 => try nosuspend in_stream.readInt(u16, endian),
310 4 => try nosuspend in_stream.readInt(u32, endian),
311 8 => try nosuspend in_stream.readInt(u64, endian),
312 -1 => try nosuspend leb.readULEB128(u64, in_stream),
313313 else => unreachable,
314314 },
315315 };
......@@ -323,7 +323,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endia
323323 FORM_block2 => parseFormValueBlock(allocator, in_stream, endian, 2),
324324 FORM_block4 => parseFormValueBlock(allocator, in_stream, endian, 4),
325325 FORM_block => x: {
326 const block_len = try noasync leb.readULEB128(usize, in_stream);
326 const block_len = try nosuspend leb.readULEB128(usize, in_stream);
327327 return parseFormValueBlockLen(allocator, in_stream, block_len);
328328 },
329329 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
335335 return parseFormValueConstant(allocator, in_stream, signed, endian, -1);
336336 },
337337 FORM_exprloc => {
338 const size = try noasync leb.readULEB128(usize, in_stream);
338 const size = try nosuspend leb.readULEB128(usize, in_stream);
339339 const buf = try readAllocBytes(allocator, in_stream, size);
340340 return FormValue{ .ExprLoc = buf };
341341 },
342 FORM_flag => FormValue{ .Flag = (try noasync in_stream.readByte()) != 0 },
342 FORM_flag => FormValue{ .Flag = (try nosuspend in_stream.readByte()) != 0 },
343343 FORM_flag_present => FormValue{ .Flag = true },
344344 FORM_sec_offset => FormValue{ .SecOffset = try readAddress(in_stream, endian, is_64) },
345345
......@@ -350,12 +350,12 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endia
350350 FORM_ref_udata => parseFormValueRef(allocator, in_stream, endian, -1),
351351
352352 FORM_ref_addr => FormValue{ .RefAddr = try readAddress(in_stream, endian, is_64) },
353 FORM_ref_sig8 => FormValue{ .Ref = try noasync in_stream.readInt(u64, endian) },
353 FORM_ref_sig8 => FormValue{ .Ref = try nosuspend in_stream.readInt(u64, endian) },
354354
355355 FORM_string => FormValue{ .String = try in_stream.readUntilDelimiterAlloc(allocator, 0, math.maxInt(usize)) },
356356 FORM_strp => FormValue{ .StrPtr = try readAddress(in_stream, endian, is_64) },
357357 FORM_indirect => {
358 const child_form_id = try noasync leb.readULEB128(u64, in_stream);
358 const child_form_id = try nosuspend leb.readULEB128(u64, in_stream);
359359 const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64));
360360 var frame = try allocator.create(F);
361361 defer allocator.destroy(frame);
lib/std/event/batch.zig+2-2
......@@ -75,7 +75,7 @@ pub fn Batch(
7575 const job = &self.jobs[self.next_job_index];
7676 self.next_job_index = (self.next_job_index + 1) % max_jobs;
7777 if (job.frame) |existing| {
78 job.result = if (async_ok) await existing else noasync await existing;
78 job.result = if (async_ok) await existing else nosuspend await existing;
7979 if (CollectedResult != void) {
8080 job.result catch |err| {
8181 self.collected_result = err;
......@@ -94,7 +94,7 @@ pub fn Batch(
9494 /// a time, however, it need not be the same thread.
9595 pub fn wait(self: *Self) CollectedResult {
9696 for (self.jobs) |*job| if (job.frame) |f| {
97 job.result = if (async_ok) await f else noasync await f;
97 job.result = if (async_ok) await f else nosuspend await f;
9898 if (CollectedResult != void) {
9999 job.result catch |err| {
100100 self.collected_result = err;
lib/std/event/loop.zig+4-4
......@@ -195,7 +195,7 @@ pub const Loop = struct {
195195 const wakeup_bytes = [_]u8{0x1} ** 8;
196196
197197 fn initOsData(self: *Loop, extra_thread_count: usize) InitOsDataError!void {
198 noasync switch (builtin.os.tag) {
198 nosuspend switch (builtin.os.tag) {
199199 .linux => {
200200 errdefer {
201201 while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd);
......@@ -371,7 +371,7 @@ pub const Loop = struct {
371371 }
372372
373373 fn deinitOsData(self: *Loop) void {
374 noasync switch (builtin.os.tag) {
374 nosuspend switch (builtin.os.tag) {
375375 .linux => {
376376 os.close(self.os_data.final_eventfd);
377377 while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd);
......@@ -663,7 +663,7 @@ pub const Loop = struct {
663663 }
664664
665665 pub fn finishOneEvent(self: *Loop) void {
666 noasync {
666 nosuspend {
667667 const prev = @atomicRmw(usize, &self.pending_event_count, .Sub, 1, .SeqCst);
668668 if (prev != 1) return;
669669
......@@ -1041,7 +1041,7 @@ pub const Loop = struct {
10411041 }
10421042
10431043 fn posixFsRun(self: *Loop) void {
1044 noasync while (true) {
1044 nosuspend while (true) {
10451045 self.fs_thread_wakeup.reset();
10461046 while (self.fs_queue.get()) |node| {
10471047 switch (node.data.msg) {
lib/std/zig/system/macos.zig+9-4
......@@ -39,7 +39,7 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
3939 zend += 1;
4040 }
4141 if (zend == yindex + 1) return error.InvalidVersion;
42 const z = std.fmt.parseUnsigned(u16, build[yindex + 1..zend], 10) catch return error.InvalidVersion;
42 const z = std.fmt.parseUnsigned(u16, build[yindex + 1 .. zend], 10) catch return error.InvalidVersion;
4343
4444 result.patch = switch (result.minor) {
4545 // TODO: compiler complains without explicit @as() coercion
......@@ -97,7 +97,9 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
9797 4 => @as(u32, switch (y) { // Tiger: 10.4
9898 'A' => 0,
9999 'B' => 1,
100 'C', 'E', => 2,
100 'C',
101 'E',
102 => 2,
101103 'F' => 3,
102104 'G' => @as(u32, block: {
103105 if (z >= 1454) break :block 5;
......@@ -105,7 +107,10 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
105107 }),
106108 'H' => 5,
107109 'I' => 6,
108 'J', 'K', 'N', => 7,
110 'J',
111 'K',
112 'N',
113 => 7,
109114 'L' => 8,
110115 'P' => 9,
111116 'R' => 10,
......@@ -438,7 +443,7 @@ test "version_from_build" {
438443 for (known) |pair| {
439444 var buf: [32]u8 = undefined;
440445 const ver = try version_from_build(pair[0]);
441 const sver = try std.fmt.bufPrint(buf[0..], "{}.{}.{}", .{ver.major, ver.minor, ver.patch});
446 const sver = try std.fmt.bufPrint(buf[0..], "{}.{}.{}", .{ ver.major, ver.minor, ver.patch });
442447 std.testing.expect(std.mem.eql(u8, sver, pair[1]));
443448 }
444449}
test/stage1/behavior/async_fn.zig+5-5
......@@ -1093,7 +1093,7 @@ test "recursive call of await @asyncCall with struct return type" {
10931093test "noasync function call" {
10941094 const S = struct {
10951095 fn doTheTest() void {
1096 const result = noasync add(50, 100);
1096 const result = nosuspend add(50, 100);
10971097 expect(result == 150);
10981098 }
10991099 fn add(a: i32, b: i32) i32 {
......@@ -1517,7 +1517,7 @@ test "noasync await" {
15171517
15181518 fn doTheTest() void {
15191519 var frame = async foo(false);
1520 expect(noasync await frame == 42);
1520 expect(nosuspend await frame == 42);
15211521 finished = true;
15221522 }
15231523
......@@ -1544,8 +1544,8 @@ test "noasync on function calls" {
15441544 return S0{};
15451545 }
15461546 };
1547 expectEqual(@as(i32, 42), noasync S1.c().b);
1548 expectEqual(@as(i32, 42), (try noasync S1.d()).b);
1547 expectEqual(@as(i32, 42), nosuspend S1.c().b);
1548 expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
15491549}
15501550
15511551test "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" {
15611561 };
15621562 var frame = async S.foo();
15631563 resume @ptrCast(anyframe->bool, @alignCast(@alignOf(@Frame(S.foo)), S.x));
1564 expect(noasync await frame);
1564 expect(nosuspend await frame);
15651565}
test/stage1/behavior/cast.zig+1-1
......@@ -823,7 +823,7 @@ test "peer type resolve array pointer and unknown pointer" {
823823
824824 comptime expect(@TypeOf(&array, const_ptr) == [*]const u8);
825825 comptime expect(@TypeOf(const_ptr, &array) == [*]const u8);
826
826
827827 comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8);
828828 comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8);
829829}
test/standalone/main_return_error/error_u8.zig+1-3
......@@ -1,6 +1,4 @@
1const Err = error {
2 Foo
3};
1const Err = error{Foo};
42
53pub fn main() !u8 {
64 return Err.Foo;
test/standalone/main_return_error/error_u8_non_zero.zig+5-2
......@@ -1,6 +1,9 @@
1const Err = error { Foo };
1const Err = error{Foo};
22
3fn foo() u8 { var x = @intCast(u8, 9); return x; }
3fn foo() u8 {
4 var x = @intCast(u8, 9);
5 return x;
6}
47
58pub fn main() !u8 {
69 if (foo() == 7) return Err.Foo;