Skip to content

Add tests for the interface types output of wasm-bindgen #1898

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

Merged
merged 4 commits into from
Dec 4, 2019

Conversation

alexcrichton
Copy link
Contributor

This commit expands the test suite with assertions about the output of
the interface types pass in wasm-bindgen. The goal here is to actually
assert that we produce the right output and have a suite of reference
files to show how the interface types output is changing over time.

The reference test suite added in the previous PR has been updated to
work for interface types as well, generating *.wit file assertions
which are printed via the wit-printer crate on crates.io.

Along the way a number of bugs were fixed with the interface types
output, such as:

  • Non-determinism in output caused by iteration of a HashMap

  • Avoiding JS generation entirely in interface types mode, ensuring that
    we don't export extraneous intrinsics that aren't otherwise needed.

  • Fixing location of the stack pointer for modules where it's GC'd out.
    It's now rooted in the aux section of wasm-bindgen so it's available
    to later passes, like the multi-value pass.

  • Interface types emission now works in debug mode, meaning the
    --release flag is no longer required. This previously did not work
    because the __wbindgen_throw intrinsic was required in debug mode.
    This comes about because of the malloc_failure and internal_error
    functions in the anyref pass. The purpose of these functions is to
    signal fatal runtime errors, if any, in a way that's usable to the
    user. For wasm interface types though we can replace calls to these
    functions with unreachable to avoid needing to import the
    intrinsic. This has the accidental side effect of making
    wasm_bindgen::throw_str "just work" with wasm interface types by
    aborting the program, but that's not actually entirely intended. It's
    hoped that a split of a wasm-bindgen-core crate would solve this
    issue for the future.

@alexcrichton alexcrichton requested a review from fitzgen December 4, 2019 20:03
This commit expands the test suite with assertions about the output of
the interface types pass in wasm-bindgen. The goal here is to actually
assert that we produce the right output and have a suite of reference
files to show how the interface types output is changing over time.

The `reference` test suite added in the previous PR has been updated to
work for interface types as well, generating `*.wit` file assertions
which are printed via the `wit-printer` crate on crates.io.

Along the way a number of bugs were fixed with the interface types
output, such as:

* Non-determinism in output caused by iteration of a `HashMap`

* Avoiding JS generation entirely in interface types mode, ensuring that
  we don't export extraneous intrinsics that aren't otherwise needed.

* Fixing location of the stack pointer for modules where it's GC'd out.
  It's now rooted in the aux section of wasm-bindgen so it's available
  to later passes, like the multi-value pass.

* Interface types emission now works in debug mode, meaning the
  `--release` flag is no longer required. This previously did not work
  because the `__wbindgen_throw` intrinsic was required in debug mode.
  This comes about because of the `malloc_failure` and `internal_error`
  functions in the anyref pass. The purpose of these functions is to
  signal fatal runtime errors, if any, in a way that's usable to the
  user. For wasm interface types though we can replace calls to these
  functions with `unreachable` to avoid needing to import the
  intrinsic. This has the accidental side effect of making
  `wasm_bindgen::throw_str` "just work" with wasm interface types by
  aborting the program, but that's not actually entirely intended. It's
  hoped that a split of a `wasm-bindgen-core` crate would solve this
  issue for the future.
@alexcrichton alexcrichton force-pushed the interface-types-tests branch from f338364 to a4dfd9b Compare December 4, 2019 20:06
The stack pointer is never initialized to zero, but some other mutable
globals are (TLS, thread ID, etc), so let's filter those out.
@alexcrichton alexcrichton merged commit 203d86f into rustwasm:master Dec 4, 2019
@alexcrichton alexcrichton deleted the interface-types-tests branch December 4, 2019 21:19
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.

1 participant