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

Stage2: wasm - Implement 'zig test' #10240

Merged
merged 5 commits into from Nov 29, 2021

Conversation

Luukdegram
Copy link
Sponsor Member

This implements all the required instructions and declaration codegen to be able to use zig test using wasm32-wasi as a target.

A simple example:

// test.zig
test {
    var i: u32 = 5;
    if (i != 5) unreachable;
}
zig test test.zig -target wasm32-wasi --test-cmd wasmtime --test-cmd-bin
0

The temporary _start supports both u8 and void as return type, to also support our old wasm stage2 testing backend. In a followup PR I'll be updating the behaviour.zig file to track progress on the wasm backend.
This is a huge milestone for the wasm backend and the backend is now in a state where contributing
is a lot easier.

The function table contains all function pointers that are called
by using call_indirect. During codegen, we create a relocation
where the linker will resolve the correct index into the table and stores
this value within the data section at the location of the pointer.
- This implements the required codegen for decl types such as pointers, arrays, structs and more.
- Wasm's start function can now use both a 'u8' and 'void' as return type. This will help us with writing tests
using the stage2 testing backend. (Until all tests of behavioural tests pass).
- Now correctly generates relocations for function pointers.
- Also implements unwrapping error union error, as well as return pointers.
@Luukdegram
Copy link
Sponsor Member Author

Errors seem related to my PR. Though, not sure yet what's causing the change of behavior in the Darwin tests.

@kubkon
Copy link
Member

kubkon commented Nov 28, 2021

Errors seem related to my PR. Though, not sure yet what's causing the change of behavior in the Darwin tests.

How do you know it's darwin specifically? It may well be wasm tests cross-compiled on darwin too.

@Luukdegram
Copy link
Sponsor Member Author

Luukdegram commented Nov 28, 2021

Errors seem related to my PR. Though, not sure yet what's causing the change of behavior in the Darwin tests.

How do you know it's darwin specifically? It may well be wasm tests cross-compiled on darwin too.

test 'darwin hello world with updates' failed: WrongCompileErrors
But upon further inspection, it seems to happen for x86_64 as well.

It now seems to output the file path as well for the compilation error test.

},
.Int => |info| {
if (info.bits != 8 or info.signedness == .signed) {
@compileError(bad_main_ret);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is bad_main_ret? Could this be the source of failures on other targets?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const bad_main_ret = "expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks!

@Luukdegram
Copy link
Sponsor Member Author

We found the culprit: Had to update the line numbers in the compilation error checks (since I updated the start.zig file).

@Luukdegram
Copy link
Sponsor Member Author

Will fix the 32bit test error tomorrow :)

@andrewrk
Copy link
Member

We found the culprit: Had to update the line numbers in the compilation error checks (since I updated the start.zig file).

Sorry about that. That's really annoying to have to do that. I should figure out how to get that test coverage without depending on the line numbers of start.zig 🤔

Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Super exciting milestone!

@kubkon kubkon merged commit 7a7df39 into ziglang:master Nov 29, 2021
@Luukdegram Luukdegram deleted the stage2-wasm-behaviour branch November 29, 2021 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants