Skip to content

Commit

Permalink
Update wasm-tools crates (#9703)
Browse files Browse the repository at this point in the history
Mostly comes with a split in `wasmparser` of simd/other ops since it's
now possible to disable the `simd` feature at compile time (which we
don't use in Wasmtime right now).
  • Loading branch information
alexcrichton authored Dec 2, 2024
1 parent 2134598 commit 1256cfa
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 132 deletions.
188 changes: 136 additions & 52 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,16 @@ wit-bindgen = { version = "0.35.0", default-features = false }
wit-bindgen-rust-macro = { version = "0.35.0", default-features = false }

# wasm-tools family:
wasmparser = { version = "0.220.0", default-features = false }
wat = "1.220.0"
wast = "220.0.0"
wasmprinter = "0.220.0"
wasm-encoder = "0.220.0"
wasm-smith = "0.220.0"
wasm-mutate = "0.220.0"
wit-parser = "0.220.0"
wit-component = "0.220.0"
wasm-wave = "0.220.0"
wasmparser = { version = "0.221.2", default-features = false, features = ['simd'] }
wat = "1.221.2"
wast = "221.0.2"
wasmprinter = "0.221.2"
wasm-encoder = "0.221.2"
wasm-smith = "0.221.2"
wasm-mutate = "0.221.2"
wit-parser = "0.221.2"
wit-component = "0.221.2"
wasm-wave = "0.221.2"

# Non-Bytecode Alliance maintained dependencies:
# --------------------------
Expand Down
3 changes: 3 additions & 0 deletions crates/cranelift/src/translate/code_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2944,6 +2944,9 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let (res1, res2) = builder.ins().isplit(result);
state.push2(res1, res2);
}

// catch-all as `Operator` is `#[non_exhaustive]`
op => return Err(wasm_unsupported!("operator {op:?}")),
};
Ok(())
}
Expand Down
6 changes: 1 addition & 5 deletions crates/wast-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,11 @@ impl WastTest {
"spec_testsuite/ref_is_null.wast",
"spec_testsuite/ref_null.wast",
"spec_testsuite/select.wast",
"spec_testsuite/table-sub.wast",
"spec_testsuite/table_fill.wast",
"spec_testsuite/table_get.wast",
"spec_testsuite/table_grow.wast",
"spec_testsuite/table_set.wast",
"spec_testsuite/table_size.wast",
"spec_testsuite/unreached-invalid.wast",
"spec_testsuite/call_indirect.wast",
// simd-related failures
"annotations/simd_lane.wast",
"memory64/simd.wast",
Expand Down Expand Up @@ -408,15 +405,14 @@ impl WastTest {
for part in self.path.iter() {
// Not implemented in Wasmtime yet
if part == "exception-handling" {
return !self.path.ends_with("binary.wast");
return !self.path.ends_with("binary.wast") && !self.path.ends_with("exports.wast");
}

if part == "memory64" {
if [
// wasmtime doesn't implement exceptions yet
"imports.wast",
"ref_null.wast",
"exports.wast",
"throw.wast",
"throw_ref.wast",
"try_table.wast",
Expand Down
36 changes: 20 additions & 16 deletions crates/wast/src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ where
Err(e) => e,
};
let error_message = format!("{err:?}");
if !is_matching_assert_invalid_error_message(&message, &error_message) {
if !is_matching_assert_invalid_error_message(filename, &message, &error_message) {
bail!(
"assert_invalid: expected \"{}\", got \"{}\"",
message,
Expand Down Expand Up @@ -612,19 +612,23 @@ where
}
}

fn is_matching_assert_invalid_error_message(expected: &str, actual: &str) -> bool {
actual.contains(expected)
// slight difference in error messages
|| (expected.contains("unknown elem segment") && actual.contains("unknown element segment"))
|| (expected.contains("type mismatch") && actual.contains("indirect calls must go through a table with type <= funcref"))
// The same test here is asserted to have one error message in
// `memory.wast` and a different error message in
// `memory64/memory.wast`, so we equate these two error messages to get
// the memory64 tests to pass.
|| (expected.contains("memory size must be at most 65536 pages") && actual.contains("invalid u32 number"))
// the spec test suite asserts a different error message than we print
// for this scenario
|| (expected == "unknown global" && actual.contains("global.get of locally defined global"))
|| (expected == "immutable global" && actual.contains("global is immutable: cannot modify it with `global.set`"))
|| (expected == "table size must be at most 2^32-1" && actual.contains("invalid u32 number: constant out of range"))
fn is_matching_assert_invalid_error_message(test: &str, expected: &str, actual: &str) -> bool {
if actual.contains(expected) {
return true;
}

// Historically wasmtime/wasm-tools tried to match the upstream error
// message. This generally led to a large sequence of matches here which is
// not easy to maintain and is particularly difficult when test suites and
// proposals conflict with each other (e.g. one asserts one error message
// and another asserts a different error message). Overall we didn't benefit
// a whole lot from trying to match errors so just assume the error is
// roughly the same and otherwise don't try to match it.
if Path::new(test).starts_with("./tests/spec_testsuite") {
return true;
}

// we are in control over all non-spec tests so all the error messages
// there should exactly match the `assert_invalid` or such
false
}
11 changes: 10 additions & 1 deletion supply-chain/audits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,15 @@ criteria = "safe-to-deploy"
delta = "1.0.26 -> 1.0.28"
notes = "No new `unsafe` and no large changes in function. This diff is mostly refactoring with a lot of docs, CI, test changes. Adds some defensive clearing out of certain variables as a safeguard."

[[audits.foldhash]]
who = "Alex Crichton <[email protected]>"
criteria = "safe-to-deploy"
version = "0.1.3"
notes = """
Only a minor amount of `unsafe` code in this crate related to global per-process
initialization which looks correct to me.
"""

[[audits.foreign-types]]
who = "Pat Hickey <[email protected]>"
criteria = "safe-to-deploy"
Expand Down Expand Up @@ -4116,7 +4125,7 @@ end = "2024-07-14"
criteria = "safe-to-deploy"
user-id = 2915 # Amanieu d'Antras (Amanieu)
start = "2019-04-02"
end = "2024-07-11"
end = "2025-12-02"

[[trusted.indexmap]]
criteria = "safe-to-deploy"
Expand Down
60 changes: 30 additions & 30 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ user-login = "Amanieu"
user-name = "Amanieu d'Antras"

[[publisher.hashbrown]]
version = "0.14.5"
when = "2024-04-28"
version = "0.15.2"
when = "2024-11-25"
user-id = 2915
user-login = "Amanieu"
user-name = "Amanieu d'Antras"
Expand Down Expand Up @@ -937,50 +937,50 @@ user-login = "alexcrichton"
user-name = "Alex Crichton"

[[publisher.wasm-encoder]]
version = "0.219.1"
when = "2024-10-10"
version = "0.220.0"
when = "2024-11-12"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasm-encoder]]
version = "0.220.0"
when = "2024-11-12"
version = "0.221.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasm-metadata]]
version = "0.219.1"
when = "2024-10-10"
version = "0.220.0"
when = "2024-11-12"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasm-metadata]]
version = "0.220.0"
when = "2024-11-12"
version = "0.221.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasm-wave]]
version = "0.220.0"
when = "2024-11-12"
version = "0.221.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasmparser]]
version = "0.219.1"
when = "2024-10-10"
version = "0.220.0"
when = "2024-11-12"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasmparser]]
version = "0.220.0"
when = "2024-11-12"
version = "0.221.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasmprinter]]
version = "0.220.0"
when = "2024-11-12"
version = "0.221.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

Expand Down Expand Up @@ -1129,14 +1129,14 @@ user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wast]]
version = "220.0.0"
when = "2024-11-12"
version = "221.0.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wat]]
version = "1.220.0"
when = "2024-11-12"
version = "1.221.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

Expand Down Expand Up @@ -1384,26 +1384,26 @@ user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-component]]
version = "0.219.1"
when = "2024-10-10"
version = "0.220.0"
when = "2024-11-12"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-component]]
version = "0.220.0"
when = "2024-11-12"
version = "0.221.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-parser]]
version = "0.219.1"
when = "2024-10-10"
version = "0.220.0"
when = "2024-11-12"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-parser]]
version = "0.220.0"
when = "2024-11-12"
version = "0.221.2"
when = "2024-12-02"
user-id = 73222
user-login = "wasmtime-publish"

Expand Down
27 changes: 23 additions & 4 deletions winch/codegen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use cranelift_codegen::{
use smallvec::SmallVec;
use wasmparser::{
BinaryReader, FuncValidator, MemArg, Operator, ValidatorResources, VisitOperator,
VisitSimdOperator,
};
use wasmtime_cranelift::{TRAP_BAD_SIGNATURE, TRAP_TABLE_OUT_OF_BOUNDS};
use wasmtime_environ::{
Expand Down Expand Up @@ -245,7 +246,7 @@ where
while !body.eof() {
let offset = body.original_position();
body.visit_operator(&mut ValidateThenVisit(
validator.visitor(offset),
validator.simd_visitor(offset),
self,
offset,
))??;
Expand Down Expand Up @@ -330,13 +331,31 @@ where

impl<'a, T, U> VisitOperator<'a> for ValidateThenVisit<'_, T, U>
where
T: VisitOperator<'a, Output = wasmparser::Result<()>>,
U: VisitOperator<'a> + VisitorHooks,
T: VisitSimdOperator<'a, Output = wasmparser::Result<()>>,
U: VisitSimdOperator<'a> + VisitorHooks,
U::Output: Default,
{
type Output = Result<U::Output>;

wasmparser::for_each_operator!(validate_then_visit);
fn simd_visitor(
&mut self,
) -> Option<&mut dyn VisitSimdOperator<'a, Output = Self::Output>>
where
T:,
{
Some(self)
}

wasmparser::for_each_visit_operator!(validate_then_visit);
}

impl<'a, T, U> VisitSimdOperator<'a> for ValidateThenVisit<'_, T, U>
where
T: VisitSimdOperator<'a, Output = wasmparser::Result<()>>,
U: VisitSimdOperator<'a> + VisitorHooks,
U::Output: Default,
{
wasmparser::for_each_visit_simd_operator!(validate_then_visit);
}
}

Expand Down
37 changes: 23 additions & 14 deletions winch/codegen/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use crate::reg::{writable, Reg};
use crate::stack::{TypedReg, Val};
use regalloc2::RegClass;
use smallvec::SmallVec;
use wasmparser::{BlockType, BrTable, Ieee32, Ieee64, MemArg, VisitOperator, V128};
use wasmparser::{
BlockType, BrTable, Ieee32, Ieee64, MemArg, VisitOperator, VisitSimdOperator, V128,
};
use wasmtime_cranelift::TRAP_INDIRECT_CALL_TO_NULL;
use wasmtime_environ::{
FuncIndex, GlobalIndex, MemoryIndex, TableIndex, TypeIndex, WasmHeapType, WasmValType,
Expand Down Expand Up @@ -273,10 +275,6 @@ where
self.context.stack.push(Val::f64(val));
}

fn visit_v128_const(&mut self, val: V128) {
self.context.stack.push(Val::v128(val.i128()))
}

fn visit_f32_add(&mut self) {
self.context.binop(
self.masm,
Expand Down Expand Up @@ -2057,14 +2055,6 @@ where
self.emit_wasm_store(&memarg, OperandSize::S64)
}

fn visit_v128_load(&mut self, memarg: MemArg) {
self.emit_wasm_load(&memarg, WasmValType::V128, OperandSize::S128, None)
}

fn visit_v128_store(&mut self, memarg: MemArg) {
self.emit_wasm_store(&memarg, OperandSize::S128)
}

fn visit_i32_trunc_sat_f32_s(&mut self) {
use OperandSize::*;

Expand Down Expand Up @@ -2219,7 +2209,26 @@ where
self.masm.mul_wide(&mut self.context, MulWideKind::Unsigned);
}

wasmparser::for_each_operator!(def_unsupported);
wasmparser::for_each_visit_operator!(def_unsupported);
}

impl<'a, 'translation, 'data, M> VisitSimdOperator<'a> for CodeGen<'a, 'translation, 'data, M>
where
M: MacroAssembler,
{
fn visit_v128_const(&mut self, val: V128) {
self.context.stack.push(Val::v128(val.i128()))
}

fn visit_v128_load(&mut self, memarg: MemArg) {
self.emit_wasm_load(&memarg, WasmValType::V128, OperandSize::S128, None)
}

fn visit_v128_store(&mut self, memarg: MemArg) {
self.emit_wasm_store(&memarg, OperandSize::S128)
}

wasmparser::for_each_visit_simd_operator!(def_unsupported);
}

impl<'a, 'translation, 'data, M> CodeGen<'a, 'translation, 'data, M>
Expand Down

0 comments on commit 1256cfa

Please sign in to comment.