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

Merge with upstream #127

Merged
merged 14 commits into from
Aug 16, 2024
Merged

Merge with upstream #127

merged 14 commits into from
Aug 16, 2024

Conversation

dhil
Copy link
Member

@dhil dhil commented Aug 16, 2024

No description provided.

alexcrichton and others added 14 commits August 12, 2024 14:54
Also cause it to return an error if the input is a core wasm module with
zero `component-type` custom sections.

Closes bytecodealliance#1673
This change attempts to add tests that check that
shared-everything-threads features indeed fail when the proposal is not
enabled. In doing this, I realized that a few features fail on other
features first (GC, reftypes), which meant the tests couldn't be as
exhaustive as I would have liked. This commit also changes the wording
of one of the failures to be consistent across the proposal.
This change adopts the suggestion to use the "missing-features + X"
functionality in `roundtrip.rs` to check more corner cases where
shared-everything-threads must be enabled. It adds the reference-types
proposal to the GC feature set to make this possible.
If an error was found before the code section a DWARF-related warning
was printed but that's not relevant and is false information, so squash
the warning.
* Update wasm-encoder's type encoding to match `wast`

This updates it to not only match the structure but also binary output.
This means that shorter forms are used a bit more and encodings for
shared-everything-threads are additionally fixed.

* Update wasm_encoder's reencoding of const exprs

Use more generic helpers to support multiple instructions and
additionally more instructions. This refactors the `parse_instruction`
helper to return the instruction directly instead of unconditionally
encoding into a `Function`.

* Simplify some type encoding in `wast`

No functional change here, just reducing some duplication of code.

* Test wasm-encoder roundtrips of `roundtrip` tests

This commit updates the wasm-roundtrip test suite to additionally run
all binaries through the reencoding phase of `wasm-encoder` to assert
the final binary matches `wast`. This is skipped for components for now
as reencoding support isn't here for components just yet.

* Fix error message when wasm binaries differ

The condition here was inverted by accident meaning that more helpful
error messages were not being generated.
* Update spec testsuite submodule to latest

* Update all snapshots

* Get all spec tests passing

* Tweak some error messages and expected error messages.
* Update validation of `try_table` to enable catching with `(ref exn)`
* Update `json-from-wast` with remaining reference types
* Update features enabled for `memory64` since it has rebased on the 3.0
  spec.
…liance#1722)

* Extend re-encode functionality to support components

Signed-off-by: itowlson <ivan.towlson@fermyon.com>

* WIP: indexes, reorg

Signed-off-by: itowlson <ivan.towlson@fermyon.com>

* Finish reencoding support for components to wasm-encoder

This commit is an extension of bytecodealliance#1656 to support components in the
reencoding support of wasm-encoder. The precise shape of the trait will
probably change over time but this is at least a first stab at getting
things working to map all the wasmparser types to wasm-encoder for components.

All existing support for components in `reencode.rs` was moved to a new
`ReencodeComponent` trait which inherits from the already-existing
`Reencode` trait. This is all located in a new `component.rs` file
beneath `reencode.rs` although crate-wise it's all showing up in the
same `wasm_encoder::reencode` module.

* Fix compat with Rust 1.78

---------

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
Co-authored-by: itowlson <ivan.towlson@fermyon.com>
This change fixes several `wast` typos and regularizes the encoding hex
codes for the shared-everything-threads instructions to use lowercase
like the rest of the file.
* threads: fix `ref.i31_shared` encoding

In the initial implementation, this encoding was incorrectly emitted as
`0xFE 0x1F`, clobbering the encoding for `i64.atomic.rmw.add` (probably
a copy-paste error). This change updates `wasm-encoder` to use the
correct `0xFE 0x72` encoding.

* threads: fix `ref.i31_shared` stack type

This instruction should return the `shared` version of `ref.i31`.

* Add a simple re-encodable test
* threads: rename tests

This change simply renames the shared-everything-threads tests to use
more conventional names within the repository.

* threads: add more Binaryen tests

@tlively has been working on Binaryen support for
shared-everything-threads and has upstreamed several [tests] that are
useful here. This change incorporates some "bottom type" checks for
arrays and structs as a `shared-ref_eq.wast` test checking `ref.eq`
behavior for shared types (renamed to `ref-equivalence.wast` here).

To make these added tests pass, validation for `ref.eq` now allows it to
check both shared and ushared `eqref` types the the `ref.i31_shared`
returns the correct type.

[tests]: https://github.com/WebAssembly/binaryen/blob/main/test/spec
[shared-ref_eq.wast]: https://github.com/WebAssembly/binaryen/blob/main/test/spec/shared-ref_eq.wast

* threads: add polymorphism over `shared`

Certain instructions accept both shared and unshared references:
`ref.eq`, `i31.get_s`, `i31.get_u`, `array.len`, `any.convert_extern`,
and `extern.convert_any`. Validation needs to handle these special cases
to pass Binaryen's `polymorphism.wast` test. This change refactors the
`pop_operand` family of functions with several helpers to add
`pop_maybe_shared_ref`; `pop_maybe_shared_ref` lets the validator pass
an unshared `RefType` expectation but adapts it to being shared if that
is what is on the stack.

* Undo previous refactoring; reuse `OperatorValidatorTemp::pop_ref`

This change undoes previous work to rationalize the duplication in
`_pop_operand`, `pop_ref`, and now `pop_maybe_shared_ref`. As suggested
by @alexcrichton, this attempt keeps the status quo by reusing `pop_ref`
and doing a bit more work after the fact (re-checking the subtype
relationship).

* Handle `ref.eq` types from unreachable code

This validator's existing logic assumed that the bottom and heap bottom
types matched any reference type (see `_pop_operand`). This change
surfaces that logic to `visit_ref_eq` as well: if `pop_maybe_shared_ref`
returns `None` (a bottom or heap bottom) for either value to `ref.eq`,
we skip checking the shared-ness match, assuming like we do in
`_pop_operand` that a bottom or heap bottom matches any reference type
(we've already checked that the types are subtypes of `eqref`).

* Add TODO for unshared propagation in unreachable code

* Return shared `bool` from `pop_maybe_shared_ref`

* Rename `is_shared_ref_type` to `is_shared`
…ance#1726)

This was an idea I had after bytecodealliance#1719 landed to statically ensure that the
asserts won't trip.
)

* Add a new `wasm-tools component unbundle` command

This commit adds a new subcommand to `wasm-tools component` named
`unbundle` which is tasked with extracting core wasm modules out of a
component. This is intended to showcase an example implementation of
doing this and the main motivation is to extract core wasm modules out
of a component for runtimes such as Wasmtime. This enables sharing
machine code for WebAssembly modules between components that use the
same core wasm module.

This new subcommand is primarily built on `wasm_encoder::reencode` with
a simple size-based heuristic for which modules to extract.

* Test module output as well
@dhil dhil merged commit 2cc5da3 into wasmfx:main Aug 16, 2024
28 checks passed
@dhil dhil deleted the wasmfx-merge branch August 16, 2024 14:07
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.

3 participants