Skip to content

Commit

Permalink
Upgrade wasm-tools crates, namely the component model
Browse files Browse the repository at this point in the history
This commit pulls in the latest versions of all of the `wasm-tools`
family of crates. There were two major changes that happened in
`wasm-tools` in the meantime:

* bytecodealliance/wasm-tools#697 - this commit introduced a new API for
  more efficiently reading binary operators from a wasm binary. The old
  `Operator`-based reading was left in place, however, and continues to
  be what Wasmtime uses. I hope to update Wasmtime in a future PR to use
  this new API, but for now the biggest change is...

* bytecodealliance/wasm-tools#703 - this commit was a major update to
  the component model AST. This commit almost entirely deals with the
  fallout of this change.

The changes made to the component model were:

1. The `unit` type no longer exists. This was generally a simple change
   where the `Unit` case in a few different locations were all removed.
2. The `expected` type was renamed to `result`. This similarly was
   relatively lightweight and mostly just a renaming on the surface. I
   took this opportunity to rename `val::Result` to `val::ResultVal` and
   `types::Result` to `types::ResultType` to avoid clashing with the
   standard library types. The `Option`-based types were handled with
   this as well.
3. The payload type of `variant` and `result` types are now optional.
   This affected many locations that calculate flat type
   representations, ABI information, etc. The `#[derive(ComponentType)]`
   macro now specifically handles Rust-defined `enum` types which have
   no payload to the equivalent in the component model.
4. Functions can now return multiple parameters. This changed the
   signature of invoking component functions because the return value is
   now bound by `ComponentNamedList` (renamed from `ComponentParams`).
   This had a large effect in the tests, fuzz test case generation, etc.
5. Function types with 2-or-more parameters/results must uniquely name
   all parameters/results. This mostly affected the text format used
   throughout the tests.

I haven't added specifically new tests for multi-return but I changed a
number of tests to use it. Additionally I've updated the fuzzers to all
exercise multi-return as well so I think we should get some good
coverage with that.
  • Loading branch information
alexcrichton committed Aug 17, 2022
1 parent c569e7b commit 2a02bae
Show file tree
Hide file tree
Showing 37 changed files with 1,359 additions and 1,113 deletions.
21 changes: 7 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,12 @@ harness = false
[[bench]]
name = "call"
harness = false

[patch.crates-io]
wasmparser = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'component-wast' }
wasm-encoder = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'component-wast' }
wasm-mutate = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'component-wast' }
wasm-smith = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'component-wast' }
wasmprinter = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'component-wast' }
wast = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'component-wast' }
wat = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'component-wast' }
12 changes: 6 additions & 6 deletions cranelift/wasm/src/sections_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ pub fn parse_element_section<'data>(
match kind {
ElementKind::Active {
table_index,
init_expr,
offset_expr,
} => {
let mut init_expr_reader = init_expr.get_binary_reader();
let (base, offset) = match init_expr_reader.read_operator()? {
let mut offset_expr_reader = offset_expr.get_binary_reader();
let (base, offset) = match offset_expr_reader.read_operator()? {
Operator::I32Const { value } => (None, value as u32),
Operator::GlobalGet { global_index } => {
(Some(GlobalIndex::from_u32(global_index)), 0)
Expand Down Expand Up @@ -354,10 +354,10 @@ pub fn parse_data_section<'data>(
match kind {
DataKind::Active {
memory_index,
init_expr,
offset_expr,
} => {
let mut init_expr_reader = init_expr.get_binary_reader();
let (base, offset) = match init_expr_reader.read_operator()? {
let mut offset_expr_reader = offset_expr.get_binary_reader();
let (base, offset) = match offset_expr_reader.read_operator()? {
Operator::I32Const { value } => (None, value as u64),
Operator::I64Const { value } => (None, value as u64),
Operator::GlobalGet { global_index } => {
Expand Down
10 changes: 5 additions & 5 deletions crates/component-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,11 @@ impl Expander for ComponentTypeExpander {
let name = rename.unwrap_or_else(|| Literal::string(&ident.to_string()));

if let Some(ty) = ty {
abi_list.extend(quote!(<#ty as wasmtime::component::ComponentType>::ABI,));
abi_list.extend(quote!(Some(<#ty as wasmtime::component::ComponentType>::ABI),));

case_names_and_checks.extend(match style {
VariantStyle::Variant => {
quote!((#name, <#ty as wasmtime::component::ComponentType>::typecheck),)
quote!((#name, Some(<#ty as wasmtime::component::ComponentType>::typecheck)),)
}
VariantStyle::Union => {
quote!(<#ty as wasmtime::component::ComponentType>::typecheck,)
Expand All @@ -780,10 +780,10 @@ impl Expander for ComponentTypeExpander {

unique_types.insert(ty);
} else {
abi_list.extend(quote!(<() as wasmtime::component::ComponentType>::ABI,));
abi_list.extend(quote!(None,));
case_names_and_checks.extend(match style {
VariantStyle::Variant => {
quote!((#name, <() as wasmtime::component::ComponentType>::typecheck),)
quote!((#name, None),)
}
VariantStyle::Union => {
quote!(<() as wasmtime::component::ComponentType>::typecheck,)
Expand Down Expand Up @@ -846,7 +846,7 @@ impl Expander for ComponentTypeExpander {
}

unsafe impl #impl_generics #internal::ComponentVariant for #name #ty_generics #where_clause {
const CASES: &'static [#internal::CanonicalAbiInfo] = &[#abi_list];
const CASES: &'static [Option<#internal::CanonicalAbiInfo>] = &[#abi_list];
}
};

Expand Down
4 changes: 2 additions & 2 deletions crates/environ/fuzz/fuzz_targets/fact-valid-module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ fn target(module: GenAdapterModule) {
let wat = format!(
"(component
{types}
(type (func {params} {result}))
(type (func {params} {results}))
)",
types = wat_decls.types,
params = wat_decls.params,
result = wat_decls.result,
results = wat_decls.results,
);
let wasm = wat::parse_str(&wat).unwrap();

Expand Down
Loading

0 comments on commit 2a02bae

Please sign in to comment.