From 1d580e308dc549cf8056166722ac93e7b73f858c Mon Sep 17 00:00:00 2001 From: Sergei Pepyakin Date: Fri, 24 Apr 2020 12:07:55 +0200 Subject: [PATCH] Migrate wasmi to edition-2018 (#233) * Migrate wasmi to edition-2018 * fmt * Fix tests. --- Cargo.toml | 7 ++++--- src/func.rs | 14 +++++++------- src/global.rs | 6 +++--- src/host.rs | 6 +++--- src/imports.rs | 15 +++++++-------- src/lib.rs | 9 ++------- src/memory/mod.rs | 10 +++++----- src/module.rs | 36 ++++++++++++++++-------------------- src/prepare/compile.rs | 3 +-- src/prepare/mod.rs | 7 ++----- src/prepare/tests.rs | 6 +++--- src/runner.rs | 24 ++++++++++++------------ src/table.rs | 6 +++--- src/tests/host.rs | 6 +++--- src/tests/mod.rs | 2 +- src/tests/wasm.rs | 6 +++--- src/value.rs | 6 +++--- 17 files changed, 78 insertions(+), 91 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7f9d295538..4084fbcc28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "wasmi" version = "0.6.2" +edition = "2018" authors = ["Nikolay Volf ", "Svyatoslav Nikolsky ", "Sergey Pepyakin "] license = "MIT/Apache-2.0" readme = "README.md" @@ -11,7 +12,7 @@ keywords = ["wasm", "webassembly", "bytecode", "interpreter"] exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ] [dependencies] -wasmi-validation = { version = "0.3", path = "validation", default-features = false } +validation = { package = "wasmi-validation", version = "0.3", path = "validation", default-features = false } parity-wasm = { version = "0.41.0", default-features = false } memory_units = "0.3.0" libm = { version = "0.1.2", optional = true } @@ -30,7 +31,7 @@ default = ["std"] # Disable for no_std support std = [ "parity-wasm/std", - "wasmi-validation/std", + "validation/std", "num-rational/std", "num-rational/bigint-std", "num-traits/std", @@ -40,7 +41,7 @@ std = [ core = [ # `core` doesn't support vec_memory "vec_memory", - "wasmi-validation/core", + "validation/core", "libm" ] # Enforce using the linear memory implementation based on `Vec` instead of diff --git a/src/func.rs b/src/func.rs index 43ae34d27b..4c9d9dda5c 100644 --- a/src/func.rs +++ b/src/func.rs @@ -1,17 +1,17 @@ +use crate::host::Externals; +use crate::isa; +use crate::module::ModuleInstance; +use crate::runner::{check_function_args, Interpreter, InterpreterState, StackRecycler}; +use crate::types::ValueType; +use crate::value::RuntimeValue; +use crate::{Signature, Trap}; use alloc::{ borrow::Cow, rc::{Rc, Weak}, vec::Vec, }; use core::fmt; -use host::Externals; -use isa; -use module::ModuleInstance; use parity_wasm::elements::Local; -use runner::{check_function_args, Interpreter, InterpreterState, StackRecycler}; -use types::ValueType; -use value::RuntimeValue; -use {Signature, Trap}; /// Reference to a function (See [`FuncInstance`] for details). /// diff --git a/src/global.rs b/src/global.rs index cde0d63784..428809ff2e 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1,9 +1,9 @@ +use crate::types::ValueType; +use crate::value::RuntimeValue; +use crate::Error; use alloc::rc::Rc; use core::cell::Cell; use parity_wasm::elements::ValueType as EValueType; -use types::ValueType; -use value::RuntimeValue; -use Error; /// Reference to a global variable (See [`GlobalInstance`] for details). /// diff --git a/src/host.rs b/src/host.rs index 352a68b0f0..54e9b6070b 100644 --- a/src/host.rs +++ b/src/host.rs @@ -1,6 +1,6 @@ +use crate::value::{FromRuntimeValue, RuntimeValue}; +use crate::{Trap, TrapKind}; use core::any::TypeId; -use value::{FromRuntimeValue, RuntimeValue}; -use {Trap, TrapKind}; /// Wrapper around slice of [`RuntimeValue`] for using it /// as an argument list conveniently. @@ -241,7 +241,7 @@ impl Externals for NopExternals { mod tests { use super::{HostError, RuntimeArgs}; - use value::RuntimeValue; + use crate::value::RuntimeValue; #[test] fn i32_runtime_args() { diff --git a/src/imports.rs b/src/imports.rs index 17f7a42255..be07dfbc22 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -1,13 +1,12 @@ +use crate::func::FuncRef; +use crate::global::GlobalRef; +use crate::memory::MemoryRef; +use crate::module::ModuleRef; +use crate::table::TableRef; +use crate::types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor}; +use crate::{Error, Signature}; use alloc::{collections::BTreeMap, string::String}; -use func::FuncRef; -use global::GlobalRef; -use memory::MemoryRef; -use module::ModuleRef; -use table::TableRef; -use types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor}; -use {Error, Signature}; - /// Resolver of a module's dependencies. /// /// A module have dependencies in a form of a list of imports (i.e. diff --git a/src/lib.rs b/src/lib.rs index 610723f8fc..3973ed6ad2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,11 +112,6 @@ extern crate assert_matches; #[cfg(test)] extern crate wabt; -extern crate memory_units as memory_units_crate; -extern crate parity_wasm; - -extern crate wasmi_validation as validation; - use alloc::{ boxed::Box, string::{String, ToString}, @@ -413,8 +408,8 @@ pub use self::value::{Error as ValueError, FromRuntimeValue, LittleEndianConvert /// WebAssembly-specific sizes and units. pub mod memory_units { - pub use memory_units_crate::wasm32::*; - pub use memory_units_crate::{size_of, ByteSize, Bytes, RoundUpTo}; + pub use memory_units::wasm32::*; + pub use memory_units::{size_of, ByteSize, Bytes, RoundUpTo}; } /// Deserialized module prepared for instantiation. diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 074644d930..696117cb35 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -1,3 +1,6 @@ +use crate::memory_units::{Bytes, Pages, RoundUpTo}; +use crate::value::LittleEndianConvert; +use crate::Error; use alloc::{rc::Rc, string::ToString, vec::Vec}; use core::{ cell::{Cell, RefCell}, @@ -5,10 +8,7 @@ use core::{ ops::Range, u32, }; -use memory_units::{Bytes, Pages, RoundUpTo}; use parity_wasm::elements::ResizableLimits; -use value::LittleEndianConvert; -use Error; #[cfg(all(unix, not(feature = "vec_memory")))] #[path = "mmap_bytebuf.rs"] @@ -540,9 +540,9 @@ impl MemoryInstance { mod tests { use super::{MemoryInstance, MemoryRef, LINEAR_MEMORY_PAGE_SIZE}; - use memory_units::Pages; + use crate::memory_units::Pages; + use crate::Error; use std::rc::Rc; - use Error; #[test] fn alloc() { diff --git a/src/module.rs b/src/module.rs index 80526ede45..033bccbfe2 100644 --- a/src/module.rs +++ b/src/module.rs @@ -1,28 +1,24 @@ +use crate::func::{FuncBody, FuncInstance, FuncRef}; +use crate::global::{GlobalInstance, GlobalRef}; +use crate::host::Externals; +use crate::imports::ImportResolver; +use crate::memory::MemoryRef; +use crate::memory_units::Pages; +use crate::runner::StackRecycler; +use crate::table::TableRef; +use crate::types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor}; +use crate::{Error, MemoryInstance, Module, RuntimeValue, Signature, TableInstance, Trap}; +use alloc::collections::BTreeMap; use alloc::{ borrow::ToOwned, rc::Rc, string::{String, ToString}, vec::Vec, }; -use core::cell::RefCell; +use core::cell::{Ref, RefCell}; use core::fmt; -use Trap; - -use alloc::collections::BTreeMap; - -use core::cell::Ref; -use func::{FuncBody, FuncInstance, FuncRef}; -use global::{GlobalInstance, GlobalRef}; -use host::Externals; -use imports::ImportResolver; -use memory::MemoryRef; -use memory_units::Pages; use parity_wasm::elements::{External, InitExpr, Instruction, Internal, ResizableLimits, Type}; -use runner::StackRecycler; -use table::TableRef; -use types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor}; use validation::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; -use {Error, MemoryInstance, Module, RuntimeValue, Signature, TableInstance}; /// Reference to a [`ModuleInstance`]. /// @@ -816,10 +812,10 @@ pub fn check_limits(limits: &ResizableLimits) -> Result<(), Error> { #[cfg(test)] mod tests { use super::{ExternVal, ModuleInstance}; - use func::FuncInstance; - use imports::ImportsBuilder; - use tests::parse_wat; - use types::{Signature, ValueType}; + use crate::func::FuncInstance; + use crate::imports::ImportsBuilder; + use crate::tests::parse_wat; + use crate::types::{Signature, ValueType}; #[should_panic] #[test] diff --git a/src/prepare/compile.rs b/src/prepare/compile.rs index cf33a7e6f8..17a7d4d974 100644 --- a/src/prepare/compile.rs +++ b/src/prepare/compile.rs @@ -2,6 +2,7 @@ use alloc::{string::String, vec::Vec}; use parity_wasm::elements::{BlockType, FuncBody, Instruction}; +use crate::isa; use validation::func::{ require_label, top_label, BlockFrame, FunctionValidationContext, StackValueType, StartedWith, }; @@ -9,8 +10,6 @@ use validation::stack::StackWithLimit; use validation::util::Locals; use validation::{Error, FuncValidator}; -use isa; - /// Type of block frame. #[derive(Debug, Clone, Copy)] enum BlockFrameType { diff --git a/src/prepare/mod.rs b/src/prepare/mod.rs index f0d4d342bf..7820197e6f 100644 --- a/src/prepare/mod.rs +++ b/src/prepare/mod.rs @@ -1,10 +1,7 @@ +use crate::isa; use alloc::vec::Vec; - -use crate::{ - isa, - validation::{validate_module, Error, Validator}, -}; use parity_wasm::elements::Module; +use validation::{validate_module, Error, Validator}; mod compile; diff --git a/src/prepare/tests.rs b/src/prepare/tests.rs index 9f9faeb330..b31aa208f3 100644 --- a/src/prepare/tests.rs +++ b/src/prepare/tests.rs @@ -1,7 +1,7 @@ use super::{compile_module, CompiledModule}; +use crate::isa; use parity_wasm::{deserialize_buffer, elements::Module}; -use isa; use wabt; fn validate(wat: &str) -> CompiledModule { @@ -31,10 +31,10 @@ fn compile(module: &CompiledModule) -> (Vec, Vec) { macro_rules! targets { ($($target:expr),*) => { - ::isa::BrTargets::from_internal( + crate::isa::BrTargets::from_internal( &[$($target,)*] .iter() - .map(|&target| ::isa::InstructionInternal::BrTableTarget(target)) + .map(|&target| crate::isa::InstructionInternal::BrTableTarget(target)) .collect::>()[..] ) }; diff --git a/src/runner.rs b/src/runner.rs index 41e11b4cc1..db21fd897e 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -1,21 +1,21 @@ +use crate::func::{FuncInstance, FuncInstanceInternal, FuncRef}; +use crate::host::Externals; +use crate::isa; +use crate::memory::MemoryRef; +use crate::memory_units::Pages; +use crate::module::ModuleRef; +use crate::nan_preserving_float::{F32, F64}; +use crate::value::{ + ArithmeticOps, ExtendInto, Float, Integer, LittleEndianConvert, RuntimeValue, TransmuteInto, + TryTruncateInto, WrapInto, +}; +use crate::{Signature, Trap, TrapKind, ValueType}; use alloc::{boxed::Box, vec::Vec}; use core::fmt; use core::ops; use core::{u32, usize}; -use func::{FuncInstance, FuncInstanceInternal, FuncRef}; -use host::Externals; -use isa; -use memory::MemoryRef; -use memory_units::Pages; -use module::ModuleRef; -use nan_preserving_float::{F32, F64}; use parity_wasm::elements::Local; use validation::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; -use value::{ - ArithmeticOps, ExtendInto, Float, Integer, LittleEndianConvert, RuntimeValue, TransmuteInto, - TryTruncateInto, WrapInto, -}; -use {Signature, Trap, TrapKind, ValueType}; /// Maximum number of bytes on the value stack. pub const DEFAULT_VALUE_STACK_LIMIT: usize = 1024 * 1024; diff --git a/src/table.rs b/src/table.rs index 479912ba52..38a1599743 100644 --- a/src/table.rs +++ b/src/table.rs @@ -1,11 +1,11 @@ +use crate::func::FuncRef; +use crate::module::check_limits; +use crate::Error; use alloc::{rc::Rc, vec::Vec}; use core::cell::RefCell; use core::fmt; use core::u32; -use func::FuncRef; -use module::check_limits; use parity_wasm::elements::ResizableLimits; -use Error; /// Reference to a table (See [`TableInstance`] for details). /// diff --git a/src/tests/host.rs b/src/tests/host.rs index b7c515f8e2..02ac10469b 100644 --- a/src/tests/host.rs +++ b/src/tests/host.rs @@ -1,7 +1,7 @@ use super::parse_wat; -use memory_units::Pages; -use types::ValueType; -use { +use crate::memory_units::Pages; +use crate::types::ValueType; +use crate::{ Error, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder, MemoryDescriptor, MemoryInstance, MemoryRef, ModuleImportResolver, ModuleInstance, ModuleRef, ResumableError, RuntimeArgs, RuntimeValue, Signature, TableDescriptor, TableInstance, TableRef, Trap, TrapKind, diff --git a/src/tests/mod.rs b/src/tests/mod.rs index a60ce73666..68d6c8e05b 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,5 +1,5 @@ +use crate::Module; use wabt; -use Module; mod host; mod wasm; diff --git a/src/tests/wasm.rs b/src/tests/wasm.rs index 07efa517f6..26ed966da0 100644 --- a/src/tests/wasm.rs +++ b/src/tests/wasm.rs @@ -1,10 +1,10 @@ -use memory_units::Pages; -use std::fs::File; -use { +use crate::memory_units::Pages; +use crate::{ Error, FuncRef, GlobalDescriptor, GlobalInstance, GlobalRef, ImportsBuilder, MemoryDescriptor, MemoryInstance, MemoryRef, Module, ModuleImportResolver, ModuleInstance, NopExternals, RuntimeValue, Signature, TableDescriptor, TableInstance, TableRef, }; +use std::fs::File; struct Env { table_base: GlobalRef, diff --git a/src/value.rs b/src/value.rs index 7d8fea9a63..60e5f83045 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,7 +1,7 @@ +use crate::nan_preserving_float::{F32, F64}; +use crate::types::ValueType; +use crate::TrapKind; use core::{f32, i32, i64, u32, u64}; -use nan_preserving_float::{F32, F64}; -use types::ValueType; -use TrapKind; /// Error for `LittleEndianConvert` #[derive(Debug)]