Skip to content

Commit

Permalink
Upgrade wasm-tools crates, namely the component model (#4715)
Browse files Browse the repository at this point in the history
* Upgrade wasm-tools crates, namely the component model

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.

* Update version numbers

* Use crates.io
  • Loading branch information
alexcrichton authored Aug 17, 2022
1 parent 3629bbb commit 57dca93
Show file tree
Hide file tree
Showing 46 changed files with 1,427 additions and 1,135 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ test-programs = { path = "crates/test-programs" }
wasmtime-runtime = { path = "crates/runtime" }
tokio = { version = "1.8.0", features = ["rt", "time", "macros", "rt-multi-thread"] }
tracing-subscriber = "0.3.1"
wast = "45.0.0"
wast = "46.0.0"
criterion = "0.3.4"
num_cpus = "1.13.0"
memchr = "2.4"
async-trait = "0.1"
wat = "1.0.47"
wat = "1.0.48"
once_cell = "1.9.0"
rayon = "1.5.0"
component-macro-test = { path = "crates/misc/component-macro-test" }
Expand Down
2 changes: 1 addition & 1 deletion cranelift/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["webassembly", "wasm"]
edition = "2021"

[dependencies]
wasmparser = { version = "0.88.0", default-features = false }
wasmparser = { version = "0.89.0", default-features = false }
cranelift-codegen = { path = "../codegen", version = "0.88.0", default-features = false }
cranelift-entity = { path = "../entity", version = "0.88.0" }
cranelift-frontend = { path = "../frontend", version = "0.88.0", default-features = false }
Expand Down
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
2 changes: 1 addition & 1 deletion crates/cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cranelift-codegen = { path = "../../cranelift/codegen", version = "0.88.0" }
cranelift-frontend = { path = "../../cranelift/frontend", version = "0.88.0" }
cranelift-entity = { path = "../../cranelift/entity", version = "0.88.0" }
cranelift-native = { path = "../../cranelift/native", version = "0.88.0" }
wasmparser = "0.88.0"
wasmparser = "0.89.0"
target-lexicon = "0.12"
gimli = { version = "0.26.0", default-features = false, features = ['read', 'std'] }
object = { version = "0.29.0", default-features = false, features = ['write'] }
Expand Down
8 changes: 4 additions & 4 deletions crates/environ/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ edition = "2021"
anyhow = "1.0"
cranelift-entity = { path = "../../cranelift/entity", version = "0.88.0" }
wasmtime-types = { path = "../types", version = "0.41.0" }
wasmparser = "0.88.0"
wasmparser = "0.89.0"
indexmap = { version = "1.0.2", features = ["serde-1"] }
thiserror = "1.0.4"
serde = { version = "1.0.94", features = ["derive"] }
log = { version = "0.4.8", default-features = false }
gimli = { version = "0.26.0", default-features = false, features = ['read'] }
object = { version = "0.29.0", default-features = false, features = ['read_core', 'write_core', 'elf'] }
target-lexicon = "0.12"
wasm-encoder = { version = "0.15.0", optional = true }
wasmprinter = { version = "0.2.38", optional = true }
wasm-encoder = { version = "0.16.0", optional = true }
wasmprinter = { version = "0.2.39", optional = true }
wasmtime-component-util = { path = "../component-util", version = "=0.41.0", optional = true }

[dev-dependencies]
atty = "0.2.14"
clap = { version = "3.2.8", features = ['derive'] }
env_logger = "0.9.0"
wat = "1.0.47"
wat = "1.0.48"

[[example]]
name = "factc"
Expand Down
4 changes: 2 additions & 2 deletions crates/environ/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ cargo-fuzz = true
arbitrary = { version = "1.1.0", features = ["derive"] }
env_logger = "0.9.0"
libfuzzer-sys = "0.4"
wasmparser = "0.88.0"
wasmprinter = "0.2.37"
wasmparser = "0.89.0"
wasmprinter = "0.2.39"
wat = "1.0"
wasmtime-environ = { path = ".." }
component-fuzz-util = { path = "../../misc/component-fuzz-util", optional = true }
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 57dca93

Please sign in to comment.