edition to 2018

This commit is contained in:
NikVolf 2019-04-09 19:10:00 +03:00
parent 0267b20e6e
commit 6e9d2eb8d2
22 changed files with 101 additions and 100 deletions

View File

@ -9,6 +9,7 @@ documentation = "https://paritytech.github.io/wasmi/"
description = "WebAssembly interpreter" description = "WebAssembly interpreter"
keywords = ["wasm", "webassembly", "bytecode", "interpreter"] keywords = ["wasm", "webassembly", "bytecode", "interpreter"]
exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ] exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
edition = "2018"
[features] [features]
default = ["std"] default = ["std"]

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use core::fmt; use core::fmt;
#[cfg(feature = "std")] #[cfg(feature = "std")]

View File

@ -1,15 +1,15 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use alloc::rc::{Rc, Weak}; use crate::alloc::rc::{Rc, Weak};
use core::fmt; use core::fmt;
use host::Externals; use crate::host::Externals;
use isa; use crate::isa;
use module::ModuleInstance; use crate::module::ModuleInstance;
use parity_wasm::elements::Local; use parity_wasm::elements::Local;
use runner::{check_function_args, Interpreter, InterpreterState}; use crate::runner::{check_function_args, Interpreter, InterpreterState};
use types::ValueType; use crate::types::ValueType;
use value::RuntimeValue; use crate::value::RuntimeValue;
use {Signature, Trap}; use crate::{Signature, Trap};
/// Reference to a function (See [`FuncInstance`] for details). /// Reference to a function (See [`FuncInstance`] for details).
/// ///

View File

@ -1,9 +1,9 @@
use alloc::rc::Rc; use crate::alloc::rc::Rc;
use core::cell::Cell; use core::cell::Cell;
use parity_wasm::elements::ValueType as EValueType; use parity_wasm::elements::ValueType as EValueType;
use types::ValueType; use crate::types::ValueType;
use value::RuntimeValue; use crate::value::RuntimeValue;
use Error; use crate::Error;
/// Reference to a global variable (See [`GlobalInstance`] for details). /// Reference to a global variable (See [`GlobalInstance`] for details).
/// ///

View File

@ -1,6 +1,6 @@
use core::any::TypeId; use core::any::TypeId;
use value::{FromRuntimeValue, RuntimeValue}; use crate::value::{FromRuntimeValue, RuntimeValue};
use {Trap, TrapKind}; use crate::{Trap, TrapKind};
/// Wrapper around slice of [`RuntimeValue`] for using it /// Wrapper around slice of [`RuntimeValue`] for using it
/// as an argument list conveniently. /// as an argument list conveniently.
@ -241,7 +241,7 @@ impl Externals for NopExternals {
mod tests { mod tests {
use super::{HostError, RuntimeArgs}; use super::{HostError, RuntimeArgs};
use value::RuntimeValue; use crate::value::RuntimeValue;
#[test] #[test]
fn i32_runtime_args() { fn i32_runtime_args() {

View File

@ -1,18 +1,18 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use hashbrown::HashMap; use hashbrown::HashMap;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::collections::HashMap; use std::collections::HashMap;
use func::FuncRef; use crate::func::FuncRef;
use global::GlobalRef; use crate::global::GlobalRef;
use memory::MemoryRef; use crate::memory::MemoryRef;
use module::ModuleRef; use crate::module::ModuleRef;
use table::TableRef; use crate::table::TableRef;
use types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor}; use crate::types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor};
use {Error, Signature}; use crate::{Error, Signature};
/// Resolver of a module's dependencies. /// Resolver of a module's dependencies.
/// ///

View File

@ -68,7 +68,7 @@
//! //!
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
/// Should we keep a value before "discarding" a stack frame? /// Should we keep a value before "discarding" a stack frame?
/// ///

View File

@ -121,7 +121,7 @@ extern crate memory_units as memory_units_crate;
extern crate parity_wasm; extern crate parity_wasm;
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use core::fmt; use core::fmt;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::error; use std::error;
@ -410,8 +410,8 @@ pub use self::value::{Error as ValueError, FromRuntimeValue, LittleEndianConvert
/// WebAssembly-specific sizes and units. /// WebAssembly-specific sizes and units.
pub mod memory_units { pub mod memory_units {
pub use memory_units_crate::wasm32::*; pub use crate::memory_units_crate::wasm32::*;
pub use memory_units_crate::{size_of, ByteSize, Bytes, RoundUpTo}; pub use crate::memory_units_crate::{size_of, ByteSize, Bytes, RoundUpTo};
} }
/// Deserialized module prepared for instantiation. /// Deserialized module prepared for instantiation.
@ -454,7 +454,7 @@ impl Module {
/// } /// }
/// ``` /// ```
pub fn from_parity_wasm_module(module: parity_wasm::elements::Module) -> Result<Module, Error> { pub fn from_parity_wasm_module(module: parity_wasm::elements::Module) -> Result<Module, Error> {
use validation::{validate_module, ValidatedModule}; use crate::validation::{validate_module, ValidatedModule};
let ValidatedModule { code_map, module } = validate_module(module)?; let ValidatedModule { code_map, module } = validate_module(module)?;
Ok(Module { code_map, module }) Ok(Module { code_map, module })

View File

@ -1,15 +1,15 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use alloc::rc::Rc; use crate::alloc::rc::Rc;
use core::cell::{Cell, RefCell}; use core::cell::{Cell, RefCell};
use core::cmp; use core::cmp;
use core::fmt; use core::fmt;
use core::ops::Range; use core::ops::Range;
use core::u32; use core::u32;
use memory_units::{Bytes, Pages, RoundUpTo}; use crate::memory_units::{Bytes, Pages, RoundUpTo};
use parity_wasm::elements::ResizableLimits; use parity_wasm::elements::ResizableLimits;
use value::LittleEndianConvert; use crate::value::LittleEndianConvert;
use Error; use crate::Error;
/// Size of a page of [linear memory][`MemoryInstance`] - 64KiB. /// Size of a page of [linear memory][`MemoryInstance`] - 64KiB.
/// ///
@ -578,9 +578,9 @@ pub fn validate_memory(initial: Pages, maximum: Option<Pages>) -> Result<(), Str
mod tests { mod tests {
use super::{MemoryInstance, MemoryRef, LINEAR_MEMORY_PAGE_SIZE}; use super::{MemoryInstance, MemoryRef, LINEAR_MEMORY_PAGE_SIZE};
use memory_units::Pages; use crate::memory_units::Pages;
use std::rc::Rc; use std::rc::Rc;
use Error; use crate::Error;
#[test] #[test]
fn alloc() { fn alloc() {
@ -623,7 +623,7 @@ mod tests {
#[test] #[test]
fn ensure_page_size() { fn ensure_page_size() {
use memory_units::ByteSize; use crate::memory_units::ByteSize;
assert_eq!(LINEAR_MEMORY_PAGE_SIZE, Pages::byte_size()); assert_eq!(LINEAR_MEMORY_PAGE_SIZE, Pages::byte_size());
} }

View File

@ -1,27 +1,27 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use alloc::rc::Rc; use crate::alloc::rc::Rc;
use core::cell::RefCell; use core::cell::RefCell;
use core::fmt; use core::fmt;
use Trap; use crate::Trap;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use hashbrown::HashMap; use hashbrown::HashMap;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::collections::HashMap; use std::collections::HashMap;
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; use crate::common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
use core::cell::Ref; use core::cell::Ref;
use func::{FuncBody, FuncInstance, FuncRef}; use crate::func::{FuncBody, FuncInstance, FuncRef};
use global::{GlobalInstance, GlobalRef}; use crate::global::{GlobalInstance, GlobalRef};
use host::Externals; use crate::host::Externals;
use imports::ImportResolver; use crate::imports::ImportResolver;
use memory::MemoryRef; use crate::memory::MemoryRef;
use memory_units::Pages; use crate::memory_units::Pages;
use parity_wasm::elements::{External, InitExpr, Instruction, Internal, ResizableLimits, Type}; use parity_wasm::elements::{External, InitExpr, Instruction, Internal, ResizableLimits, Type};
use table::TableRef; use crate::table::TableRef;
use types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor}; use crate::types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor};
use {Error, MemoryInstance, Module, RuntimeValue, Signature, TableInstance}; use crate::{Error, MemoryInstance, Module, RuntimeValue, Signature, TableInstance};
/// Reference to a [`ModuleInstance`]. /// Reference to a [`ModuleInstance`].
/// ///
@ -785,10 +785,10 @@ pub fn check_limits(limits: &ResizableLimits) -> Result<(), Error> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{ExternVal, ModuleInstance}; use super::{ExternVal, ModuleInstance};
use func::FuncInstance; use crate::func::FuncInstance;
use imports::ImportsBuilder; use crate::imports::ImportsBuilder;
use tests::parse_wat; use crate::tests::parse_wat;
use types::{Signature, ValueType}; use crate::types::{Signature, ValueType};
#[should_panic] #[should_panic]
#[test] #[test]

View File

@ -1,22 +1,22 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; use crate::common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
use core::fmt; use core::fmt;
use core::ops; use core::ops;
use core::{u32, usize}; use core::{u32, usize};
use func::{FuncInstance, FuncInstanceInternal, FuncRef}; use crate::func::{FuncInstance, FuncInstanceInternal, FuncRef};
use host::Externals; use crate::host::Externals;
use isa; use crate::isa;
use memory::MemoryRef; use crate::memory::MemoryRef;
use memory_units::Pages; use crate::memory_units::Pages;
use module::ModuleRef; use crate::module::ModuleRef;
use nan_preserving_float::{F32, F64}; use crate::nan_preserving_float::{F32, F64};
use parity_wasm::elements::Local; use parity_wasm::elements::Local;
use value::{ use crate::value::{
ArithmeticOps, ExtendInto, Float, Integer, LittleEndianConvert, RuntimeValue, TransmuteInto, ArithmeticOps, ExtendInto, Float, Integer, LittleEndianConvert, RuntimeValue, TransmuteInto,
TryTruncateInto, WrapInto, TryTruncateInto, WrapInto,
}; };
use {Signature, Trap, TrapKind, ValueType}; use crate::{Signature, Trap, TrapKind, ValueType};
/// Maximum number of entries in value stack. /// Maximum number of entries in value stack.
pub const DEFAULT_VALUE_STACK_LIMIT: usize = (1024 * 1024) / ::core::mem::size_of::<RuntimeValue>(); pub const DEFAULT_VALUE_STACK_LIMIT: usize = (1024 * 1024) / ::core::mem::size_of::<RuntimeValue>();

View File

@ -1,13 +1,13 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use alloc::rc::Rc; use crate::alloc::rc::Rc;
use core::cell::RefCell; use core::cell::RefCell;
use core::fmt; use core::fmt;
use core::u32; use core::u32;
use func::FuncRef; use crate::func::FuncRef;
use module::check_limits; use crate::module::check_limits;
use parity_wasm::elements::ResizableLimits; use parity_wasm::elements::ResizableLimits;
use Error; use crate::Error;
/// Reference to a table (See [`TableInstance`] for details). /// Reference to a table (See [`TableInstance`] for details).
/// ///

View File

@ -1,7 +1,7 @@
use super::parse_wat; use super::parse_wat;
use memory_units::Pages; use crate::memory_units::Pages;
use types::ValueType; use crate::types::ValueType;
use { use crate::{
Error, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder, MemoryDescriptor, Error, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder, MemoryDescriptor,
MemoryInstance, MemoryRef, ModuleImportResolver, ModuleInstance, ModuleRef, ResumableError, MemoryInstance, MemoryRef, ModuleImportResolver, ModuleInstance, ModuleRef, ResumableError,
RuntimeArgs, RuntimeValue, Signature, TableDescriptor, TableInstance, TableRef, Trap, TrapKind, RuntimeArgs, RuntimeValue, Signature, TableDescriptor, TableInstance, TableRef, Trap, TrapKind,

View File

@ -1,5 +1,5 @@
use wabt; use wabt;
use Module; use crate::Module;
mod host; mod host;
mod wasm; mod wasm;

View File

@ -1,6 +1,6 @@
use memory_units::Pages; use crate::memory_units::Pages;
use std::fs::File; use std::fs::File;
use { use crate::{
Error, FuncRef, GlobalDescriptor, GlobalInstance, GlobalRef, ImportsBuilder, MemoryDescriptor, Error, FuncRef, GlobalDescriptor, GlobalInstance, GlobalRef, ImportsBuilder, MemoryDescriptor,
MemoryInstance, MemoryRef, Module, ModuleImportResolver, ModuleInstance, NopExternals, MemoryInstance, MemoryRef, Module, ModuleImportResolver, ModuleInstance, NopExternals,
RuntimeValue, Signature, TableDescriptor, TableInstance, TableRef, RuntimeValue, Signature, TableDescriptor, TableInstance, TableRef,

View File

@ -1,4 +1,4 @@
use alloc::borrow::Cow; use crate::alloc::borrow::Cow;
use parity_wasm::elements::{ use parity_wasm::elements::{
FunctionType, GlobalType, MemoryType, TableType, ValueType as EValueType, FunctionType, GlobalType, MemoryType, TableType, ValueType as EValueType,

View File

@ -1,9 +1,9 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use parity_wasm::elements::{ use parity_wasm::elements::{
BlockType, FunctionType, GlobalType, MemoryType, TableType, ValueType, BlockType, FunctionType, GlobalType, MemoryType, TableType, ValueType,
}; };
use validation::Error; use crate::validation::Error;
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct ModuleContext { pub struct ModuleContext {

View File

@ -1,15 +1,15 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; use crate::common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
use core::u32; use core::u32;
use parity_wasm::elements::{BlockType, Func, FuncBody, Instruction, TableElementType, ValueType}; use parity_wasm::elements::{BlockType, Func, FuncBody, Instruction, TableElementType, ValueType};
use validation::context::ModuleContext; use crate::validation::context::ModuleContext;
use validation::util::Locals; use crate::validation::util::Locals;
use validation::Error; use crate::validation::Error;
use common::stack::StackWithLimit; use crate::common::stack::StackWithLimit;
use isa; use crate::isa;
/// Maximum number of entries in value stack per function. /// Maximum number of entries in value stack per function.
const DEFAULT_VALUE_STACK_LIMIT: usize = 16384; const DEFAULT_VALUE_STACK_LIMIT: usize = 16384;

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use core::fmt; use core::fmt;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::error; use std::error;
@ -11,9 +11,9 @@ use std::collections::HashSet;
use self::context::ModuleContextBuilder; use self::context::ModuleContextBuilder;
use self::func::FunctionReader; use self::func::FunctionReader;
use common::stack; use crate::common::stack;
use isa; use crate::isa;
use memory_units::Pages; use crate::memory_units::Pages;
use parity_wasm::elements::{ use parity_wasm::elements::{
BlockType, External, GlobalEntry, GlobalType, InitExpr, Instruction, Internal, MemoryType, BlockType, External, GlobalEntry, GlobalType, InitExpr, Instruction, Internal, MemoryType,
Module, ResizableLimits, TableType, Type, ValueType, Module, ResizableLimits, TableType, Type, ValueType,
@ -400,7 +400,7 @@ fn validate_limits(limits: &ResizableLimits) -> Result<(), Error> {
fn validate_memory_type(memory_type: &MemoryType) -> Result<(), Error> { fn validate_memory_type(memory_type: &MemoryType) -> Result<(), Error> {
let initial: Pages = Pages(memory_type.limits().initial() as usize); let initial: Pages = Pages(memory_type.limits().initial() as usize);
let maximum: Option<Pages> = memory_type.limits().maximum().map(|m| Pages(m as usize)); let maximum: Option<Pages> = memory_type.limits().maximum().map(|m| Pages(m as usize));
::memory::validate_memory(initial, maximum).map_err(Error) crate::memory::validate_memory(initial, maximum).map_err(Error)
} }
fn validate_table_type(table_type: &TableType) -> Result<(), Error> { fn validate_table_type(table_type: &TableType) -> Result<(), Error> {

View File

@ -1,5 +1,5 @@
use super::{validate_module, ValidatedModule}; use super::{validate_module, ValidatedModule};
use isa; use crate::isa;
use parity_wasm::builder::module; use parity_wasm::builder::module;
use parity_wasm::elements::{ use parity_wasm::elements::{
deserialize_buffer, BlockType, External, GlobalEntry, GlobalType, ImportEntry, InitExpr, deserialize_buffer, BlockType, External, GlobalEntry, GlobalType, ImportEntry, InitExpr,
@ -299,10 +299,10 @@ fn compile(module: &ValidatedModule) -> (Vec<isa::Instruction>, Vec<u32>) {
macro_rules! targets { macro_rules! targets {
($($target:expr),*) => { ($($target:expr),*) => {
::isa::BrTargets::from_internal( crate::isa::BrTargets::from_internal(
&[$($target,)*] &[$($target,)*]
.iter() .iter()
.map(|&target| ::isa::InstructionInternal::BrTableTarget(target)) .map(|&target| crate::isa::InstructionInternal::BrTableTarget(target))
.collect::<Vec<_>>()[..] .collect::<Vec<_>>()[..]
) )
}; };

View File

@ -1,7 +1,7 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use crate::alloc::prelude::*;
use parity_wasm::elements::{Local, ValueType}; use parity_wasm::elements::{Local, ValueType};
use validation::Error; use crate::validation::Error;
/// Locals are the concatenation of a slice of function parameters /// Locals are the concatenation of a slice of function parameters
/// with function declared local variables. /// with function declared local variables.

View File

@ -1,7 +1,7 @@
use core::{f32, i32, i64, u32, u64}; use core::{f32, i32, i64, u32, u64};
use nan_preserving_float::{F32, F64}; use crate::nan_preserving_float::{F32, F64};
use types::ValueType; use crate::types::ValueType;
use TrapKind; use crate::TrapKind;
/// Error for `LittleEndianConvert` /// Error for `LittleEndianConvert`
#[derive(Debug)] #[derive(Debug)]