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

wit-component: implement a tool to create WebAssembly components. #183

Merged
merged 13 commits into from Apr 4, 2022

Conversation

peterhuene
Copy link
Member

This PR introduces the wit-component tool responsible for taking as input a core WebAssembly module that implements the canonical ABI (i.e. produced by wit-bindgen) and a set of import and export interfaces to output a WebAssembly component based on the component model proposal.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

I want to dig a bit more into the actual construction of the final component but I've otherwise looked at a most everything else and this is all looking really good. This is a first round of feedback but has a lot of musings about various unrelated things to this PR which we'll want to consider for future refactorings too.

crates/wit-component/Cargo.toml Show resolved Hide resolved
crates/wit-component/tests/wit/floats.wat Outdated Show resolved Hide resolved
crates/wit-component/tests/wit/floats.wat Outdated Show resolved Hide resolved
crates/wit-component/tests/interface-encoding.rs Outdated Show resolved Hide resolved
crates/wit-component/src/encoding.rs Outdated Show resolved Hide resolved
crates/wit-component/src/encoding.rs Outdated Show resolved Hide resolved
crates/wit-component/src/encoding.rs Show resolved Hide resolved
crates/wit-component/src/encoding.rs Show resolved Hide resolved
crates/wit-component/src/encoding.rs Outdated Show resolved Hide resolved
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Apr 1, 2022
From bytecodealliance/wit-bindgen#183 I realized that the current
explainer has the printing of indices here slightly different where the
outer index/name is outside in the `alias` annotation where the local
name/index is printed inside of the `type` or item container.

This also updates the printing of the local index to attempt to use the
name section, if one is present.
peterhuene pushed a commit to bytecodealliance/wasm-tools that referenced this pull request Apr 1, 2022
From bytecodealliance/wit-bindgen#183 I realized that the current
explainer has the printing of indices here slightly different where the
outer index/name is outside in the `alias` annotation where the local
name/index is printed inside of the `type` or item container.

This also updates the printing of the local index to attempt to use the
name section, if one is present.
@peterhuene
Copy link
Member Author

Working on fixing up the way we do import lowering, but that should be the last bit of feedback remaining thus far.

@peterhuene
Copy link
Member Author

Okay, I think all code review feedback thus far has been addressed. I'll rebase this once approved to resolve the conflict.

This commit provides the initial implementation for the `wit-component` tool.

The tool is responsible for converting a core module implementing the canonical
ABI into a component based on the WebAssembly component model proposal.

Users provide the tool with the interfaces to be exported or imported by the
component in `wit` format. The output of the tool is a component file.

The tool validates that the core module is satisfied with the given imports and
also exports the provided interfaces.

The output component is also verified with the validator from `wasmparser`.
This commit adds a test to encode an interface, decode the bytes using
`wasmprinter`, and then compare the output with a baseline wat file.

It also adds a `simple` test case for encoding components where a component
exports a single default interface.
This commit adds more tests to `wit-component` for component encoding.
This commit adds several test cases for validation of the module that will be
encoded as a component.
This commit only adds an encoding option if the function signatures contain
strings.

It also only adds the `into` option only if the function signature requires it.

Added tests for lifting and lowering of various function signatures to ensure
the canonical options emitted are correct.
This commit updates the documentation for the tests in `wit-component` and
restructures the interface encoding tests directory layout to match that of the
component encoding tests.
This commit updates wasmprinter and the test baselines now that it correctly
prints outer aliases.
The `pretty_assertions` crate prints a nice diff for `assert_eq!` failures, but
the tests were reversing left and right to make it more confusing when
conceptually seeing changes from the baseline.

This commit swaps the two arguments to `assert_eq!` so that left is the
baseline and right is the output of the test.
This commit adds some names to one of the test module's canonical definitions.

This helps to test that the names survive encoding and are also present when
printed.
This commit adds a test to cover both importing and exporting interfaces from
the same component.

Fixes a bug where importing functions wasn't contributing to the function type
list.
This commit uses the type information returned from wasmparser for the
validation of the core module.

It also reduces the complexity of parsing the core module by using methods
provided by wasmparser.
Various code review feedback changes.
This commit changes how imports are lowered.

Previously, the tool used indirect lowerings for all imports, even if the
import didn't need the `into` option. Now such lowerings are lowered before the
inner core module is instantiated and directly given as an argument.

Additionally, if there are indirect lowerings to perform, at most two
additional modules are encoded: a module storing a table for only the indirect
lowerings and another that initializes the table once the core module has been
instantiated.
@peterhuene peterhuene merged commit 8929a90 into bytecodealliance:main Apr 4, 2022
@peterhuene peterhuene deleted the wit-component branch April 4, 2022 17:47
willemneal pushed a commit to AhaLabs/wit-bindgen that referenced this pull request May 31, 2022
…tecodealliance#183)

* wit-component: initial implementation.

This commit provides the initial implementation for the `wit-component` tool.

The tool is responsible for converting a core module implementing the canonical
ABI into a component based on the WebAssembly component model proposal.

Users provide the tool with the interfaces to be exported or imported by the
component in `wit` format. The output of the tool is a component file.

The tool validates that the core module is satisfied with the given imports and
also exports the provided interfaces.

The output component is also verified with the validator from `wasmparser`.

* wit-component: add more tests.

This commit adds a test to encode an interface, decode the bytes using
`wasmprinter`, and then compare the output with a baseline wat file.

It also adds a `simple` test case for encoding components where a component
exports a single default interface.

* wit-component: add more component tests.

This commit adds more tests to `wit-component` for component encoding.

* wit-component: add error handling test cases.

This commit adds several test cases for validation of the module that will be
encoded as a component.

* wit-component: be smarter about canonical option encoding.

This commit only adds an encoding option if the function signatures contain
strings.

It also only adds the `into` option only if the function signature requires it.

Added tests for lifting and lowering of various function signatures to ensure
the canonical options emitted are correct.

* wit-component: update and better doc test cases.

This commit updates the documentation for the tests in `wit-component` and
restructures the interface encoding tests directory layout to match that of the
component encoding tests.

* wit-component: update test baseline for new wasmprinter.

This commit updates wasmprinter and the test baselines now that it correctly
prints outer aliases.

* wit-component: update assert_eq! for better diff printing.

The `pretty_assertions` crate prints a nice diff for `assert_eq!` failures, but
the tests were reversing left and right to make it more confusing when
conceptually seeing changes from the baseline.

This commit swaps the two arguments to `assert_eq!` so that left is the
baseline and right is the output of the test.

* wit-component: give names to one of the test core modules.

This commit adds some names to one of the test module's canonical definitions.

This helps to test that the names survive encoding and are also present when
printed.

* wit-component: add an import and export test case.

This commit adds a test to cover both importing and exporting interfaces from
the same component.

Fixes a bug where importing functions wasn't contributing to the function type
list.

* wit-component: use type information from wasmparser for validation.

This commit uses the type information returned from wasmparser for the
validation of the core module.

It also reduces the complexity of parsing the core module by using methods
provided by wasmparser.

* wit-component: code review feedback changes.

Various code review feedback changes.

* wit-component: be smarter about import lowerings.

This commit changes how imports are lowered.

Previously, the tool used indirect lowerings for all imports, even if the
import didn't need the `into` option. Now such lowerings are lowered before the
inner core module is instantiated and directly given as an argument.

Additionally, if there are indirect lowerings to perform, at most two
additional modules are encoded: a module storing a table for only the indirect
lowerings and another that initializes the table once the core module has been
instantiated.
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