authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-06 19:38:59+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-07 10:30:11+02:00
logcb20093614efecb341f8b3260bf9f91bb10556e6
treeacbc8f6fae9e00bf79223162d5c5ca747540456c
parentb06e5b8c6862ce77dab314c7817709f0832799df
signaturelock-open Commit is signed but in an unrecognized format.

self hosted compiler: remove await async pattern


9 files changed, 151 insertions(+), 192 deletions(-)

src-self-hosted/codegen.zig+1-1
...@@ -17,7 +17,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)...@@ -17,7 +17,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
17 defer fn_val.base.deref(comp);17 defer fn_val.base.deref(comp);
18 defer code.destroy(comp.gpa());18 defer code.destroy(comp.gpa());
1919
20 var output_path = try await (async comp.createRandomOutputPath(comp.target.objFileExt()) catch unreachable);20 var output_path = try comp.createRandomOutputPath(comp.target.objFileExt());
21 errdefer output_path.deinit();21 errdefer output_path.deinit();
2222
23 const llvm_handle = try comp.zig_compiler.getAnyLlvmContext();23 const llvm_handle = try comp.zig_compiler.getAnyLlvmContext();
src-self-hosted/compilation.zig+63-81
...@@ -93,8 +93,8 @@ pub const ZigCompiler = struct {...@@ -93,8 +93,8 @@ pub const ZigCompiler = struct {
93 }93 }
9494
95 pub async fn getNativeLibC(self: *ZigCompiler) !*LibCInstallation {95 pub async fn getNativeLibC(self: *ZigCompiler) !*LibCInstallation {
96 if (await (async self.native_libc.start() catch unreachable)) |ptr| return ptr;96 if (self.native_libc.start()) |ptr| return ptr;
97 try await (async self.native_libc.data.findNative(self.loop) catch unreachable);97 try self.native_libc.data.findNative(self.loop);
98 self.native_libc.resolve();98 self.native_libc.resolve();
99 return &self.native_libc.data;99 return &self.native_libc.data;
100 }100 }
...@@ -227,8 +227,8 @@ pub const Compilation = struct {...@@ -227,8 +227,8 @@ pub const Compilation = struct {
227 /// need to wait on this group before deinitializing227 /// need to wait on this group before deinitializing
228 deinit_group: event.Group(void),228 deinit_group: event.Group(void),
229229
230 destroy_handle: promise,230 // destroy_frame: @Frame(createAsync),
231 main_loop_handle: promise,231 main_loop_frame: @Frame(Compilation.mainLoop),
232 main_loop_future: event.Future(void),232 main_loop_future: event.Future(void),
233233
234 have_err_ret_tracing: bool,234 have_err_ret_tracing: bool,
...@@ -348,7 +348,7 @@ pub const Compilation = struct {...@@ -348,7 +348,7 @@ pub const Compilation = struct {
348 zig_lib_dir: []const u8,348 zig_lib_dir: []const u8,
349 ) !*Compilation {349 ) !*Compilation {
350 var optional_comp: ?*Compilation = null;350 var optional_comp: ?*Compilation = null;
351 const handle = try async<zig_compiler.loop.allocator> createAsync(351 const frame = async createAsync(
352 &optional_comp,352 &optional_comp,
353 zig_compiler,353 zig_compiler,
354 name,354 name,
...@@ -359,10 +359,7 @@ pub const Compilation = struct {...@@ -359,10 +359,7 @@ pub const Compilation = struct {
359 is_static,359 is_static,
360 zig_lib_dir,360 zig_lib_dir,
361 );361 );
362 return optional_comp orelse if (getAwaitResult(362 return optional_comp orelse await frame;
363 zig_compiler.loop.allocator,
364 handle,
365 )) |_| unreachable else |err| err;
366 }363 }
367364
368 async fn createAsync(365 async fn createAsync(
...@@ -376,10 +373,6 @@ pub const Compilation = struct {...@@ -376,10 +373,6 @@ pub const Compilation = struct {
376 is_static: bool,373 is_static: bool,
377 zig_lib_dir: []const u8,374 zig_lib_dir: []const u8,
378 ) !void {375 ) !void {
379 // workaround for https://github.com/ziglang/zig/issues/1194
380 suspend {
381 resume @handle();
382 }
383376
384 const loop = zig_compiler.loop;377 const loop = zig_compiler.loop;
385 var comp = Compilation{378 var comp = Compilation{
...@@ -395,8 +388,8 @@ pub const Compilation = struct {...@@ -395,8 +388,8 @@ pub const Compilation = struct {
395 .zig_lib_dir = zig_lib_dir,388 .zig_lib_dir = zig_lib_dir,
396 .zig_std_dir = undefined,389 .zig_std_dir = undefined,
397 .tmp_dir = event.Future(BuildError![]u8).init(loop),390 .tmp_dir = event.Future(BuildError![]u8).init(loop),
398 .destroy_handle = @handle(),391 .destroy_frame = @frame(),
399 .main_loop_handle = undefined,392 .main_loop_frame = undefined,
400 .main_loop_future = event.Future(void).init(loop),393 .main_loop_future = event.Future(void).init(loop),
401394
402 .name = undefined,395 .name = undefined,
...@@ -546,7 +539,7 @@ pub const Compilation = struct {...@@ -546,7 +539,7 @@ pub const Compilation = struct {
546 try comp.initTypes();539 try comp.initTypes();
547 defer comp.primitive_type_table.deinit();540 defer comp.primitive_type_table.deinit();
548541
549 comp.main_loop_handle = async comp.mainLoop() catch unreachable;542 comp.main_loop_frame = async comp.mainLoop() catch unreachable;
550 // Set this to indicate that initialization completed successfully.543 // Set this to indicate that initialization completed successfully.
551 // from here on out we must not return an error.544 // from here on out we must not return an error.
552 // This must occur before the first suspend/await.545 // This must occur before the first suspend/await.
...@@ -555,7 +548,7 @@ pub const Compilation = struct {...@@ -555,7 +548,7 @@ pub const Compilation = struct {
555 suspend;548 suspend;
556 // From here on is cleanup.549 // From here on is cleanup.
557550
558 await (async comp.deinit_group.wait() catch unreachable);551 comp.deinit_group.wait();
559552
560 if (comp.tmp_dir.getOrNull()) |tmp_dir_result| if (tmp_dir_result.*) |tmp_dir| {553 if (comp.tmp_dir.getOrNull()) |tmp_dir_result| if (tmp_dir_result.*) |tmp_dir| {
561 // TODO evented I/O?554 // TODO evented I/O?
...@@ -578,10 +571,10 @@ pub const Compilation = struct {...@@ -578,10 +571,10 @@ pub const Compilation = struct {
578 error.Overflow => return error.Overflow,571 error.Overflow => return error.Overflow,
579 error.InvalidCharacter => unreachable, // we just checked the characters above572 error.InvalidCharacter => unreachable, // we just checked the characters above
580 };573 };
581 const int_type = try await (async Type.Int.get(comp, Type.Int.Key{574 const int_type = try Type.Int.get(comp, Type.Int.Key{
582 .bit_count = bit_count,575 .bit_count = bit_count,
583 .is_signed = is_signed,576 .is_signed = is_signed,
584 }) catch unreachable);577 });
585 errdefer int_type.base.base.deref();578 errdefer int_type.base.base.deref();
586 return &int_type.base;579 return &int_type.base;
587 },580 },
...@@ -758,8 +751,8 @@ pub const Compilation = struct {...@@ -758,8 +751,8 @@ pub const Compilation = struct {
758 }751 }
759752
760 pub fn destroy(self: *Compilation) void {753 pub fn destroy(self: *Compilation) void {
761 cancel self.main_loop_handle;754 await self.main_loop_frame;
762 resume self.destroy_handle;755 resume self.destroy_frame;
763 }756 }
764757
765 fn start(self: *Compilation) void {758 fn start(self: *Compilation) void {
...@@ -768,13 +761,13 @@ pub const Compilation = struct {...@@ -768,13 +761,13 @@ pub const Compilation = struct {
768761
769 async fn mainLoop(self: *Compilation) void {762 async fn mainLoop(self: *Compilation) void {
770 // wait until start() is called763 // wait until start() is called
771 _ = await (async self.main_loop_future.get() catch unreachable);764 _ = self.main_loop_future.get();
772765
773 var build_result = await (async self.initialCompile() catch unreachable);766 var build_result = self.initialCompile();
774767
775 while (true) {768 while (true) {
776 const link_result = if (build_result) blk: {769 const link_result = if (build_result) blk: {
777 break :blk await (async self.maybeLink() catch unreachable);770 break :blk self.maybeLink();
778 } else |err| err;771 } else |err| err;
779 // this makes a handy error return trace and stack trace in debug mode772 // this makes a handy error return trace and stack trace in debug mode
780 if (std.debug.runtime_safety) {773 if (std.debug.runtime_safety) {
...@@ -782,28 +775,28 @@ pub const Compilation = struct {...@@ -782,28 +775,28 @@ pub const Compilation = struct {
782 }775 }
783776
784 const compile_errors = blk: {777 const compile_errors = blk: {
785 const held = await (async self.compile_errors.acquire() catch unreachable);778 const held = self.compile_errors.acquire();
786 defer held.release();779 defer held.release();
787 break :blk held.value.toOwnedSlice();780 break :blk held.value.toOwnedSlice();
788 };781 };
789782
790 if (link_result) |_| {783 if (link_result) |_| {
791 if (compile_errors.len == 0) {784 if (compile_errors.len == 0) {
792 await (async self.events.put(Event.Ok) catch unreachable);785 self.events.put(Event.Ok);
793 } else {786 } else {
794 await (async self.events.put(Event{ .Fail = compile_errors }) catch unreachable);787 self.events.put(Event{ .Fail = compile_errors });
795 }788 }
796 } else |err| {789 } else |err| {
797 // if there's an error then the compile errors have dangling references790 // if there's an error then the compile errors have dangling references
798 self.gpa().free(compile_errors);791 self.gpa().free(compile_errors);
799792
800 await (async self.events.put(Event{ .Error = err }) catch unreachable);793 self.events.put(Event{ .Error = err });
801 }794 }
802795
803 // First, get an item from the watch channel, waiting on the channel.796 // First, get an item from the watch channel, waiting on the channel.
804 var group = event.Group(BuildError!void).init(self.loop);797 var group = event.Group(BuildError!void).init(self.loop);
805 {798 {
806 const ev = (await (async self.fs_watch.channel.get() catch unreachable)) catch |err| {799 const ev = (self.fs_watch.channel.get()) catch |err| {
807 build_result = err;800 build_result = err;
808 continue;801 continue;
809 };802 };
...@@ -814,7 +807,7 @@ pub const Compilation = struct {...@@ -814,7 +807,7 @@ pub const Compilation = struct {
814 };807 };
815 }808 }
816 // Next, get all the items from the channel that are buffered up.809 // Next, get all the items from the channel that are buffered up.
817 while (await (async self.fs_watch.channel.getOrNull() catch unreachable)) |ev_or_err| {810 while (self.fs_watch.channel.getOrNull()) |ev_or_err| {
818 if (ev_or_err) |ev| {811 if (ev_or_err) |ev| {
819 const root_scope = ev.data;812 const root_scope = ev.data;
820 group.call(rebuildFile, self, root_scope) catch |err| {813 group.call(rebuildFile, self, root_scope) catch |err| {
...@@ -826,17 +819,17 @@ pub const Compilation = struct {...@@ -826,17 +819,17 @@ pub const Compilation = struct {
826 continue;819 continue;
827 }820 }
828 }821 }
829 build_result = await (async group.wait() catch unreachable);822 build_result = group.wait();
830 }823 }
831 }824 }
832825
833 async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) !void {826 async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) !void {
834 const tree_scope = blk: {827 const tree_scope = blk: {
835 const source_code = (await (async fs.readFile(828 const source_code = fs.readFile(
836 self.loop,829 self.loop,
837 root_scope.realpath,830 root_scope.realpath,
838 max_src_size,831 max_src_size,
839 ) catch unreachable)) catch |err| {832 ) catch |err| {
840 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err));833 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err));
841 return;834 return;
842 };835 };
...@@ -856,13 +849,13 @@ pub const Compilation = struct {...@@ -856,13 +849,13 @@ pub const Compilation = struct {
856 const msg = try Msg.createFromParseErrorAndScope(self, tree_scope, parse_error);849 const msg = try Msg.createFromParseErrorAndScope(self, tree_scope, parse_error);
857 errdefer msg.destroy();850 errdefer msg.destroy();
858851
859 try await (async self.addCompileErrorAsync(msg) catch unreachable);852 try self.addCompileErrorAsync(msg);
860 }853 }
861 if (tree_scope.tree.errors.len != 0) {854 if (tree_scope.tree.errors.len != 0) {
862 return;855 return;
863 }856 }
864857
865 const locked_table = await (async root_scope.decls.table.acquireWrite() catch unreachable);858 const locked_table = root_scope.decls.table.acquireWrite();
866 defer locked_table.release();859 defer locked_table.release();
867860
868 var decl_group = event.Group(BuildError!void).init(self.loop);861 var decl_group = event.Group(BuildError!void).init(self.loop);
...@@ -876,7 +869,7 @@ pub const Compilation = struct {...@@ -876,7 +869,7 @@ pub const Compilation = struct {
876 tree_scope,869 tree_scope,
877 );870 );
878871
879 try await (async decl_group.wait() catch unreachable);872 try decl_group.wait();
880 }873 }
881874
882 async fn rebuildChangedDecls(875 async fn rebuildChangedDecls(
...@@ -988,20 +981,20 @@ pub const Compilation = struct {...@@ -988,20 +981,20 @@ pub const Compilation = struct {
988 }981 }
989982
990 async fn maybeLink(self: *Compilation) !void {983 async fn maybeLink(self: *Compilation) !void {
991 (await (async self.prelink_group.wait() catch unreachable)) catch |err| switch (err) {984 (self.prelink_group.wait()) catch |err| switch (err) {
992 error.SemanticAnalysisFailed => {},985 error.SemanticAnalysisFailed => {},
993 else => return err,986 else => return err,
994 };987 };
995988
996 const any_prelink_errors = blk: {989 const any_prelink_errors = blk: {
997 const compile_errors = await (async self.compile_errors.acquire() catch unreachable);990 const compile_errors = self.compile_errors.acquire();
998 defer compile_errors.release();991 defer compile_errors.release();
999992
1000 break :blk compile_errors.value.len != 0;993 break :blk compile_errors.value.len != 0;
1001 };994 };
1002995
1003 if (!any_prelink_errors) {996 if (!any_prelink_errors) {
1004 try await (async link(self) catch unreachable);997 try link(self);
1005 }998 }
1006 }999 }
10071000
...@@ -1013,12 +1006,12 @@ pub const Compilation = struct {...@@ -1013,12 +1006,12 @@ pub const Compilation = struct {
1013 node: *ast.Node,1006 node: *ast.Node,
1014 expected_type: ?*Type,1007 expected_type: ?*Type,
1015 ) !*ir.Code {1008 ) !*ir.Code {
1016 const unanalyzed_code = try await (async ir.gen(1009 const unanalyzed_code = try ir.gen(
1017 comp,1010 comp,
1018 node,1011 node,
1019 tree_scope,1012 tree_scope,
1020 scope,1013 scope,
1021 ) catch unreachable);1014 );
1022 defer unanalyzed_code.destroy(comp.gpa());1015 defer unanalyzed_code.destroy(comp.gpa());
10231016
1024 if (comp.verbose_ir) {1017 if (comp.verbose_ir) {
...@@ -1026,11 +1019,11 @@ pub const Compilation = struct {...@@ -1026,11 +1019,11 @@ pub const Compilation = struct {
1026 unanalyzed_code.dump();1019 unanalyzed_code.dump();
1027 }1020 }
10281021
1029 const analyzed_code = try await (async ir.analyze(1022 const analyzed_code = try ir.analyze(
1030 comp,1023 comp,
1031 unanalyzed_code,1024 unanalyzed_code,
1032 expected_type,1025 expected_type,
1033 ) catch unreachable);1026 );
1034 errdefer analyzed_code.destroy(comp.gpa());1027 errdefer analyzed_code.destroy(comp.gpa());
10351028
1036 if (comp.verbose_ir) {1029 if (comp.verbose_ir) {
...@@ -1050,13 +1043,13 @@ pub const Compilation = struct {...@@ -1050,13 +1043,13 @@ pub const Compilation = struct {
1050 const void_type = Type.Void.get(comp);1043 const void_type = Type.Void.get(comp);
1051 defer void_type.base.base.deref(comp);1044 defer void_type.base.base.deref(comp);
10521045
1053 const analyzed_code = (await (async genAndAnalyzeCode(1046 const analyzed_code = genAndAnalyzeCode(
1054 comp,1047 comp,
1055 tree_scope,1048 tree_scope,
1056 scope,1049 scope,
1057 comptime_node.expr,1050 comptime_node.expr,
1058 &void_type.base,1051 &void_type.base,
1059 ) catch unreachable)) catch |err| switch (err) {1052 ) catch |err| switch (err) {
1060 // This poison value should not cause the errdefers to run. It simply means1053 // This poison value should not cause the errdefers to run. It simply means
1061 // that comp.compile_errors is populated.1054 // that comp.compile_errors is populated.
1062 error.SemanticAnalysisFailed => return {},1055 error.SemanticAnalysisFailed => return {},
...@@ -1112,14 +1105,14 @@ pub const Compilation = struct {...@@ -1112,14 +1105,14 @@ pub const Compilation = struct {
1112 ) !void {1105 ) !void {
1113 errdefer msg.destroy();1106 errdefer msg.destroy();
11141107
1115 const compile_errors = await (async self.compile_errors.acquire() catch unreachable);1108 const compile_errors = self.compile_errors.acquire();
1116 defer compile_errors.release();1109 defer compile_errors.release();
11171110
1118 try compile_errors.value.append(msg);1111 try compile_errors.value.append(msg);
1119 }1112 }
11201113
1121 async fn verifyUniqueSymbol(self: *Compilation, decl: *Decl) !void {1114 async fn verifyUniqueSymbol(self: *Compilation, decl: *Decl) !void {
1122 const exported_symbol_names = await (async self.exported_symbol_names.acquire() catch unreachable);1115 const exported_symbol_names = self.exported_symbol_names.acquire();
1123 defer exported_symbol_names.release();1116 defer exported_symbol_names.release();
11241117
1125 if (try exported_symbol_names.value.put(decl.name, decl)) |other_decl| {1118 if (try exported_symbol_names.value.put(decl.name, decl)) |other_decl| {
...@@ -1173,9 +1166,9 @@ pub const Compilation = struct {...@@ -1173,9 +1166,9 @@ pub const Compilation = struct {
11731166
1174 /// cancels itself so no need to await or cancel the promise.1167 /// cancels itself so no need to await or cancel the promise.
1175 async fn startFindingNativeLibC(self: *Compilation) void {1168 async fn startFindingNativeLibC(self: *Compilation) void {
1176 await (async self.loop.yield() catch unreachable);1169 self.loop.yield();
1177 // we don't care if it fails, we're just trying to kick off the future resolution1170 // we don't care if it fails, we're just trying to kick off the future resolution
1178 _ = (await (async self.zig_compiler.getNativeLibC() catch unreachable)) catch return;1171 _ = (self.zig_compiler.getNativeLibC()) catch return;
1179 }1172 }
11801173
1181 /// General Purpose Allocator. Must free when done.1174 /// General Purpose Allocator. Must free when done.
...@@ -1191,8 +1184,8 @@ pub const Compilation = struct {...@@ -1191,8 +1184,8 @@ pub const Compilation = struct {
1191 /// If the temporary directory for this compilation has not been created, it creates it.1184 /// If the temporary directory for this compilation has not been created, it creates it.
1192 /// Then it creates a random file name in that dir and returns it.1185 /// Then it creates a random file name in that dir and returns it.
1193 pub async fn createRandomOutputPath(self: *Compilation, suffix: []const u8) !Buffer {1186 pub async fn createRandomOutputPath(self: *Compilation, suffix: []const u8) !Buffer {
1194 const tmp_dir = try await (async self.getTmpDir() catch unreachable);1187 const tmp_dir = try self.getTmpDir();
1195 const file_prefix = await (async self.getRandomFileName() catch unreachable);1188 const file_prefix = self.getRandomFileName();
11961189
1197 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);1190 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
1198 defer self.gpa().free(file_name);1191 defer self.gpa().free(file_name);
...@@ -1207,14 +1200,14 @@ pub const Compilation = struct {...@@ -1207,14 +1200,14 @@ pub const Compilation = struct {
1207 /// Then returns it. The directory is unique to this Compilation and cleaned up when1200 /// Then returns it. The directory is unique to this Compilation and cleaned up when
1208 /// the Compilation deinitializes.1201 /// the Compilation deinitializes.
1209 async fn getTmpDir(self: *Compilation) ![]const u8 {1202 async fn getTmpDir(self: *Compilation) ![]const u8 {
1210 if (await (async self.tmp_dir.start() catch unreachable)) |ptr| return ptr.*;1203 if (self.tmp_dir.start()) |ptr| return ptr.*;
1211 self.tmp_dir.data = await (async self.getTmpDirImpl() catch unreachable);1204 self.tmp_dir.data = self.getTmpDirImpl();
1212 self.tmp_dir.resolve();1205 self.tmp_dir.resolve();
1213 return self.tmp_dir.data;1206 return self.tmp_dir.data;
1214 }1207 }
12151208
1216 async fn getTmpDirImpl(self: *Compilation) ![]u8 {1209 async fn getTmpDirImpl(self: *Compilation) ![]u8 {
1217 const comp_dir_name = await (async self.getRandomFileName() catch unreachable);1210 const comp_dir_name = self.getRandomFileName();
1218 const zig_dir_path = try getZigDir(self.gpa());1211 const zig_dir_path = try getZigDir(self.gpa());
1219 defer self.gpa().free(zig_dir_path);1212 defer self.gpa().free(zig_dir_path);
12201213
...@@ -1233,7 +1226,7 @@ pub const Compilation = struct {...@@ -1233,7 +1226,7 @@ pub const Compilation = struct {
1233 var rand_bytes: [9]u8 = undefined;1226 var rand_bytes: [9]u8 = undefined;
12341227
1235 {1228 {
1236 const held = await (async self.zig_compiler.prng.acquire() catch unreachable);1229 const held = self.zig_compiler.prng.acquire();
1237 defer held.release();1230 defer held.release();
12381231
1239 held.value.random.bytes(rand_bytes[0..]);1232 held.value.random.bytes(rand_bytes[0..]);
...@@ -1256,7 +1249,7 @@ pub const Compilation = struct {...@@ -1256,7 +1249,7 @@ pub const Compilation = struct {
1256 node: *ast.Node,1249 node: *ast.Node,
1257 expected_type: *Type,1250 expected_type: *Type,
1258 ) !*Value {1251 ) !*Value {
1259 const analyzed_code = try await (async comp.genAndAnalyzeCode(tree_scope, scope, node, expected_type) catch unreachable);1252 const analyzed_code = try comp.genAndAnalyzeCode(tree_scope, scope, node, expected_type);
1260 defer analyzed_code.destroy(comp.gpa());1253 defer analyzed_code.destroy(comp.gpa());
12611254
1262 return analyzed_code.getCompTimeResult(comp);1255 return analyzed_code.getCompTimeResult(comp);
...@@ -1266,7 +1259,7 @@ pub const Compilation = struct {...@@ -1266,7 +1259,7 @@ pub const Compilation = struct {
1266 const meta_type = &Type.MetaType.get(comp).base;1259 const meta_type = &Type.MetaType.get(comp).base;
1267 defer meta_type.base.deref(comp);1260 defer meta_type.base.deref(comp);
12681261
1269 const result_val = try await (async comp.analyzeConstValue(tree_scope, scope, node, meta_type) catch unreachable);1262 const result_val = try comp.analyzeConstValue(tree_scope, scope, node, meta_type);
1270 errdefer result_val.base.deref(comp);1263 errdefer result_val.base.deref(comp);
12711264
1272 return result_val.cast(Type).?;1265 return result_val.cast(Type).?;
...@@ -1274,9 +1267,9 @@ pub const Compilation = struct {...@@ -1274,9 +1267,9 @@ pub const Compilation = struct {
12741267
1275 /// This declaration has been blessed as going into the final code generation.1268 /// This declaration has been blessed as going into the final code generation.
1276 pub async fn resolveDecl(comp: *Compilation, decl: *Decl) !void {1269 pub async fn resolveDecl(comp: *Compilation, decl: *Decl) !void {
1277 if (await (async decl.resolution.start() catch unreachable)) |ptr| return ptr.*;1270 if (decl.resolution.start()) |ptr| return ptr.*;
12781271
1279 decl.resolution.data = try await (async generateDecl(comp, decl) catch unreachable);1272 decl.resolution.data = try generateDecl(comp, decl);
1280 decl.resolution.resolve();1273 decl.resolution.resolve();
1281 return decl.resolution.data;1274 return decl.resolution.data;
1282 }1275 }
...@@ -1298,7 +1291,7 @@ async fn generateDecl(comp: *Compilation, decl: *Decl) !void {...@@ -1298,7 +1291,7 @@ async fn generateDecl(comp: *Compilation, decl: *Decl) !void {
1298 Decl.Id.Var => @panic("TODO"),1291 Decl.Id.Var => @panic("TODO"),
1299 Decl.Id.Fn => {1292 Decl.Id.Fn => {
1300 const fn_decl = @fieldParentPtr(Decl.Fn, "base", decl);1293 const fn_decl = @fieldParentPtr(Decl.Fn, "base", decl);
1301 return await (async generateDeclFn(comp, fn_decl) catch unreachable);1294 return generateDeclFn(comp, fn_decl);
1302 },1295 },
1303 Decl.Id.CompTime => @panic("TODO"),1296 Decl.Id.CompTime => @panic("TODO"),
1304 }1297 }
...@@ -1307,12 +1300,12 @@ async fn generateDecl(comp: *Compilation, decl: *Decl) !void {...@@ -1307,12 +1300,12 @@ async fn generateDecl(comp: *Compilation, decl: *Decl) !void {
1307async fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {1300async fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {
1308 const tree_scope = fn_decl.base.tree_scope;1301 const tree_scope = fn_decl.base.tree_scope;
13091302
1310 const body_node = fn_decl.fn_proto.body_node orelse return await (async generateDeclFnProto(comp, fn_decl) catch unreachable);1303 const body_node = fn_decl.fn_proto.body_node orelse return generateDeclFnProto(comp, fn_decl);
13111304
1312 const fndef_scope = try Scope.FnDef.create(comp, fn_decl.base.parent_scope);1305 const fndef_scope = try Scope.FnDef.create(comp, fn_decl.base.parent_scope);
1313 defer fndef_scope.base.deref(comp);1306 defer fndef_scope.base.deref(comp);
13141307
1315 const fn_type = try await (async analyzeFnType(comp, tree_scope, fn_decl.base.parent_scope, fn_decl.fn_proto) catch unreachable);1308 const fn_type = try analyzeFnType(comp, tree_scope, fn_decl.base.parent_scope, fn_decl.fn_proto);
1316 defer fn_type.base.base.deref(comp);1309 defer fn_type.base.base.deref(comp);
13171310
1318 var symbol_name = try std.Buffer.init(comp.gpa(), fn_decl.base.name);1311 var symbol_name = try std.Buffer.init(comp.gpa(), fn_decl.base.name);
...@@ -1356,12 +1349,12 @@ async fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {...@@ -1356,12 +1349,12 @@ async fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {
1356 try fn_type.non_key.Normal.variable_list.append(var_scope);1349 try fn_type.non_key.Normal.variable_list.append(var_scope);
1357 }1350 }
13581351
1359 const analyzed_code = try await (async comp.genAndAnalyzeCode(1352 const analyzed_code = try comp.genAndAnalyzeCode(
1360 tree_scope,1353 tree_scope,
1361 fn_val.child_scope,1354 fn_val.child_scope,
1362 body_node,1355 body_node,
1363 fn_type.key.data.Normal.return_type,1356 fn_type.key.data.Normal.return_type,
1364 ) catch unreachable);1357 );
1365 errdefer analyzed_code.destroy(comp.gpa());1358 errdefer analyzed_code.destroy(comp.gpa());
13661359
1367 assert(fn_val.block_scope != null);1360 assert(fn_val.block_scope != null);
...@@ -1378,7 +1371,7 @@ async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) void {...@@ -1378,7 +1371,7 @@ async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) void {
13781371
1379 fn_val.link_set_node.data = fn_val;1372 fn_val.link_set_node.data = fn_val;
13801373
1381 const held = await (async comp.fn_link_set.acquire() catch unreachable);1374 const held = comp.fn_link_set.acquire();
1382 defer held.release();1375 defer held.release();
13831376
1384 held.value.append(fn_val.link_set_node);1377 held.value.append(fn_val.link_set_node);
...@@ -1398,7 +1391,7 @@ async fn analyzeFnType(...@@ -1398,7 +1391,7 @@ async fn analyzeFnType(
1398 ast.Node.FnProto.ReturnType.Explicit => |n| n,1391 ast.Node.FnProto.ReturnType.Explicit => |n| n,
1399 ast.Node.FnProto.ReturnType.InferErrorSet => |n| n,1392 ast.Node.FnProto.ReturnType.InferErrorSet => |n| n,
1400 };1393 };
1401 const return_type = try await (async comp.analyzeTypeExpr(tree_scope, scope, return_type_node) catch unreachable);1394 const return_type = try comp.analyzeTypeExpr(tree_scope, scope, return_type_node);
1402 return_type.base.deref(comp);1395 return_type.base.deref(comp);
14031396
1404 var params = ArrayList(Type.Fn.Param).init(comp.gpa());1397 var params = ArrayList(Type.Fn.Param).init(comp.gpa());
...@@ -1414,7 +1407,7 @@ async fn analyzeFnType(...@@ -1414,7 +1407,7 @@ async fn analyzeFnType(
1414 var it = fn_proto.params.iterator(0);1407 var it = fn_proto.params.iterator(0);
1415 while (it.next()) |param_node_ptr| {1408 while (it.next()) |param_node_ptr| {
1416 const param_node = param_node_ptr.*.cast(ast.Node.ParamDecl).?;1409 const param_node = param_node_ptr.*.cast(ast.Node.ParamDecl).?;
1417 const param_type = try await (async comp.analyzeTypeExpr(tree_scope, scope, param_node.type_node) catch unreachable);1410 const param_type = try comp.analyzeTypeExpr(tree_scope, scope, param_node.type_node);
1418 errdefer param_type.base.deref(comp);1411 errdefer param_type.base.deref(comp);
1419 try params.append(Type.Fn.Param{1412 try params.append(Type.Fn.Param{
1420 .typ = param_type,1413 .typ = param_type,
...@@ -1443,7 +1436,7 @@ async fn analyzeFnType(...@@ -1443,7 +1436,7 @@ async fn analyzeFnType(
1443 comp.gpa().free(key.data.Normal.params);1436 comp.gpa().free(key.data.Normal.params);
1444 };1437 };
14451438
1446 const fn_type = try await (async Type.Fn.get(comp, key) catch unreachable);1439 const fn_type = try Type.Fn.get(comp, key);
1447 key_consumed = true;1440 key_consumed = true;
1448 errdefer fn_type.base.base.deref(comp);1441 errdefer fn_type.base.base.deref(comp);
14491442
...@@ -1451,12 +1444,12 @@ async fn analyzeFnType(...@@ -1451,12 +1444,12 @@ async fn analyzeFnType(
1451}1444}
14521445
1453async fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void {1446async fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void {
1454 const fn_type = try await (async analyzeFnType(1447 const fn_type = try analyzeFnType(
1455 comp,1448 comp,
1456 fn_decl.base.tree_scope,1449 fn_decl.base.tree_scope,
1457 fn_decl.base.parent_scope,1450 fn_decl.base.parent_scope,
1458 fn_decl.fn_proto,1451 fn_decl.fn_proto,
1459 ) catch unreachable);1452 );
1460 defer fn_type.base.base.deref(comp);1453 defer fn_type.base.base.deref(comp);
14611454
1462 var symbol_name = try std.Buffer.init(comp.gpa(), fn_decl.base.name);1455 var symbol_name = try std.Buffer.init(comp.gpa(), fn_decl.base.name);
...@@ -1468,14 +1461,3 @@ async fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void {...@@ -1468,14 +1461,3 @@ async fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void {
1468 fn_decl.value = Decl.Fn.Val{ .FnProto = fn_proto_val };1461 fn_decl.value = Decl.Fn.Val{ .FnProto = fn_proto_val };
1469 symbol_name_consumed = true;1462 symbol_name_consumed = true;
1470}1463}
1471
1472// TODO these are hacks which should probably be solved by the language
1473fn getAwaitResult(allocator: *Allocator, handle: var) @typeInfo(@typeOf(handle)).Promise.child.? {
1474 var result: ?@typeInfo(@typeOf(handle)).Promise.child.? = null;
1475 cancel (async<allocator> getAwaitResultAsync(handle, &result) catch unreachable);
1476 return result.?;
1477}
1478
1479async fn getAwaitResultAsync(handle: var, out: *?@typeInfo(@typeOf(handle)).Promise.child.?) void {
1480 out.* = await handle;
1481}
src-self-hosted/ir.zig+41-41
...@@ -116,16 +116,16 @@ pub const Inst = struct {...@@ -116,16 +116,16 @@ pub const Inst = struct {
116 Id.Return => return @fieldParentPtr(Return, "base", base).analyze(ira),116 Id.Return => return @fieldParentPtr(Return, "base", base).analyze(ira),
117 Id.Const => return @fieldParentPtr(Const, "base", base).analyze(ira),117 Id.Const => return @fieldParentPtr(Const, "base", base).analyze(ira),
118 Id.Call => return @fieldParentPtr(Call, "base", base).analyze(ira),118 Id.Call => return @fieldParentPtr(Call, "base", base).analyze(ira),
119 Id.DeclRef => return await (async @fieldParentPtr(DeclRef, "base", base).analyze(ira) catch unreachable),119 Id.DeclRef => return @fieldParentPtr(DeclRef, "base", base).analyze(ira),
120 Id.Ref => return await (async @fieldParentPtr(Ref, "base", base).analyze(ira) catch unreachable),120 Id.Ref => return @fieldParentPtr(Ref, "base", base).analyze(ira),
121 Id.DeclVar => return @fieldParentPtr(DeclVar, "base", base).analyze(ira),121 Id.DeclVar => return @fieldParentPtr(DeclVar, "base", base).analyze(ira),
122 Id.CheckVoidStmt => return @fieldParentPtr(CheckVoidStmt, "base", base).analyze(ira),122 Id.CheckVoidStmt => return @fieldParentPtr(CheckVoidStmt, "base", base).analyze(ira),
123 Id.Phi => return @fieldParentPtr(Phi, "base", base).analyze(ira),123 Id.Phi => return @fieldParentPtr(Phi, "base", base).analyze(ira),
124 Id.Br => return @fieldParentPtr(Br, "base", base).analyze(ira),124 Id.Br => return @fieldParentPtr(Br, "base", base).analyze(ira),
125 Id.AddImplicitReturnType => return @fieldParentPtr(AddImplicitReturnType, "base", base).analyze(ira),125 Id.AddImplicitReturnType => return @fieldParentPtr(AddImplicitReturnType, "base", base).analyze(ira),
126 Id.PtrType => return await (async @fieldParentPtr(PtrType, "base", base).analyze(ira) catch unreachable),126 Id.PtrType => return @fieldParentPtr(PtrType, "base", base).analyze(ira),
127 Id.VarPtr => return await (async @fieldParentPtr(VarPtr, "base", base).analyze(ira) catch unreachable),127 Id.VarPtr => return @fieldParentPtr(VarPtr, "base", base).analyze(ira),
128 Id.LoadPtr => return await (async @fieldParentPtr(LoadPtr, "base", base).analyze(ira) catch unreachable),128 Id.LoadPtr => return @fieldParentPtr(LoadPtr, "base", base).analyze(ira),
129 }129 }
130 }130 }
131131
...@@ -441,13 +441,13 @@ pub const Inst = struct {...@@ -441,13 +441,13 @@ pub const Inst = struct {
441 .volatility = self.params.volatility,441 .volatility = self.params.volatility,
442 });442 });
443 const elem_type = target.getKnownType();443 const elem_type = target.getKnownType();
444 const ptr_type = try await (async Type.Pointer.get(ira.irb.comp, Type.Pointer.Key{444 const ptr_type = try Type.Pointer.get(ira.irb.comp, Type.Pointer.Key{
445 .child_type = elem_type,445 .child_type = elem_type,
446 .mut = self.params.mut,446 .mut = self.params.mut,
447 .vol = self.params.volatility,447 .vol = self.params.volatility,
448 .size = Type.Pointer.Size.One,448 .size = Type.Pointer.Size.One,
449 .alignment = Type.Pointer.Align.Abi,449 .alignment = Type.Pointer.Align.Abi,
450 }) catch unreachable);450 });
451 // TODO: potentially set the hint that this is a stack pointer. But it might not be - this451 // TODO: potentially set the hint that this is a stack pointer. But it might not be - this
452 // could be a ref of a global, for example452 // could be a ref of a global, for example
453 new_inst.val = IrVal{ .KnownType = &ptr_type.base };453 new_inst.val = IrVal{ .KnownType = &ptr_type.base };
...@@ -474,7 +474,7 @@ pub const Inst = struct {...@@ -474,7 +474,7 @@ pub const Inst = struct {
474 }474 }
475475
476 pub async fn analyze(self: *const DeclRef, ira: *Analyze) !*Inst {476 pub async fn analyze(self: *const DeclRef, ira: *Analyze) !*Inst {
477 (await (async ira.irb.comp.resolveDecl(self.params.decl) catch unreachable)) catch |err| switch (err) {477 (ira.irb.comp.resolveDecl(self.params.decl)) catch |err| switch (err) {
478 error.OutOfMemory => return error.OutOfMemory,478 error.OutOfMemory => return error.OutOfMemory,
479 else => return error.SemanticAnalysisFailed,479 else => return error.SemanticAnalysisFailed,
480 };480 };
...@@ -527,13 +527,13 @@ pub const Inst = struct {...@@ -527,13 +527,13 @@ pub const Inst = struct {
527 self.base.span,527 self.base.span,
528 Inst.VarPtr.Params{ .var_scope = self.params.var_scope },528 Inst.VarPtr.Params{ .var_scope = self.params.var_scope },
529 );529 );
530 const ptr_type = try await (async Type.Pointer.get(ira.irb.comp, Type.Pointer.Key{530 const ptr_type = try Type.Pointer.get(ira.irb.comp, Type.Pointer.Key{
531 .child_type = param.typ,531 .child_type = param.typ,
532 .mut = Type.Pointer.Mut.Const,532 .mut = Type.Pointer.Mut.Const,
533 .vol = Type.Pointer.Vol.Non,533 .vol = Type.Pointer.Vol.Non,
534 .size = Type.Pointer.Size.One,534 .size = Type.Pointer.Size.One,
535 .alignment = Type.Pointer.Align.Abi,535 .alignment = Type.Pointer.Align.Abi,
536 }) catch unreachable);536 });
537 new_inst.val = IrVal{ .KnownType = &ptr_type.base };537 new_inst.val = IrVal{ .KnownType = &ptr_type.base };
538 return new_inst;538 return new_inst;
539 },539 },
...@@ -661,13 +661,13 @@ pub const Inst = struct {...@@ -661,13 +661,13 @@ pub const Inst = struct {
661 } else blk: {661 } else blk: {
662 break :blk Type.Pointer.Align{ .Abi = {} };662 break :blk Type.Pointer.Align{ .Abi = {} };
663 };663 };
664 const ptr_type = try await (async Type.Pointer.get(ira.irb.comp, Type.Pointer.Key{664 const ptr_type = try Type.Pointer.get(ira.irb.comp, Type.Pointer.Key{
665 .child_type = child_type,665 .child_type = child_type,
666 .mut = self.params.mut,666 .mut = self.params.mut,
667 .vol = self.params.vol,667 .vol = self.params.vol,
668 .size = self.params.size,668 .size = self.params.size,
669 .alignment = alignment,669 .alignment = alignment,
670 }) catch unreachable);670 });
671 ptr_type.base.base.deref(ira.irb.comp);671 ptr_type.base.base.deref(ira.irb.comp);
672672
673 return ira.irb.buildConstValue(self.base.scope, self.base.span, &ptr_type.base.base);673 return ira.irb.buildConstValue(self.base.scope, self.base.span, &ptr_type.base.base);
...@@ -1101,7 +1101,7 @@ pub const Builder = struct {...@@ -1101,7 +1101,7 @@ pub const Builder = struct {
1101 ast.Node.PrefixOp.Op.NegationWrap => return error.Unimplemented,1101 ast.Node.PrefixOp.Op.NegationWrap => return error.Unimplemented,
1102 ast.Node.PrefixOp.Op.Resume => return error.Unimplemented,1102 ast.Node.PrefixOp.Op.Resume => return error.Unimplemented,
1103 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {1103 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {
1104 const inst = try await (async irb.genPtrType(prefix_op, ptr_info, scope) catch unreachable);1104 const inst = try irb.genPtrType(prefix_op, ptr_info, scope);
1105 return irb.lvalWrap(scope, inst, lval);1105 return irb.lvalWrap(scope, inst, lval);
1106 },1106 },
1107 ast.Node.PrefixOp.Op.SliceType => |ptr_info| return error.Unimplemented,1107 ast.Node.PrefixOp.Op.SliceType => |ptr_info| return error.Unimplemented,
...@@ -1112,7 +1112,7 @@ pub const Builder = struct {...@@ -1112,7 +1112,7 @@ pub const Builder = struct {
1112 const suffix_op = @fieldParentPtr(ast.Node.SuffixOp, "base", node);1112 const suffix_op = @fieldParentPtr(ast.Node.SuffixOp, "base", node);
1113 switch (suffix_op.op) {1113 switch (suffix_op.op) {
1114 @TagType(ast.Node.SuffixOp.Op).Call => |*call| {1114 @TagType(ast.Node.SuffixOp.Op).Call => |*call| {
1115 const inst = try await (async irb.genCall(suffix_op, call, scope) catch unreachable);1115 const inst = try irb.genCall(suffix_op, call, scope);
1116 return irb.lvalWrap(scope, inst, lval);1116 return irb.lvalWrap(scope, inst, lval);
1117 },1117 },
1118 @TagType(ast.Node.SuffixOp.Op).ArrayAccess => |n| return error.Unimplemented,1118 @TagType(ast.Node.SuffixOp.Op).ArrayAccess => |n| return error.Unimplemented,
...@@ -1129,7 +1129,7 @@ pub const Builder = struct {...@@ -1129,7 +1129,7 @@ pub const Builder = struct {
1129 ast.Node.Id.If => return error.Unimplemented,1129 ast.Node.Id.If => return error.Unimplemented,
1130 ast.Node.Id.ControlFlowExpression => {1130 ast.Node.Id.ControlFlowExpression => {
1131 const control_flow_expr = @fieldParentPtr(ast.Node.ControlFlowExpression, "base", node);1131 const control_flow_expr = @fieldParentPtr(ast.Node.ControlFlowExpression, "base", node);
1132 return await (async irb.genControlFlowExpr(control_flow_expr, scope, lval) catch unreachable);1132 return irb.genControlFlowExpr(control_flow_expr, scope, lval);
1133 },1133 },
1134 ast.Node.Id.Suspend => return error.Unimplemented,1134 ast.Node.Id.Suspend => return error.Unimplemented,
1135 ast.Node.Id.VarType => return error.Unimplemented,1135 ast.Node.Id.VarType => return error.Unimplemented,
...@@ -1143,7 +1143,7 @@ pub const Builder = struct {...@@ -1143,7 +1143,7 @@ pub const Builder = struct {
1143 ast.Node.Id.FloatLiteral => return error.Unimplemented,1143 ast.Node.Id.FloatLiteral => return error.Unimplemented,
1144 ast.Node.Id.StringLiteral => {1144 ast.Node.Id.StringLiteral => {
1145 const str_lit = @fieldParentPtr(ast.Node.StringLiteral, "base", node);1145 const str_lit = @fieldParentPtr(ast.Node.StringLiteral, "base", node);
1146 const inst = try await (async irb.genStrLit(str_lit, scope) catch unreachable);1146 const inst = try irb.genStrLit(str_lit, scope);
1147 return irb.lvalWrap(scope, inst, lval);1147 return irb.lvalWrap(scope, inst, lval);
1148 },1148 },
1149 ast.Node.Id.MultilineStringLiteral => return error.Unimplemented,1149 ast.Node.Id.MultilineStringLiteral => return error.Unimplemented,
...@@ -1154,11 +1154,11 @@ pub const Builder = struct {...@@ -1154,11 +1154,11 @@ pub const Builder = struct {
1154 ast.Node.Id.Unreachable => return error.Unimplemented,1154 ast.Node.Id.Unreachable => return error.Unimplemented,
1155 ast.Node.Id.Identifier => {1155 ast.Node.Id.Identifier => {
1156 const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node);1156 const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node);
1157 return await (async irb.genIdentifier(identifier, scope, lval) catch unreachable);1157 return irb.genIdentifier(identifier, scope, lval);
1158 },1158 },
1159 ast.Node.Id.GroupedExpression => {1159 ast.Node.Id.GroupedExpression => {
1160 const grouped_expr = @fieldParentPtr(ast.Node.GroupedExpression, "base", node);1160 const grouped_expr = @fieldParentPtr(ast.Node.GroupedExpression, "base", node);
1161 return await (async irb.genNode(grouped_expr.expr, scope, lval) catch unreachable);1161 return irb.genNode(grouped_expr.expr, scope, lval);
1162 },1162 },
1163 ast.Node.Id.BuiltinCall => return error.Unimplemented,1163 ast.Node.Id.BuiltinCall => return error.Unimplemented,
1164 ast.Node.Id.ErrorSetDecl => return error.Unimplemented,1164 ast.Node.Id.ErrorSetDecl => return error.Unimplemented,
...@@ -1167,7 +1167,7 @@ pub const Builder = struct {...@@ -1167,7 +1167,7 @@ pub const Builder = struct {
1167 ast.Node.Id.Comptime => return error.Unimplemented,1167 ast.Node.Id.Comptime => return error.Unimplemented,
1168 ast.Node.Id.Block => {1168 ast.Node.Id.Block => {
1169 const block = @fieldParentPtr(ast.Node.Block, "base", node);1169 const block = @fieldParentPtr(ast.Node.Block, "base", node);
1170 const inst = try await (async irb.genBlock(block, scope) catch unreachable);1170 const inst = try irb.genBlock(block, scope);
1171 return irb.lvalWrap(scope, inst, lval);1171 return irb.lvalWrap(scope, inst, lval);
1172 },1172 },
1173 ast.Node.Id.DocComment => return error.Unimplemented,1173 ast.Node.Id.DocComment => return error.Unimplemented,
...@@ -1188,13 +1188,13 @@ pub const Builder = struct {...@@ -1188,13 +1188,13 @@ pub const Builder = struct {
1188 }1188 }
11891189
1190 async fn genCall(irb: *Builder, suffix_op: *ast.Node.SuffixOp, call: *ast.Node.SuffixOp.Op.Call, scope: *Scope) !*Inst {1190 async fn genCall(irb: *Builder, suffix_op: *ast.Node.SuffixOp, call: *ast.Node.SuffixOp.Op.Call, scope: *Scope) !*Inst {
1191 const fn_ref = try await (async irb.genNode(suffix_op.lhs, scope, LVal.None) catch unreachable);1191 const fn_ref = try irb.genNode(suffix_op.lhs, scope, LVal.None);
11921192
1193 const args = try irb.arena().alloc(*Inst, call.params.len);1193 const args = try irb.arena().alloc(*Inst, call.params.len);
1194 var it = call.params.iterator(0);1194 var it = call.params.iterator(0);
1195 var i: usize = 0;1195 var i: usize = 0;
1196 while (it.next()) |arg_node_ptr| : (i += 1) {1196 while (it.next()) |arg_node_ptr| : (i += 1) {
1197 args[i] = try await (async irb.genNode(arg_node_ptr.*, scope, LVal.None) catch unreachable);1197 args[i] = try irb.genNode(arg_node_ptr.*, scope, LVal.None);
1198 }1198 }
11991199
1200 //bool is_async = node->data.fn_call_expr.is_async;1200 //bool is_async = node->data.fn_call_expr.is_async;
...@@ -1239,7 +1239,7 @@ pub const Builder = struct {...@@ -1239,7 +1239,7 @@ pub const Builder = struct {
1239 //} else {1239 //} else {
1240 // align_value = nullptr;1240 // align_value = nullptr;
1241 //}1241 //}
1242 const child_type = try await (async irb.genNode(prefix_op.rhs, scope, LVal.None) catch unreachable);1242 const child_type = try irb.genNode(prefix_op.rhs, scope, LVal.None);
12431243
1244 //uint32_t bit_offset_start = 0;1244 //uint32_t bit_offset_start = 0;
1245 //if (node->data.pointer_type.bit_offset_start != nullptr) {1245 //if (node->data.pointer_type.bit_offset_start != nullptr) {
...@@ -1366,23 +1366,23 @@ pub const Builder = struct {...@@ -1366,23 +1366,23 @@ pub const Builder = struct {
1366 buf[buf.len - 1] = 0;1366 buf[buf.len - 1] = 0;
13671367
1368 // next make an array value1368 // next make an array value
1369 const array_val = try await (async Value.Array.createOwnedBuffer(irb.comp, buf) catch unreachable);1369 const array_val = try Value.Array.createOwnedBuffer(irb.comp, buf);
1370 buf_cleaned = true;1370 buf_cleaned = true;
1371 defer array_val.base.deref(irb.comp);1371 defer array_val.base.deref(irb.comp);
13721372
1373 // then make a pointer value pointing at the first element1373 // then make a pointer value pointing at the first element
1374 const ptr_val = try await (async Value.Ptr.createArrayElemPtr(1374 const ptr_val = try Value.Ptr.createArrayElemPtr(
1375 irb.comp,1375 irb.comp,
1376 array_val,1376 array_val,
1377 Type.Pointer.Mut.Const,1377 Type.Pointer.Mut.Const,
1378 Type.Pointer.Size.Many,1378 Type.Pointer.Size.Many,
1379 0,1379 0,
1380 ) catch unreachable);1380 );
1381 defer ptr_val.base.deref(irb.comp);1381 defer ptr_val.base.deref(irb.comp);
13821382
1383 return irb.buildConstValue(scope, src_span, &ptr_val.base);1383 return irb.buildConstValue(scope, src_span, &ptr_val.base);
1384 } else {1384 } else {
1385 const array_val = try await (async Value.Array.createOwnedBuffer(irb.comp, buf) catch unreachable);1385 const array_val = try Value.Array.createOwnedBuffer(irb.comp, buf);
1386 buf_cleaned = true;1386 buf_cleaned = true;
1387 defer array_val.base.deref(irb.comp);1387 defer array_val.base.deref(irb.comp);
13881388
...@@ -1438,7 +1438,7 @@ pub const Builder = struct {...@@ -1438,7 +1438,7 @@ pub const Builder = struct {
1438 child_scope = &defer_child_scope.base;1438 child_scope = &defer_child_scope.base;
1439 continue;1439 continue;
1440 }1440 }
1441 const statement_value = try await (async irb.genNode(statement_node, child_scope, LVal.None) catch unreachable);1441 const statement_value = try irb.genNode(statement_node, child_scope, LVal.None);
14421442
1443 is_continuation_unreachable = statement_value.isNoReturn();1443 is_continuation_unreachable = statement_value.isNoReturn();
1444 if (is_continuation_unreachable) {1444 if (is_continuation_unreachable) {
...@@ -1481,7 +1481,7 @@ pub const Builder = struct {...@@ -1481,7 +1481,7 @@ pub const Builder = struct {
1481 try block_scope.incoming_values.append(1481 try block_scope.incoming_values.append(
1482 try irb.buildConstVoid(parent_scope, Span.token(block.rbrace), true),1482 try irb.buildConstVoid(parent_scope, Span.token(block.rbrace), true),
1483 );1483 );
1484 _ = try await (async irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit) catch unreachable);1484 _ = try irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit);
14851485
1486 _ = try irb.buildGen(Inst.Br, parent_scope, Span.token(block.rbrace), Inst.Br.Params{1486 _ = try irb.buildGen(Inst.Br, parent_scope, Span.token(block.rbrace), Inst.Br.Params{
1487 .dest_block = block_scope.end_block,1487 .dest_block = block_scope.end_block,
...@@ -1496,7 +1496,7 @@ pub const Builder = struct {...@@ -1496,7 +1496,7 @@ pub const Builder = struct {
1496 });1496 });
1497 }1497 }
14981498
1499 _ = try await (async irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit) catch unreachable);1499 _ = try irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit);
1500 return irb.buildConstVoid(child_scope, Span.token(block.rbrace), true);1500 return irb.buildConstVoid(child_scope, Span.token(block.rbrace), true);
1501 }1501 }
15021502
...@@ -1534,7 +1534,7 @@ pub const Builder = struct {...@@ -1534,7 +1534,7 @@ pub const Builder = struct {
15341534
1535 const outer_scope = irb.begin_scope.?;1535 const outer_scope = irb.begin_scope.?;
1536 const return_value = if (control_flow_expr.rhs) |rhs| blk: {1536 const return_value = if (control_flow_expr.rhs) |rhs| blk: {
1537 break :blk try await (async irb.genNode(rhs, scope, LVal.None) catch unreachable);1537 break :blk try irb.genNode(rhs, scope, LVal.None);
1538 } else blk: {1538 } else blk: {
1539 break :blk try irb.buildConstVoid(scope, src_span, true);1539 break :blk try irb.buildConstVoid(scope, src_span, true);
1540 };1540 };
...@@ -1545,7 +1545,7 @@ pub const Builder = struct {...@@ -1545,7 +1545,7 @@ pub const Builder = struct {
1545 const err_block = try irb.createBasicBlock(scope, c"ErrRetErr");1545 const err_block = try irb.createBasicBlock(scope, c"ErrRetErr");
1546 const ok_block = try irb.createBasicBlock(scope, c"ErrRetOk");1546 const ok_block = try irb.createBasicBlock(scope, c"ErrRetOk");
1547 if (!have_err_defers) {1547 if (!have_err_defers) {
1548 _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable);1548 _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit);
1549 }1549 }
15501550
1551 const is_err = try irb.build(1551 const is_err = try irb.build(
...@@ -1568,7 +1568,7 @@ pub const Builder = struct {...@@ -1568,7 +1568,7 @@ pub const Builder = struct {
15681568
1569 try irb.setCursorAtEndAndAppendBlock(err_block);1569 try irb.setCursorAtEndAndAppendBlock(err_block);
1570 if (have_err_defers) {1570 if (have_err_defers) {
1571 _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ErrorExit) catch unreachable);1571 _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ErrorExit);
1572 }1572 }
1573 if (irb.comp.have_err_ret_tracing and !irb.isCompTime(scope)) {1573 if (irb.comp.have_err_ret_tracing and !irb.isCompTime(scope)) {
1574 _ = try irb.build(Inst.SaveErrRetAddr, scope, src_span, Inst.SaveErrRetAddr.Params{});1574 _ = try irb.build(Inst.SaveErrRetAddr, scope, src_span, Inst.SaveErrRetAddr.Params{});
...@@ -1580,7 +1580,7 @@ pub const Builder = struct {...@@ -1580,7 +1580,7 @@ pub const Builder = struct {
15801580
1581 try irb.setCursorAtEndAndAppendBlock(ok_block);1581 try irb.setCursorAtEndAndAppendBlock(ok_block);
1582 if (have_err_defers) {1582 if (have_err_defers) {
1583 _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable);1583 _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit);
1584 }1584 }
1585 _ = try irb.build(Inst.Br, scope, src_span, Inst.Br.Params{1585 _ = try irb.build(Inst.Br, scope, src_span, Inst.Br.Params{
1586 .dest_block = ret_stmt_block,1586 .dest_block = ret_stmt_block,
...@@ -1590,7 +1590,7 @@ pub const Builder = struct {...@@ -1590,7 +1590,7 @@ pub const Builder = struct {
1590 try irb.setCursorAtEndAndAppendBlock(ret_stmt_block);1590 try irb.setCursorAtEndAndAppendBlock(ret_stmt_block);
1591 return irb.genAsyncReturn(scope, src_span, return_value, false);1591 return irb.genAsyncReturn(scope, src_span, return_value, false);
1592 } else {1592 } else {
1593 _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable);1593 _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit);
1594 return irb.genAsyncReturn(scope, src_span, return_value, false);1594 return irb.genAsyncReturn(scope, src_span, return_value, false);
1595 }1595 }
1596 },1596 },
...@@ -1610,7 +1610,7 @@ pub const Builder = struct {...@@ -1610,7 +1610,7 @@ pub const Builder = struct {
1610 // return &const_instruction->base;1610 // return &const_instruction->base;
1611 //}1611 //}
16121612
1613 if (await (async irb.comp.getPrimitiveType(name) catch unreachable)) |result| {1613 if (irb.comp.getPrimitiveType(name)) |result| {
1614 if (result) |primitive_type| {1614 if (result) |primitive_type| {
1615 defer primitive_type.base.deref(irb.comp);1615 defer primitive_type.base.deref(irb.comp);
1616 switch (lval) {1616 switch (lval) {
...@@ -1628,7 +1628,7 @@ pub const Builder = struct {...@@ -1628,7 +1628,7 @@ pub const Builder = struct {
1628 error.OutOfMemory => return error.OutOfMemory,1628 error.OutOfMemory => return error.OutOfMemory,
1629 }1629 }
16301630
1631 switch (await (async irb.findIdent(scope, name) catch unreachable)) {1631 switch (irb.findIdent(scope, name)) {
1632 Ident.Decl => |decl| {1632 Ident.Decl => |decl| {
1633 return irb.build(Inst.DeclRef, scope, src_span, Inst.DeclRef.Params{1633 return irb.build(Inst.DeclRef, scope, src_span, Inst.DeclRef.Params{
1634 .decl = decl,1634 .decl = decl,
...@@ -1713,11 +1713,11 @@ pub const Builder = struct {...@@ -1713,11 +1713,11 @@ pub const Builder = struct {
1713 };1713 };
1714 if (generate) {1714 if (generate) {
1715 const defer_expr_scope = defer_scope.defer_expr_scope;1715 const defer_expr_scope = defer_scope.defer_expr_scope;
1716 const instruction = try await (async irb.genNode(1716 const instruction = try irb.genNode(
1717 defer_expr_scope.expr_node,1717 defer_expr_scope.expr_node,
1718 &defer_expr_scope.base,1718 &defer_expr_scope.base,
1719 LVal.None,1719 LVal.None,
1720 ) catch unreachable);1720 );
1721 if (instruction.isNoReturn()) {1721 if (instruction.isNoReturn()) {
1722 is_noreturn = true;1722 is_noreturn = true;
1723 } else {1723 } else {
...@@ -1918,7 +1918,7 @@ pub const Builder = struct {...@@ -1918,7 +1918,7 @@ pub const Builder = struct {
1918 Scope.Id.Root => return Ident.NotFound,1918 Scope.Id.Root => return Ident.NotFound,
1919 Scope.Id.Decls => {1919 Scope.Id.Decls => {
1920 const decls = @fieldParentPtr(Scope.Decls, "base", s);1920 const decls = @fieldParentPtr(Scope.Decls, "base", s);
1921 const locked_table = await (async decls.table.acquireRead() catch unreachable);1921 const locked_table = decls.table.acquireRead();
1922 defer locked_table.release();1922 defer locked_table.release();
1923 if (locked_table.value.get(name)) |entry| {1923 if (locked_table.value.get(name)) |entry| {
1924 return Ident{ .Decl = entry.value };1924 return Ident{ .Decl = entry.value };
...@@ -2534,7 +2534,7 @@ pub async fn gen(...@@ -2534,7 +2534,7 @@ pub async fn gen(
2534 entry_block.ref(&irb); // Entry block gets a reference because we enter it to begin.2534 entry_block.ref(&irb); // Entry block gets a reference because we enter it to begin.
2535 try irb.setCursorAtEndAndAppendBlock(entry_block);2535 try irb.setCursorAtEndAndAppendBlock(entry_block);
25362536
2537 const result = try await (async irb.genNode(body_node, scope, LVal.None) catch unreachable);2537 const result = try irb.genNode(body_node, scope, LVal.None);
2538 if (!result.isNoReturn()) {2538 if (!result.isNoReturn()) {
2539 // no need for save_err_ret_addr because this cannot return error2539 // no need for save_err_ret_addr because this cannot return error
2540 _ = try irb.genAsyncReturn(scope, Span.token(body_node.lastToken()), result, true);2540 _ = try irb.genAsyncReturn(scope, Span.token(body_node.lastToken()), result, true);
...@@ -2564,7 +2564,7 @@ pub async fn analyze(comp: *Compilation, old_code: *Code, expected_type: ?*Type)...@@ -2564,7 +2564,7 @@ pub async fn analyze(comp: *Compilation, old_code: *Code, expected_type: ?*Type)
2564 continue;2564 continue;
2565 }2565 }
25662566
2567 const return_inst = try await (async old_instruction.analyze(&ira) catch unreachable);2567 const return_inst = try old_instruction.analyze(&ira);
2568 assert(return_inst.val != IrVal.Unknown); // at least the type should be known at this point2568 assert(return_inst.val != IrVal.Unknown); // at least the type should be known at this point
2569 return_inst.linkToParent(old_instruction);2569 return_inst.linkToParent(old_instruction);
2570 // Note: if we ever modify the above to handle error.CompileError by continuing analysis,2570 // Note: if we ever modify the above to handle error.CompileError by continuing analysis,
src-self-hosted/libc_installation.zig+6-6
...@@ -178,7 +178,7 @@ pub const LibCInstallation = struct {...@@ -178,7 +178,7 @@ pub const LibCInstallation = struct {
178 },178 },
179 else => @compileError("unimplemented: find libc for this OS"),179 else => @compileError("unimplemented: find libc for this OS"),
180 }180 }
181 return await (async group.wait() catch unreachable);181 return group.wait();
182 }182 }
183183
184 async fn findNativeIncludeDirLinux(self: *LibCInstallation, loop: *event.Loop) !void {184 async fn findNativeIncludeDirLinux(self: *LibCInstallation, loop: *event.Loop) !void {
...@@ -301,11 +301,11 @@ pub const LibCInstallation = struct {...@@ -301,11 +301,11 @@ pub const LibCInstallation = struct {
301 }301 }
302302
303 async fn findNativeLibDirLinux(self: *LibCInstallation, loop: *event.Loop) FindError!void {303 async fn findNativeLibDirLinux(self: *LibCInstallation, loop: *event.Loop) FindError!void {
304 self.lib_dir = try await (async ccPrintFileName(loop, "crt1.o", true) catch unreachable);304 self.lib_dir = try ccPrintFileName(loop, "crt1.o", true);
305 }305 }
306306
307 async fn findNativeStaticLibDir(self: *LibCInstallation, loop: *event.Loop) FindError!void {307 async fn findNativeStaticLibDir(self: *LibCInstallation, loop: *event.Loop) FindError!void {
308 self.static_lib_dir = try await (async ccPrintFileName(loop, "crtbegin.o", true) catch unreachable);308 self.static_lib_dir = try ccPrintFileName(loop, "crtbegin.o", true);
309 }309 }
310310
311 async fn findNativeDynamicLinker(self: *LibCInstallation, loop: *event.Loop) FindError!void {311 async fn findNativeDynamicLinker(self: *LibCInstallation, loop: *event.Loop) FindError!void {
...@@ -324,7 +324,7 @@ pub const LibCInstallation = struct {...@@ -324,7 +324,7 @@ pub const LibCInstallation = struct {
324 for (dyn_tests) |*dyn_test| {324 for (dyn_tests) |*dyn_test| {
325 try group.call(testNativeDynamicLinker, self, loop, dyn_test);325 try group.call(testNativeDynamicLinker, self, loop, dyn_test);
326 }326 }
327 try await (async group.wait() catch unreachable);327 try group.wait();
328 for (dyn_tests) |*dyn_test| {328 for (dyn_tests) |*dyn_test| {
329 if (dyn_test.result) |result| {329 if (dyn_test.result) |result| {
330 self.dynamic_linker_path = result;330 self.dynamic_linker_path = result;
...@@ -339,7 +339,7 @@ pub const LibCInstallation = struct {...@@ -339,7 +339,7 @@ pub const LibCInstallation = struct {
339 };339 };
340340
341 async fn testNativeDynamicLinker(self: *LibCInstallation, loop: *event.Loop, dyn_test: *DynTest) FindError!void {341 async fn testNativeDynamicLinker(self: *LibCInstallation, loop: *event.Loop, dyn_test: *DynTest) FindError!void {
342 if (await (async ccPrintFileName(loop, dyn_test.name, false) catch unreachable)) |result| {342 if (ccPrintFileName(loop, dyn_test.name, false)) |result| {
343 dyn_test.result = result;343 dyn_test.result = result;
344 return;344 return;
345 } else |err| switch (err) {345 } else |err| switch (err) {
...@@ -398,7 +398,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo...@@ -398,7 +398,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo
398 const argv = [_][]const u8{ cc_exe, arg1 };398 const argv = [_][]const u8{ cc_exe, arg1 };
399399
400 // TODO This simulates evented I/O for the child process exec400 // TODO This simulates evented I/O for the child process exec
401 await (async loop.yield() catch unreachable);401 loop.yield();
402 const errorable_result = std.ChildProcess.exec(loop.allocator, argv, null, null, 1024 * 1024);402 const errorable_result = std.ChildProcess.exec(loop.allocator, argv, null, null, 1024 * 1024);
403 const exec_result = if (std.debug.runtime_safety) blk: {403 const exec_result = if (std.debug.runtime_safety) blk: {
404 break :blk errorable_result catch unreachable;404 break :blk errorable_result catch unreachable;
src-self-hosted/link.zig+2-2
...@@ -61,7 +61,7 @@ pub async fn link(comp: *Compilation) !void {...@@ -61,7 +61,7 @@ pub async fn link(comp: *Compilation) !void {
61 ctx.libc = ctx.comp.override_libc orelse blk: {61 ctx.libc = ctx.comp.override_libc orelse blk: {
62 switch (comp.target) {62 switch (comp.target) {
63 Target.Native => {63 Target.Native => {
64 break :blk (await (async comp.zig_compiler.getNativeLibC() catch unreachable)) catch return error.LibCRequiredButNotProvidedOrFound;64 break :blk comp.zig_compiler.getNativeLibC() catch return error.LibCRequiredButNotProvidedOrFound;
65 },65 },
66 else => return error.LibCRequiredButNotProvidedOrFound,66 else => return error.LibCRequiredButNotProvidedOrFound,
67 }67 }
...@@ -83,7 +83,7 @@ pub async fn link(comp: *Compilation) !void {...@@ -83,7 +83,7 @@ pub async fn link(comp: *Compilation) !void {
8383
84 {84 {
85 // LLD is not thread-safe, so we grab a global lock.85 // LLD is not thread-safe, so we grab a global lock.
86 const held = await (async comp.zig_compiler.lld_lock.acquire() catch unreachable);86 const held = comp.zig_compiler.lld_lock.acquire();
87 defer held.release();87 defer held.release();
8888
89 // Not evented I/O. LLD does its own multithreading internally.89 // Not evented I/O. LLD does its own multithreading internally.
src-self-hosted/main.zig+12-28
...@@ -466,7 +466,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -466,7 +466,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
466 comp.link_objects = link_objects;466 comp.link_objects = link_objects;
467467
468 comp.start();468 comp.start();
469 // TODO const process_build_events_handle = try async<loop.allocator> processBuildEvents(comp, color);469 const frame = try async processBuildEvents(comp, color);
470 loop.run();470 loop.run();
471}471}
472472
...@@ -474,7 +474,7 @@ async fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {...@@ -474,7 +474,7 @@ async fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
474 var count: usize = 0;474 var count: usize = 0;
475 while (true) {475 while (true) {
476 // TODO directly awaiting async should guarantee memory allocation elision476 // TODO directly awaiting async should guarantee memory allocation elision
477 const build_event = await (async comp.events.get() catch unreachable);477 const build_event = comp.events.get();
478 count += 1;478 count += 1;
479479
480 switch (build_event) {480 switch (build_event) {
...@@ -577,13 +577,13 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -577,13 +577,13 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
577 var zig_compiler = try ZigCompiler.init(&loop);577 var zig_compiler = try ZigCompiler.init(&loop);
578 defer zig_compiler.deinit();578 defer zig_compiler.deinit();
579579
580 // TODO const handle = try async<loop.allocator> findLibCAsync(&zig_compiler);580 const frame = async findLibCAsync(&zig_compiler);
581581
582 loop.run();582 loop.run();
583}583}
584584
585async fn findLibCAsync(zig_compiler: *ZigCompiler) void {585async fn findLibCAsync(zig_compiler: *ZigCompiler) void {
586 const libc = (await (async zig_compiler.getNativeLibC() catch unreachable)) catch |err| {586 const libc = zig_compiler.getNativeLibC() catch |err| {
587 stderr.print("unable to find libc: {}\n", @errorName(err)) catch process.exit(1);587 stderr.print("unable to find libc: {}\n", @errorName(err)) catch process.exit(1);
588 process.exit(1);588 process.exit(1);
589 };589 };
...@@ -660,24 +660,11 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -660,24 +660,11 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
660 try loop.initMultiThreaded(allocator);660 try loop.initMultiThreaded(allocator);
661 defer loop.deinit();661 defer loop.deinit();
662662
663 var result: FmtError!void = undefined;663 return asyncFmtMain(
664 // TODO const main_handle = try async<allocator> asyncFmtMainChecked(664 &flags,
665 // TODO &result,665 color,
666 // TODO &loop,666 );
667 // TODO &flags,667 // loop.run();
668 // TODO color,
669 // TODO );
670 loop.run();
671 return result;
672}
673
674async fn asyncFmtMainChecked(
675 result: *(FmtError!void),
676 loop: *event.Loop,
677 flags: *const Args,
678 color: errmsg.Color,
679) void {
680 result.* = await (async asyncFmtMain(loop, flags, color) catch unreachable);
681}668}
682669
683const FmtError = error{670const FmtError = error{
...@@ -707,9 +694,6 @@ async fn asyncFmtMain(...@@ -707,9 +694,6 @@ async fn asyncFmtMain(
707 flags: *const Args,694 flags: *const Args,
708 color: errmsg.Color,695 color: errmsg.Color,
709) FmtError!void {696) FmtError!void {
710 suspend {
711 resume @handle();
712 }
713 var fmt = Fmt{697 var fmt = Fmt{
714 .seen = event.Locked(Fmt.SeenMap).init(loop, Fmt.SeenMap.init(loop.allocator)),698 .seen = event.Locked(Fmt.SeenMap).init(loop, Fmt.SeenMap.init(loop.allocator)),
715 .any_error = false,699 .any_error = false,
...@@ -723,7 +707,7 @@ async fn asyncFmtMain(...@@ -723,7 +707,7 @@ async fn asyncFmtMain(
723 for (flags.positionals.toSliceConst()) |file_path| {707 for (flags.positionals.toSliceConst()) |file_path| {
724 try group.call(fmtPath, &fmt, file_path, check_mode);708 try group.call(fmtPath, &fmt, file_path, check_mode);
725 }709 }
726 try await (async group.wait() catch unreachable);710 try group.wait();
727 if (fmt.any_error) {711 if (fmt.any_error) {
728 process.exit(1);712 process.exit(1);
729 }713 }
...@@ -734,7 +718,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -734,7 +718,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
734 defer fmt.loop.allocator.free(file_path);718 defer fmt.loop.allocator.free(file_path);
735719
736 {720 {
737 const held = await (async fmt.seen.acquire() catch unreachable);721 const held = fmt.seen.acquire();
738 defer held.release();722 defer held.release();
739723
740 if (try held.value.put(file_path, {})) |_| return;724 if (try held.value.put(file_path, {})) |_| return;
...@@ -757,7 +741,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -757,7 +741,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
757 try group.call(fmtPath, fmt, full_path, check_mode);741 try group.call(fmtPath, fmt, full_path, check_mode);
758 }742 }
759 }743 }
760 return await (async group.wait() catch unreachable);744 return group.wait();
761 },745 },
762 else => {746 else => {
763 // TODO lock stderr printing747 // TODO lock stderr printing
src-self-hosted/test.zig+4-4
...@@ -68,13 +68,13 @@ pub const TestContext = struct {...@@ -68,13 +68,13 @@ pub const TestContext = struct {
6868
69 fn run(self: *TestContext) !void {69 fn run(self: *TestContext) !void {
70 const handle = try self.loop.call(waitForGroup, self);70 const handle = try self.loop.call(waitForGroup, self);
71 defer cancel handle;71 defer await handle;
72 self.loop.run();72 self.loop.run();
73 return self.any_err;73 return self.any_err;
74 }74 }
7575
76 async fn waitForGroup(self: *TestContext) void {76 async fn waitForGroup(self: *TestContext) void {
77 self.any_err = await (async self.group.wait() catch unreachable);77 self.any_err = self.group.wait();
78 }78 }
7979
80 fn testCompileError(80 fn testCompileError(
...@@ -158,7 +158,7 @@ pub const TestContext = struct {...@@ -158,7 +158,7 @@ pub const TestContext = struct {
158 const exe_file_2 = try std.mem.dupe(allocator, u8, exe_file);158 const exe_file_2 = try std.mem.dupe(allocator, u8, exe_file);
159159
160 defer comp.destroy();160 defer comp.destroy();
161 const build_event = await (async comp.events.get() catch unreachable);161 const build_event = comp.events.get();
162162
163 switch (build_event) {163 switch (build_event) {
164 Compilation.Event.Ok => {164 Compilation.Event.Ok => {
...@@ -200,7 +200,7 @@ pub const TestContext = struct {...@@ -200,7 +200,7 @@ pub const TestContext = struct {
200 text: []const u8,200 text: []const u8,
201 ) !void {201 ) !void {
202 defer comp.destroy();202 defer comp.destroy();
203 const build_event = await (async comp.events.get() catch unreachable);203 const build_event = comp.events.get();
204204
205 switch (build_event) {205 switch (build_event) {
206 Compilation.Event.Ok => {206 Compilation.Event.Ok => {
src-self-hosted/type.zig+18-25
...@@ -181,7 +181,7 @@ pub const Type = struct {...@@ -181,7 +181,7 @@ pub const Type = struct {
181 /// If you happen to have an llvm context handy, use getAbiAlignmentInContext instead.181 /// If you happen to have an llvm context handy, use getAbiAlignmentInContext instead.
182 /// Otherwise, this one will grab one from the pool and then release it.182 /// Otherwise, this one will grab one from the pool and then release it.
183 pub async fn getAbiAlignment(base: *Type, comp: *Compilation) !u32 {183 pub async fn getAbiAlignment(base: *Type, comp: *Compilation) !u32 {
184 if (await (async base.abi_alignment.start() catch unreachable)) |ptr| return ptr.*;184 if (base.abi_alignment.start()) |ptr| return ptr.*;
185185
186 {186 {
187 const held = try comp.zig_compiler.getAnyLlvmContext();187 const held = try comp.zig_compiler.getAnyLlvmContext();
...@@ -189,7 +189,7 @@ pub const Type = struct {...@@ -189,7 +189,7 @@ pub const Type = struct {
189189
190 const llvm_context = held.node.data;190 const llvm_context = held.node.data;
191191
192 base.abi_alignment.data = await (async base.resolveAbiAlignment(comp, llvm_context) catch unreachable);192 base.abi_alignment.data = base.resolveAbiAlignment(comp, llvm_context);
193 }193 }
194 base.abi_alignment.resolve();194 base.abi_alignment.resolve();
195 return base.abi_alignment.data;195 return base.abi_alignment.data;
...@@ -197,9 +197,9 @@ pub const Type = struct {...@@ -197,9 +197,9 @@ pub const Type = struct {
197197
198 /// If you have an llvm conext handy, you can use it here.198 /// If you have an llvm conext handy, you can use it here.
199 pub async fn getAbiAlignmentInContext(base: *Type, comp: *Compilation, llvm_context: *llvm.Context) !u32 {199 pub async fn getAbiAlignmentInContext(base: *Type, comp: *Compilation, llvm_context: *llvm.Context) !u32 {
200 if (await (async base.abi_alignment.start() catch unreachable)) |ptr| return ptr.*;200 if (base.abi_alignment.start()) |ptr| return ptr.*;
201201
202 base.abi_alignment.data = await (async base.resolveAbiAlignment(comp, llvm_context) catch unreachable);202 base.abi_alignment.data = base.resolveAbiAlignment(comp, llvm_context);
203 base.abi_alignment.resolve();203 base.abi_alignment.resolve();
204 return base.abi_alignment.data;204 return base.abi_alignment.data;
205 }205 }
...@@ -401,7 +401,7 @@ pub const Type = struct {...@@ -401,7 +401,7 @@ pub const Type = struct {
401 /// takes ownership of key.Normal.params on success401 /// takes ownership of key.Normal.params on success
402 pub async fn get(comp: *Compilation, key: Key) !*Fn {402 pub async fn get(comp: *Compilation, key: Key) !*Fn {
403 {403 {
404 const held = await (async comp.fn_type_table.acquire() catch unreachable);404 const held = comp.fn_type_table.acquire();
405 defer held.release();405 defer held.release();
406406
407 if (held.value.get(&key)) |entry| {407 if (held.value.get(&key)) |entry| {
...@@ -430,15 +430,8 @@ pub const Type = struct {...@@ -430,15 +430,8 @@ pub const Type = struct {
430 switch (key.data) {430 switch (key.data) {
431 Kind.Generic => |generic| {431 Kind.Generic => |generic| {
432 self.non_key = NonKey{ .Generic = {} };432 self.non_key = NonKey{ .Generic = {} };
433 switch (generic.cc) {433 const cc_str = ccFnTypeStr(generic.cc);
434 CallingConvention.Async => |async_allocator_type| {434 try name_stream.write(cc_str);
435 try name_stream.print("async<{}> ", async_allocator_type.name);
436 },
437 else => {
438 const cc_str = ccFnTypeStr(generic.cc);
439 try name_stream.write(cc_str);
440 },
441 }
442 try name_stream.write("fn(");435 try name_stream.write("fn(");
443 var param_i: usize = 0;436 var param_i: usize = 0;
444 while (param_i < generic.param_count) : (param_i += 1) {437 while (param_i < generic.param_count) : (param_i += 1) {
...@@ -477,7 +470,7 @@ pub const Type = struct {...@@ -477,7 +470,7 @@ pub const Type = struct {
477 self.base.init(comp, Id.Fn, name_buf.toOwnedSlice());470 self.base.init(comp, Id.Fn, name_buf.toOwnedSlice());
478471
479 {472 {
480 const held = await (async comp.fn_type_table.acquire() catch unreachable);473 const held = comp.fn_type_table.acquire();
481 defer held.release();474 defer held.release();
482475
483 _ = try held.value.put(&self.key, self);476 _ = try held.value.put(&self.key, self);
...@@ -606,7 +599,7 @@ pub const Type = struct {...@@ -606,7 +599,7 @@ pub const Type = struct {
606599
607 pub async fn get(comp: *Compilation, key: Key) !*Int {600 pub async fn get(comp: *Compilation, key: Key) !*Int {
608 {601 {
609 const held = await (async comp.int_type_table.acquire() catch unreachable);602 const held = comp.int_type_table.acquire();
610 defer held.release();603 defer held.release();
611604
612 if (held.value.get(&key)) |entry| {605 if (held.value.get(&key)) |entry| {
...@@ -630,7 +623,7 @@ pub const Type = struct {...@@ -630,7 +623,7 @@ pub const Type = struct {
630 self.base.init(comp, Id.Int, name);623 self.base.init(comp, Id.Int, name);
631624
632 {625 {
633 const held = await (async comp.int_type_table.acquire() catch unreachable);626 const held = comp.int_type_table.acquire();
634 defer held.release();627 defer held.release();
635628
636 _ = try held.value.put(&self.key, self);629 _ = try held.value.put(&self.key, self);
...@@ -648,7 +641,7 @@ pub const Type = struct {...@@ -648,7 +641,7 @@ pub const Type = struct {
648641
649 pub async fn gcDestroy(self: *Int, comp: *Compilation) void {642 pub async fn gcDestroy(self: *Int, comp: *Compilation) void {
650 {643 {
651 const held = await (async comp.int_type_table.acquire() catch unreachable);644 const held = comp.int_type_table.acquire();
652 defer held.release();645 defer held.release();
653646
654 _ = held.value.remove(&self.key).?;647 _ = held.value.remove(&self.key).?;
...@@ -742,7 +735,7 @@ pub const Type = struct {...@@ -742,7 +735,7 @@ pub const Type = struct {
742735
743 pub async fn gcDestroy(self: *Pointer, comp: *Compilation) void {736 pub async fn gcDestroy(self: *Pointer, comp: *Compilation) void {
744 {737 {
745 const held = await (async comp.ptr_type_table.acquire() catch unreachable);738 const held = comp.ptr_type_table.acquire();
746 defer held.release();739 defer held.release();
747740
748 _ = held.value.remove(&self.key).?;741 _ = held.value.remove(&self.key).?;
...@@ -753,7 +746,7 @@ pub const Type = struct {...@@ -753,7 +746,7 @@ pub const Type = struct {
753746
754 pub async fn getAlignAsInt(self: *Pointer, comp: *Compilation) u32 {747 pub async fn getAlignAsInt(self: *Pointer, comp: *Compilation) u32 {
755 switch (self.key.alignment) {748 switch (self.key.alignment) {
756 Align.Abi => return await (async self.key.child_type.getAbiAlignment(comp) catch unreachable),749 Align.Abi => return self.key.child_type.getAbiAlignment(comp),
757 Align.Override => |alignment| return alignment,750 Align.Override => |alignment| return alignment,
758 }751 }
759 }752 }
...@@ -766,14 +759,14 @@ pub const Type = struct {...@@ -766,14 +759,14 @@ pub const Type = struct {
766 switch (key.alignment) {759 switch (key.alignment) {
767 Align.Abi => {},760 Align.Abi => {},
768 Align.Override => |alignment| {761 Align.Override => |alignment| {
769 const abi_align = try await (async key.child_type.getAbiAlignment(comp) catch unreachable);762 const abi_align = try key.child_type.getAbiAlignment(comp);
770 if (abi_align == alignment) {763 if (abi_align == alignment) {
771 normal_key.alignment = Align.Abi;764 normal_key.alignment = Align.Abi;
772 }765 }
773 },766 },
774 }767 }
775 {768 {
776 const held = await (async comp.ptr_type_table.acquire() catch unreachable);769 const held = comp.ptr_type_table.acquire();
777 defer held.release();770 defer held.release();
778771
779 if (held.value.get(&normal_key)) |entry| {772 if (held.value.get(&normal_key)) |entry| {
...@@ -828,7 +821,7 @@ pub const Type = struct {...@@ -828,7 +821,7 @@ pub const Type = struct {
828 self.base.init(comp, Id.Pointer, name);821 self.base.init(comp, Id.Pointer, name);
829822
830 {823 {
831 const held = await (async comp.ptr_type_table.acquire() catch unreachable);824 const held = comp.ptr_type_table.acquire();
832 defer held.release();825 defer held.release();
833826
834 _ = try held.value.put(&self.key, self);827 _ = try held.value.put(&self.key, self);
...@@ -873,7 +866,7 @@ pub const Type = struct {...@@ -873,7 +866,7 @@ pub const Type = struct {
873 errdefer key.elem_type.base.deref(comp);866 errdefer key.elem_type.base.deref(comp);
874867
875 {868 {
876 const held = await (async comp.array_type_table.acquire() catch unreachable);869 const held = comp.array_type_table.acquire();
877 defer held.release();870 defer held.release();
878871
879 if (held.value.get(&key)) |entry| {872 if (held.value.get(&key)) |entry| {
...@@ -896,7 +889,7 @@ pub const Type = struct {...@@ -896,7 +889,7 @@ pub const Type = struct {
896 self.base.init(comp, Id.Array, name);889 self.base.init(comp, Id.Array, name);
897890
898 {891 {
899 const held = await (async comp.array_type_table.acquire() catch unreachable);892 const held = comp.array_type_table.acquire();
900 defer held.release();893 defer held.release();
901894
902 _ = try held.value.put(&self.key, self);895 _ = try held.value.put(&self.key, self);
src-self-hosted/value.zig+4-4
...@@ -346,13 +346,13 @@ pub const Value = struct {...@@ -346,13 +346,13 @@ pub const Value = struct {
346 errdefer array_val.base.deref(comp);346 errdefer array_val.base.deref(comp);
347347
348 const elem_type = array_val.base.typ.cast(Type.Array).?.key.elem_type;348 const elem_type = array_val.base.typ.cast(Type.Array).?.key.elem_type;
349 const ptr_type = try await (async Type.Pointer.get(comp, Type.Pointer.Key{349 const ptr_type = try Type.Pointer.get(comp, Type.Pointer.Key{
350 .child_type = elem_type,350 .child_type = elem_type,
351 .mut = mut,351 .mut = mut,
352 .vol = Type.Pointer.Vol.Non,352 .vol = Type.Pointer.Vol.Non,
353 .size = size,353 .size = size,
354 .alignment = Type.Pointer.Align.Abi,354 .alignment = Type.Pointer.Align.Abi,
355 }) catch unreachable);355 });
356 var ptr_type_consumed = false;356 var ptr_type_consumed = false;
357 errdefer if (!ptr_type_consumed) ptr_type.base.base.deref(comp);357 errdefer if (!ptr_type_consumed) ptr_type.base.base.deref(comp);
358358
...@@ -428,10 +428,10 @@ pub const Value = struct {...@@ -428,10 +428,10 @@ pub const Value = struct {
428 const u8_type = Type.Int.get_u8(comp);428 const u8_type = Type.Int.get_u8(comp);
429 defer u8_type.base.base.deref(comp);429 defer u8_type.base.base.deref(comp);
430430
431 const array_type = try await (async Type.Array.get(comp, Type.Array.Key{431 const array_type = try Type.Array.get(comp, Type.Array.Key{
432 .elem_type = &u8_type.base,432 .elem_type = &u8_type.base,
433 .len = buffer.len,433 .len = buffer.len,
434 }) catch unreachable);434 });
435 errdefer array_type.base.base.deref(comp);435 errdefer array_type.base.base.deref(comp);
436436
437 const self = try comp.gpa().create(Value.Array);437 const self = try comp.gpa().create(Value.Array);