From d6dec8026192503a8d64587063b2dc10b14df665 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 31 Oct 2019 14:21:04 -0400 Subject: [PATCH] startup code respects root source file's event_loop if present --- lib/std/special/start.zig | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/std/special/start.zig b/lib/std/special/start.zig index cdf09606a9..7738c00d1a 100644 --- a/lib/std/special/start.zig +++ b/lib/std/special/start.zig @@ -191,25 +191,27 @@ const bad_main_ret = "expected return type of main to be 'void', '!void', 'noret // and we want fewer call frames in stack traces. inline fn initEventLoopAndCallMain() u8 { if (std.event.Loop.instance) |loop| { - loop.init() catch |err| { - std.debug.warn("error: {}\n", @errorName(err)); - if (@errorReturnTrace()) |trace| { - std.debug.dumpStackTrace(trace.*); - } - return 1; - }; - defer loop.deinit(); + if (!@hasDecl(root, "event_loop")) { + loop.init() catch |err| { + std.debug.warn("error: {}\n", @errorName(err)); + if (@errorReturnTrace()) |trace| { + std.debug.dumpStackTrace(trace.*); + } + return 1; + }; + defer loop.deinit(); - var result: u8 = undefined; - var frame: @Frame(callMain) = undefined; - _ = @asyncCall(&frame, &result, callMain); - loop.run(); - return result; - } else { - // This is marked inline because for some reason LLVM in release mode fails to inline it, - // and we want fewer call frames in stack traces. - return @inlineCall(callMain); + var result: u8 = undefined; + var frame: @Frame(callMain) = undefined; + _ = @asyncCall(&frame, &result, callMain); + loop.run(); + return result; + } } + + // This is marked inline because for some reason LLVM in release mode fails to inline it, + // and we want fewer call frames in stack traces. + return @inlineCall(callMain); } // This is not marked inline because it is called with @asyncCall when