Skip to content

Commit

Permalink
Migrate wasmi to edition-2018 (wasmi-labs#233)
Browse files Browse the repository at this point in the history
* Migrate wasmi to edition-2018

* fmt

* Fix tests.
  • Loading branch information
pepyakin authored Apr 24, 2020
1 parent 39a18a4 commit 1d580e3
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 91 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "wasmi"
version = "0.6.2"
edition = "2018"
authors = ["Nikolay Volf <[email protected]>", "Svyatoslav Nikolsky <[email protected]>", "Sergey Pepyakin <[email protected]>"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand All @@ -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 }
Expand All @@ -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",
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/func.rs
Original file line number Diff line number Diff line change
@@ -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).
///
Expand Down
6 changes: 3 additions & 3 deletions src/global.rs
Original file line number Diff line number Diff line change
@@ -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).
///
Expand Down
6 changes: 3 additions & 3 deletions src/host.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
15 changes: 7 additions & 8 deletions src/imports.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/memory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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},
cmp, fmt,
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"]
Expand Down Expand Up @@ -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() {
Expand Down
36 changes: 16 additions & 20 deletions src/module.rs
Original file line number Diff line number Diff line change
@@ -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`].
///
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions src/prepare/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ 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,
};
use validation::stack::StackWithLimit;
use validation::util::Locals;
use validation::{Error, FuncValidator};

use isa;

/// Type of block frame.
#[derive(Debug, Clone, Copy)]
enum BlockFrameType {
Expand Down
7 changes: 2 additions & 5 deletions src/prepare/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/prepare/tests.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -31,10 +31,10 @@ fn compile(module: &CompiledModule) -> (Vec<isa::Instruction>, Vec<u32>) {

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::<Vec<_>>()[..]
)
};
Expand Down
24 changes: 12 additions & 12 deletions src/runner.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/table.rs
Original file line number Diff line number Diff line change
@@ -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).
///
Expand Down
6 changes: 3 additions & 3 deletions src/tests/host.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Module;
use wabt;
use Module;

mod host;
mod wasm;
Expand Down
6 changes: 3 additions & 3 deletions src/tests/wasm.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/value.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down

0 comments on commit 1d580e3

Please sign in to comment.