ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.67k stars 2.47k forks source link

broken LLVM module when directly awaiting a certain @asyncCall #5509

Open courajs opened 4 years ago

courajs commented 4 years ago

Sorry for the large example, I had trouble reducing it: https://gist.github.com/courajs/7815091c46d94cb9585f25832da4487c

broken LLVM module found: Instruction does not dominate all uses!
  %10 = getelementptr inbounds %"RunningGenerator(u8,u8,u8)", %"RunningGenerator(u8,u8,u8)"* %9, i32 0, i32 3, !dbg !2213
  %33 = getelementptr inbounds %"[]u8", %"[]u8"* %10, i32 0, i32 0, !dbg !2216
Instruction does not dominate all uses!
  %40 = getelementptr inbounds %"RunningGenerator(u8,u8,u8)", %"RunningGenerator(u8,u8,u8)"* %39, i32 0, i32 3, !dbg !2220
  %64 = getelementptr inbounds %"[]u8", %"[]u8"* %40, i32 0, i32 0, !dbg !2224

This is a bug in the Zig compiler.
Unable to dump stack trace: debug info stripped
generators...The following command terminated unexpectedly:
/usr/local/Cellar/zig/0.6.0_1/bin/zig build-exe /Users/aaron/dev/zig/generators/src/main.zig --cache-dir /Users/aaron/dev/zig/generators/zig-cache --name generators --cache on

Build failed. The following command failed:
/Users/aaron/dev/zig/generators/zig-cache/o/oMByx-gNppEQTgYvwtZpRnNUX5q_awT1z3mpznAuuVyXAfkub9BPM46rvNJGkAU0/build /usr/local/Cellar/zig/0.6.0_1/bin/zig /Users/aaron/dev/zig/generators /Users/aaron/dev/zig/generators/zig-cache run

shell returned 6

If you change lines 106 & 108 to store the return of @asyncCall in a variable, it works as expected:

var n = await @asyncCall(target.yield_frame, {}, yield, target, 0);

->

var f = @asyncCall(target.yield_frame, {}, yield, target, 0);
var n = await f;
courajs commented 4 years ago

Ah - I ran this against master and now get a compile error. Has async fn type syntax been removed?

🚀 generators$ /Users/aaron/Downloads/zig-macos-x86_64-0.6.0+c6764fd25/zig build run
./src/main.zig:104:98: error: invalid token: ')'
fn thing(target: *RunningGenerator(u8,u8,u8), yield: async fn(*RunningGenerator(u8,u8,u8), u8) u8) u8 {
                                                                                                 ^
generators...The following command exited with error code 1:
/Users/aaron/Downloads/zig-macos-x86_64-0.6.0+c6764fd25/zig build-exe /Users/aaron/dev/zig/generators/src/main.zig --cache-dir /Users/aaron/dev/zig/generators/zig-cache --name generators --cache on

Build failed. The following command failed:
/Users/aaron/dev/zig/generators/zig-cache/o/cU0PoSBcKL1sr6QtX5H4agcHEObF6D5SjwC5esYol3WK9_1FKLHWZni1yXbTaZD0/build /Users/aaron/Downloads/zig-macos-x86_64-0.6.0+c6764fd25/zig /Users/aaron/dev/zig/generators /Users/aaron/dev/zig/generators/zig-cache run
Vexu commented 4 years ago

async fn() void was changed to fn() callconv(.Async) void.

courajs commented 4 years ago

Ah... yes (https://github.com/ziglang/zig/pull/5253). Updated the gist to use callconv, and now get the same broken module on master.