From 9dffaf9d577cf731d54e94b385fec2a8174dce36 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 6 Feb 2020 12:25:32 -0600 Subject: [PATCH] Update wasmparser dependency (#912) * Update wasmparser dependency Closes #905 * Fix lightbeam compilation --- Cargo.lock | 36 ++-- crates/api/Cargo.toml | 2 +- crates/debug/Cargo.toml | 2 +- crates/environ/Cargo.toml | 2 +- crates/fuzzing/Cargo.toml | 2 +- crates/interface-types/Cargo.toml | 2 +- crates/jit/Cargo.toml | 2 +- crates/lightbeam/Cargo.toml | 2 +- crates/lightbeam/src/error.rs | 3 +- crates/lightbeam/src/function_body.rs | 5 +- crates/lightbeam/src/microwasm.rs | 236 +++++++++----------------- crates/misc/py/Cargo.toml | 2 +- 12 files changed, 111 insertions(+), 185 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cdc3486bdf..fda6af81c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -896,7 +896,7 @@ dependencies = [ "smallvec", "thiserror", "typemap", - "wasmparser 0.47.0", + "wasmparser 0.51.0", "wat", ] @@ -1859,12 +1859,6 @@ version = "0.39.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" -[[package]] -name = "wasmparser" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1527c84a5bd585215f29c06b0e2a5274e478ad4dfc970d26ffad66fdc6cb311d" - [[package]] name = "wasmparser" version = "0.47.0" @@ -1872,13 +1866,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1add8db5a53a2f64f13418b241982c4ab533d7a9e1e8a5dcadccce633d8d393b" [[package]] -name = "wasmprinter" -version = "0.2.0" +name = "wasmparser" +version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89101d1890503f4d87cc0512ff2568c00d6c13ed9de3880569e5c9c21556c06c" +checksum = "6860a452de64c9f5fb5af92a630b3894c0414a5f6a113f184ad2376d7a39fb40" + +[[package]] +name = "wasmprinter" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bd423d45b95fcee11775472bfdce66c63c45ada23c1b338e0a63d623a6c475b" dependencies = [ "anyhow", - "wasmparser 0.42.1", + "wasmparser 0.51.0", ] [[package]] @@ -1897,7 +1897,7 @@ dependencies = [ "rustc-demangle", "target-lexicon", "wasi-common", - "wasmparser 0.47.0", + "wasmparser 0.51.0", "wasmtime-environ", "wasmtime-jit", "wasmtime-runtime", @@ -1951,7 +1951,7 @@ dependencies = [ "more-asserts", "target-lexicon", "thiserror", - "wasmparser 0.47.0", + "wasmparser 0.51.0", "wasmtime-environ", ] @@ -1985,7 +1985,7 @@ dependencies = [ "tempfile", "thiserror", "toml", - "wasmparser 0.47.0", + "wasmparser 0.51.0", "winapi", "zstd", ] @@ -2009,7 +2009,7 @@ dependencies = [ "binaryen", "env_logger 0.7.1", "log", - "wasmparser 0.47.0", + "wasmparser 0.51.0", "wasmprinter", "wasmtime", "wat", @@ -2022,7 +2022,7 @@ dependencies = [ "anyhow", "walrus", "wasm-webidl-bindings", - "wasmparser 0.47.0", + "wasmparser 0.51.0", "wasmtime", "wasmtime-environ", "wasmtime-jit", @@ -2045,7 +2045,7 @@ dependencies = [ "region", "target-lexicon", "thiserror", - "wasmparser 0.47.0", + "wasmparser 0.51.0", "wasmtime-debug", "wasmtime-environ", "wasmtime-runtime", @@ -2070,7 +2070,7 @@ dependencies = [ "pyo3", "region", "target-lexicon", - "wasmparser 0.47.0", + "wasmparser 0.51.0", "wasmtime", "wasmtime-interface-types", "wasmtime-wasi", diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index b48b8a59e3..8453cd525c 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" wasmtime-runtime = { path = "../runtime", version = "0.9.0" } wasmtime-environ = { path = "../environ", version = "0.9.0" } wasmtime-jit = { path = "../jit", version = "0.9.0" } -wasmparser = { version = "0.47.0", default-features = false } +wasmparser = "0.51.0" target-lexicon = { version = "0.10.0", default-features = false } anyhow = "1.0.19" region = "2.0.0" diff --git a/crates/debug/Cargo.toml b/crates/debug/Cargo.toml index f7ac2cc8c0..fdc90f8735 100644 --- a/crates/debug/Cargo.toml +++ b/crates/debug/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] gimli = "0.19.0" -wasmparser = "0.47.0" +wasmparser = "0.51.0" faerie = "0.14.0" wasmtime-environ = { path = "../environ", version = "0.9.0" } target-lexicon = { version = "0.10.0", default-features = false } diff --git a/crates/environ/Cargo.toml b/crates/environ/Cargo.toml index 94f5bcbe57..331a7e0147 100644 --- a/crates/environ/Cargo.toml +++ b/crates/environ/Cargo.toml @@ -16,7 +16,7 @@ anyhow = "1.0" cranelift-codegen = { version = "0.56", features = ["enable-serde"] } cranelift-entity = { version = "0.56", features = ["enable-serde"] } cranelift-wasm = { version = "0.56", features = ["enable-serde"] } -wasmparser = "0.47.0" +wasmparser = "0.51.0" lightbeam = { path = "../lightbeam", optional = true, version = "0.9.0" } indexmap = "1.0.2" rayon = "1.2.1" diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index 98fe89affe..3a44047974 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -14,7 +14,7 @@ arbitrary = { version = "0.3.2", features = ["derive"] } binaryen = "0.8.2" env_logger = { version = "0.7.1", optional = true } log = "0.4.8" -wasmparser = "0.47.0" +wasmparser = "0.51.0" wasmprinter = "0.2.0" wasmtime = { path = "../api", version = "0.9.0" } diff --git a/crates/interface-types/Cargo.toml b/crates/interface-types/Cargo.toml index 380d466766..cb96cdb473 100644 --- a/crates/interface-types/Cargo.toml +++ b/crates/interface-types/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] anyhow = "1.0.19" walrus = "0.13" -wasmparser = { version = "0.47.0", default-features = false } +wasmparser = "0.51.0" wasm-webidl-bindings = "0.6" wasmtime = { path = "../api", version = "0.9.0" } wasmtime-jit = { path = "../jit", version = "0.9.0" } diff --git a/crates/jit/Cargo.toml b/crates/jit/Cargo.toml index 2670bb7564..ce8e2b5868 100644 --- a/crates/jit/Cargo.toml +++ b/crates/jit/Cargo.toml @@ -22,7 +22,7 @@ wasmtime-debug = { path = "../debug", version = "0.9.0" } region = "2.0.0" thiserror = "1.0.4" target-lexicon = { version = "0.10.0", default-features = false } -wasmparser = { version = "0.47.0", default-features = false } +wasmparser = "0.51.0" more-asserts = "0.2.1" anyhow = "1.0" cfg-if = "0.1.9" diff --git a/crates/lightbeam/Cargo.toml b/crates/lightbeam/Cargo.toml index 685785c08c..9b88f8ed68 100644 --- a/crates/lightbeam/Cargo.toml +++ b/crates/lightbeam/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" smallvec = "1.0.0" dynasm = "0.5.2" dynasmrt = "0.5.2" -wasmparser = "0.47.0" +wasmparser = "0.51.0" memoffset = "0.5.3" itertools = "0.8.2" capstone = "0.6.0" diff --git a/crates/lightbeam/src/error.rs b/crates/lightbeam/src/error.rs index 67031afe1b..3a64e660fe 100644 --- a/crates/lightbeam/src/error.rs +++ b/crates/lightbeam/src/error.rs @@ -19,8 +19,7 @@ pub enum Error { impl From for Error { fn from(e: BinaryReaderError) -> Self { - let BinaryReaderError { message, offset } = e; - Error::Input(format!("At wasm offset {}: {}", offset, message)) + Error::Input(format!("At wasm offset {}: {}", e.offset(), e.message())) } } diff --git a/crates/lightbeam/src/function_body.rs b/crates/lightbeam/src/function_body.rs index eca60528a1..439a41a22f 100644 --- a/crates/lightbeam/src/function_body.rs +++ b/crates/lightbeam/src/function_body.rs @@ -73,10 +73,7 @@ where let mut body = Vec::new(); for i in microwasm_conv { - match i { - Ok(v) => body.extend(v), - Err(e) => return Err(Error::Microwasm(e.message.to_string())), - }; + body.extend(i?); } translate(session, reloc_sink, func_idx, body)?; diff --git a/crates/lightbeam/src/microwasm.rs b/crates/lightbeam/src/microwasm.rs index 2a1a26d027..3b17600e11 100644 --- a/crates/lightbeam/src/microwasm.rs +++ b/crates/lightbeam/src/microwasm.rs @@ -8,7 +8,7 @@ use std::{ ops::RangeInclusive, }; use wasmparser::{ - BinaryReaderError, FunctionBody, Ieee32 as WasmIeee32, Ieee64 as WasmIeee64, + FunctionBody, Ieee32 as WasmIeee32, Ieee64 as WasmIeee64, MemoryImmediate as WasmMemoryImmediate, Operator as WasmOperator, OperatorsReader, }; @@ -275,7 +275,7 @@ pub const SF32: SignfulType = Type::Float(Size::_32); pub const SF64: SignfulType = Type::Float(Size::_64); impl SignlessType { - pub fn from_wasm(other: wasmparser::Type) -> Result { + pub fn from_wasm(other: wasmparser::Type) -> Result { use wasmparser::Type; match other { @@ -283,27 +283,22 @@ impl SignlessType { Type::I64 => Ok(I64), Type::F32 => Ok(F32), Type::F64 => Ok(F64), - Type::EmptyBlockType => Err(BinaryReaderError { - message: "SignlessType with EmptyBlockType", - offset: -1isize as usize, - }), - _ => Err(BinaryReaderError { - message: "SignlessType unimplemented", - offset: -1isize as usize, - }), + Type::EmptyBlockType => Err(Error::Microwasm( + "SignlessType with EmptyBlockType".to_string(), + )), + _ => Err(Error::Microwasm("SignlessType unimplemented".to_string())), } } } fn create_returns_from_wasm_type( ty: wasmparser::TypeOrFuncType, -) -> Result, BinaryReaderError> { +) -> Result, Error> { match ty { wasmparser::TypeOrFuncType::Type(ty) => Ok(Vec::from_iter(Type::from_wasm(ty))), - wasmparser::TypeOrFuncType::FuncType(_) => Err(BinaryReaderError { - message: "Unsupported func type", - offset: -1isize as usize, - }), + wasmparser::TypeOrFuncType::FuncType(_) => { + Err(Error::Microwasm("Unsupported func type".to_string())) + } } } @@ -1106,7 +1101,7 @@ where Ok(out) } - fn op_sig(&self, op: &WasmOperator) -> Result { + fn op_sig(&self, op: &WasmOperator) -> Result { use self::SigT::T; use std::iter::{empty as none, once}; @@ -1237,16 +1232,10 @@ where WasmOperator::F64Const { .. } => sig!(() -> (F64)), WasmOperator::RefNull => { - return Err(BinaryReaderError { - message: "RefNull unimplemented", - offset: -1isize as usize, - }) + return Err(Error::Microwasm("RefNull unimplemented".to_string())) } WasmOperator::RefIsNull => { - return Err(BinaryReaderError { - message: "RefIsNull unimplemented", - offset: -1isize as usize, - }) + return Err(Error::Microwasm("RefIsNull unimplemented".to_string())) } // All comparison operators remove 2 elements and push 1 @@ -1382,12 +1371,7 @@ where WasmOperator::I64Extend16S => sig!((I32) -> (I64)), WasmOperator::I64Extend32S => sig!((I32) -> (I64)), - _ => { - return Err(BinaryReaderError { - message: "Opcode Unimplemented", - offset: -1isize as usize, - }) - } + _ => return Err(Error::Microwasm("Opcode Unimplemented".to_string())), }; Ok(o) } @@ -1414,18 +1398,13 @@ where self.stack.len() as i32 - 1 - idx as i32 } - fn apply_op(&mut self, sig: OpSig) -> Result<(), BinaryReaderError> { + fn apply_op(&mut self, sig: OpSig) -> Result<(), Error> { let mut ty_param = None; for p in sig.input.iter().rev() { let stack_ty = match self.stack.pop() { Some(e) => e, - None => { - return Err(BinaryReaderError { - message: "Stack is empty", - offset: -1isize as usize, - }) - } + None => return Err(Error::Microwasm("Stack is empty".to_string())), }; let ty = match p { @@ -1447,12 +1426,7 @@ where let ty = match p { SigT::T => match ty_param { Some(e) => e, - None => { - return Err(BinaryReaderError { - message: "Type parameter was not set", - offset: -1isize as usize, - }) - } + None => return Err(Error::Microwasm("Type parameter was not set".to_string())), }, SigT::Concrete(ty) => ty, }; @@ -1468,7 +1442,7 @@ where fn block_params_with_wasm_type( &self, ty: wasmparser::TypeOrFuncType, - ) -> Result, BinaryReaderError> { + ) -> Result, Error> { let mut out = self.block_params(); let return_wasm_type = create_returns_from_wasm_type(ty)?; out.extend(return_wasm_type); @@ -1480,9 +1454,9 @@ impl<'a, 'b, M: ModuleContext> Iterator for MicrowasmConv<'a, 'b, M> where for<'any> &'any M::Signature: Into, { - type Item = wasmparser::Result>; + type Item = Result, Error>; - fn next(&mut self) -> Option>> { + fn next(&mut self) -> Option, Error>> { macro_rules! to_drop { ($block:expr) => {{ let block = &$block; @@ -1521,7 +1495,7 @@ where // the removal of uncalled blocks to the backend. return Some(Ok(loop { let op = match self.internal.read() { - Err(e) => return Some(Err(e)), + Err(e) => return Some(Err(e.into())), Ok(o) => o, }; match op { @@ -1535,10 +1509,9 @@ where let block = match self.control_frames.last_mut() { Some(e) => e, None => { - return Some(Err(BinaryReaderError { - message: "unreachable Block else Failed", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "unreachable Block else Failed".to_string(), + ))) } }; @@ -1556,10 +1529,9 @@ where let block = match self.control_frames.pop() { Some(e) => e, None => { - return Some(Err(BinaryReaderError { - message: "unreachable Block end Failed", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "unreachable Block end Failed".to_string(), + ))) } }; @@ -1597,7 +1569,7 @@ where } let op = match self.internal.read() { - Err(e) => return Some(Err(e)), + Err(e) => return Some(Err(e.into())), Ok(o) => o, }; @@ -1699,22 +1671,12 @@ where // We don't pop it since we're still in the second block. let block = match self.control_frames.last() { Some(e) => e, - None => { - return Some(Err(BinaryReaderError { - message: "Block else Failed", - offset: -1isize as usize, - })) - } + None => return Some(Err(Error::Microwasm("Block else Failed".to_string()))), }; let to_drop = to_drop!(block); let block = match self.control_frames.last_mut() { Some(e) => e, - None => { - return Some(Err(BinaryReaderError { - message: "Block else Failed", - offset: -1isize as usize, - })) - } + None => return Some(Err(Error::Microwasm("Block else Failed".to_string()))), }; if let ControlFrameKind::If { has_else, .. } = &mut block.kind { @@ -1738,12 +1700,7 @@ where WasmOperator::End => { let block = match self.control_frames.pop() { Some(e) => e, - None => { - return Some(Err(BinaryReaderError { - message: "Block End Failed", - offset: -1isize as usize, - })) - } + None => return Some(Err(Error::Microwasm("Block End Failed".to_string()))), }; let to_drop = to_drop!(block); @@ -1838,7 +1795,7 @@ where self.unreachable = true; let (entries, default) = match table.read_table() { Ok(o) => o, - Err(e) => return Some(Err(e)), + Err(e) => return Some(Err(e.into())), }; let targets = entries .iter() @@ -1893,10 +1850,9 @@ where let depth = match depth.try_into() { Ok(o) => o, Err(_) => { - return Some(Err(BinaryReaderError { - message: "LocalGet - Local out of range", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "LocalGet - Local out of range".to_string(), + ))) } }; smallvec![Operator::Pick(depth)] @@ -1907,10 +1863,9 @@ where let depth = match depth.try_into() { Ok(o) => o, Err(_) => { - return Some(Err(BinaryReaderError { - message: "LocalSet - Local out of range", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "LocalSet - Local out of range".to_string(), + ))) } }; smallvec![Operator::Swap(depth), Operator::Drop(0..=0)] @@ -1921,10 +1876,9 @@ where let depth = match depth.try_into() { Ok(o) => o, Err(_) => { - return Some(Err(BinaryReaderError { - message: "LocalTee - Local out of range", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "LocalTee - Local out of range".to_string(), + ))) } }; smallvec![ @@ -2044,16 +1998,10 @@ where smallvec![Operator::Const(Value::F64(value.into()))] } WasmOperator::RefNull => { - return Some(Err(BinaryReaderError { - message: "RefNull unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm("RefNull unimplemented".to_string()))) } WasmOperator::RefIsNull => { - return Some(Err(BinaryReaderError { - message: "RefIsNull unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm("RefIsNull unimplemented".to_string()))) } WasmOperator::I32Eqz => smallvec![Operator::Eqz(Size::_32)], WasmOperator::I32Eq => smallvec![Operator::Eq(I32)], @@ -2236,93 +2184,75 @@ where WasmOperator::F32ReinterpretI32 => smallvec![Operator::F32ReinterpretFromI32], WasmOperator::F64ReinterpretI64 => smallvec![Operator::F64ReinterpretFromI64], WasmOperator::I32Extend8S => { - return Some(Err(BinaryReaderError { - message: "I32Extend8S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I32Extend8S unimplemented".to_string(), + ))) } WasmOperator::I32Extend16S => { - return Some(Err(BinaryReaderError { - message: "I32Extend16S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I32Extend16S unimplemented".to_string(), + ))) } WasmOperator::I64Extend8S => { - return Some(Err(BinaryReaderError { - message: "I64Extend8S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I64Extend8S unimplemented".to_string(), + ))) } WasmOperator::I64Extend16S => { - return Some(Err(BinaryReaderError { - message: "I64Extend16S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I64Extend16S unimplemented".to_string(), + ))) } WasmOperator::I64Extend32S => { - return Some(Err(BinaryReaderError { - message: "I64Extend32S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I64Extend32S unimplemented".to_string(), + ))) } // 0xFC operators // Non-trapping Float-to-int Conversions WasmOperator::I32TruncSatF32S => { - return Some(Err(BinaryReaderError { - message: "I32TruncSatF32S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I32TruncSatF32S unimplemented".to_string(), + ))) } WasmOperator::I32TruncSatF32U => { - return Some(Err(BinaryReaderError { - message: "I32TruncSatF32U unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I32TruncSatF32U unimplemented".to_string(), + ))) } WasmOperator::I32TruncSatF64S => { - return Some(Err(BinaryReaderError { - message: "I32TruncSatF64S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I32TruncSatF64S unimplemented".to_string(), + ))) } WasmOperator::I32TruncSatF64U => { - return Some(Err(BinaryReaderError { - message: "I32TruncSatF64U unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I32TruncSatF64U unimplemented".to_string(), + ))) } WasmOperator::I64TruncSatF32S => { - return Some(Err(BinaryReaderError { - message: "I64TruncSatF32S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I64TruncSatF32S unimplemented".to_string(), + ))) } WasmOperator::I64TruncSatF32U => { - return Some(Err(BinaryReaderError { - message: "I64TruncSatF32U unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I64TruncSatF32U unimplemented".to_string(), + ))) } WasmOperator::I64TruncSatF64S => { - return Some(Err(BinaryReaderError { - message: "I64TruncSatF64S unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I64TruncSatF64S unimplemented".to_string(), + ))) } WasmOperator::I64TruncSatF64U => { - return Some(Err(BinaryReaderError { - message: "I64TruncSatF64U unimplemented", - offset: -1isize as usize, - })) + return Some(Err(Error::Microwasm( + "I64TruncSatF64U unimplemented".to_string(), + ))) } - _other => { - return Some(Err(BinaryReaderError { - message: "Opcode unimplemented", - offset: -1isize as usize, - })) - } + _other => return Some(Err(Error::Microwasm("Opcode unimplemented".to_string()))), })) } } diff --git a/crates/misc/py/Cargo.toml b/crates/misc/py/Cargo.toml index 2531b26484..993d33dc73 100644 --- a/crates/misc/py/Cargo.toml +++ b/crates/misc/py/Cargo.toml @@ -23,7 +23,7 @@ wasmtime-wasi = { path = "../../wasi", version = "0.9.0" } target-lexicon = { version = "0.10.0", default-features = false } anyhow = "1.0.19" region = "2.0.0" -wasmparser = "0.47.0" +wasmparser = "0.51.0" pyo3 = { version = "0.8.0", features = ["extension-module"] } [badges]