Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler error when using async and WASM #7995

Open
leroycep opened this issue Feb 11, 2021 · 2 comments
Open

Compiler error when using async and WASM #7995

leroycep opened this issue Feb 11, 2021 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@leroycep
Copy link
Contributor

I'm trying to build a asset loading system using async for WASM, but I'm getting an internal compiler error:

$ ~/Downloads/zig/0.8.0-dev.1120/zig build wasm
broken LLVM module found: Stored value type does not match pointer operand type!
  store %"[]u8"* %27, { %"[]u8", i16 }** %28, align 4
 { %"[]u8", i16 }*Stored value type does not match pointer operand type!
  store %"[]u8"* %36, { %"[]u8", i16 }** %37, align 4
 { %"[]u8", i16 }*
This is a bug in the Zig compiler.thread 1345860 panic:
Unable to dump stack trace: debug info stripped

The code is here: https://github.com/leroycep/zig-wasm-assets/tree/zig-compiler-crash

On the master branch there is a version that works. It works by storing the main task in a global variable, and then relying on the JS runtime to resume once the fetch tasks are complete. https://github.com/leroycep/zig-wasm-assets/blob/master/src/main.zig

@kivikakk
Copy link
Contributor

I worked out what the root cause was. It's these lines here:

fn load_text_files() void {
    var hello_fetch = async env.fetch("hello.txt");
    var world_fetch = async env.fetch("world.txt");

    text_files_opt = TextFiles{
        .hello = await hello_fetch,
        .world = await world_fetch,
    };
}

Note env.fetch's signature:

pub fn fetch(file_name: []const u8) ![]const u8 {

await hello_fetch returns a ![]const u8, but here we try to assign it to struct fields of type []const u8.

This fixes the compile panic:

     text_files_opt = TextFiles{
-        .hello = await hello_fetch,
-        .world = await world_fetch,
+        .hello = try await hello_fetch,
+        .world = try await world_fetch,
     };

The asyncness is causing our type checker to not catch this before it gets to LLVM, I guess.

@leroycep
Copy link
Contributor Author

Oh, I feel silly now. Thanks for finding what makes the compiler panic!

@SpexGuy SpexGuy added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Mar 16, 2021
@Vexu Vexu added this to the 0.9.0 milestone Mar 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@Vexu Vexu removed the stage1 The process of building from source via WebAssembly and the C backend. label Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

5 participants