Skip to content

Commit

Permalink
Clean-up Wasmi engine imports and exports (#1228)
Browse files Browse the repository at this point in the history
* clean-up Wasmi engine imports and exports

* fix doc test imports

* apply rustfmt
  • Loading branch information
Robbepop authored Oct 6, 2024
1 parent 4e3569c commit 242e5e9
Show file tree
Hide file tree
Showing 59 changed files with 154 additions and 192 deletions.
6 changes: 2 additions & 4 deletions crates/wasmi/src/engine/code_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ use super::{
use crate::{
collections::arena::{Arena, ArenaIndex},
core::{TrapCode, UntypedVal},
engine::{
bytecode::{index::InternalFunc, Instruction},
utils::unreachable_unchecked,
},
engine::utils::unreachable_unchecked,
ir::{index::InternalFunc, Instruction},
module::{FuncIdx, ModuleHeader},
store::{Fuel, FuelError},
Config,
Expand Down
3 changes: 2 additions & 1 deletion crates/wasmi/src/engine/executor/cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
core::UntypedVal,
engine::{bytecode::index, DedupFuncType},
engine::DedupFuncType,
instance::InstanceEntity,
ir::index,
memory::DataSegment,
module::DEFAULT_MEMORY_INDEX,
store::StoreInner,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/executor/instr_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::engine::bytecode::Instruction;
use crate::ir::Instruction;

/// The instruction pointer to the instruction of a function on the call stack.
#[derive(Debug, Copy, Clone)]
Expand Down
3 changes: 1 addition & 2 deletions crates/wasmi/src/engine/executor/instrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use super::{cache::CachedInstance, InstructionPtr, Stack};
use crate::{
core::{hint, TrapCode, UntypedVal},
engine::{
bytecode::{index, BlockFuel, Const16, Instruction, Reg},
code_map::CodeMap,
executor::stack::{CallFrame, FrameRegisters, ValueStack},
utils::unreachable_unchecked,
DedupFuncType,
EngineFunc,
},
ir::ShiftAmount,
ir::{index, BlockFuel, Const16, Instruction, Reg, ShiftAmount},
memory::DataSegment,
store::StoreInner,
table::ElementSegment,
Expand Down
5 changes: 2 additions & 3 deletions crates/wasmi/src/engine/executor/instrs/binary.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use super::{Executor, UntypedValueExt};
use crate::{
core::{TrapCode, UntypedVal},
engine::bytecode::{Const16, Reg, Sign},
ir::ShiftAmount,
ir::{Const16, Reg, ShiftAmount, Sign},
Error,
};
use core::num::{NonZeroI32, NonZeroI64, NonZeroU32, NonZeroU64};

#[cfg(doc)]
use crate::engine::bytecode::Instruction;
use crate::ir::Instruction;

macro_rules! impl_binary {
( $( (Instruction::$var_name:ident, $fn_name:ident, $op:expr) ),* $(,)? ) => {
Expand Down
20 changes: 9 additions & 11 deletions crates/wasmi/src/engine/executor/instrs/branch.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use super::Executor;
use crate::{
core::UntypedVal,
engine::{
bytecode::{
BranchOffset,
BranchOffset16,
Comparator,
ComparatorAndOffset,
Const16,
Instruction,
Reg,
},
utils::unreachable_unchecked,
engine::utils::unreachable_unchecked,
ir::{
BranchOffset,
BranchOffset16,
Comparator,
ComparatorAndOffset,
Const16,
Instruction,
Reg,
},
};
use core::cmp;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/executor/instrs/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use super::{Executor, InstructionPtr};
use crate::{
core::TrapCode,
engine::{
bytecode::{index, Instruction, Reg, RegSpan},
code_map::CompiledFuncRef,
executor::stack::{CallFrame, FrameParams, ValueStack},
utils::unreachable_unchecked,
EngineFunc,
FuncParams,
},
func::{FuncEntity, HostFuncEntity},
ir::{index, Instruction, Reg, RegSpan},
store::StoreInner,
CallHook,
Error,
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/executor/instrs/comparison.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::Executor;
use crate::{
core::UntypedVal,
engine::bytecode::{Const16, Reg},
ir::{Const16, Reg},
};

#[cfg(doc)]
use crate::engine::bytecode::Instruction;
use crate::ir::Instruction;

macro_rules! impl_comparison {
( $( (Instruction::$var_name:ident, $fn_name:ident, $op:expr) ),* $(,)? ) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/executor/instrs/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::Executor;
use crate::{core::UntypedVal, engine::bytecode::Reg, Error};
use crate::{core::UntypedVal, ir::Reg, Error};

#[cfg(doc)]
use crate::engine::bytecode::Instruction;
use crate::ir::Instruction;

macro_rules! impl_conversion_impls {
( $( (Instruction::$var_name:ident, $fn_name:ident, $op:expr) ),* $(,)? ) => {
Expand Down
6 changes: 2 additions & 4 deletions crates/wasmi/src/engine/executor/instrs/copy.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::{Executor, InstructionPtr};
use crate::{
core::UntypedVal,
engine::{
bytecode::{AnyConst32, Const32, FixedRegSpan, Instruction, Reg, RegSpan},
utils::unreachable_unchecked,
},
engine::utils::unreachable_unchecked,
ir::{AnyConst32, Const32, FixedRegSpan, Instruction, Reg, RegSpan},
};
use core::slice;
use smallvec::SmallVec;
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/executor/instrs/global.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::Executor;
use crate::{
core::{hint, UntypedVal},
engine::bytecode::{index, Const16, Reg},
ir::{index, Const16, Reg},
store::StoreInner,
};

#[cfg(doc)]
use crate::engine::bytecode::Instruction;
use crate::ir::Instruction;

impl Executor<'_> {
/// Executes an [`Instruction::GlobalGet`].
Expand Down
8 changes: 2 additions & 6 deletions crates/wasmi/src/engine/executor/instrs/load.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use super::Executor;
use crate::{
core::{TrapCode, UntypedVal},
engine::{
bytecode::{Const16, Reg},
executor::instr_ptr::InstructionPtr,
utils::unreachable_unchecked,
},
ir::{index::Memory, Instruction},
engine::{executor::instr_ptr::InstructionPtr, utils::unreachable_unchecked},
ir::{index::Memory, Const16, Instruction, Reg},
store::StoreInner,
Error,
};
Expand Down
12 changes: 7 additions & 5 deletions crates/wasmi/src/engine/executor/instrs/memory.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use super::{Executor, InstructionPtr};
use crate::{
core::TrapCode,
engine::{
bytecode::{index::Data, Const16, Instruction, Reg},
utils::unreachable_unchecked,
},
engine::utils::unreachable_unchecked,
error::EntityGrowError,
ir::index::Memory,
ir::{
index::{Data, Memory},
Const16,
Instruction,
Reg,
},
store::{ResourceLimiterRef, StoreInner},
Error,
Store,
Expand Down
7 changes: 2 additions & 5 deletions crates/wasmi/src/engine/executor/instrs/return_.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use super::{Executor, InstructionPtr};
use crate::{
core::UntypedVal,
engine::{
bytecode::{AnyConst32, BoundedRegSpan, Const32, Instruction, Reg, RegSpan},
executor::stack::FrameRegisters,
utils::unreachable_unchecked,
},
engine::{executor::stack::FrameRegisters, utils::unreachable_unchecked},
ir::{AnyConst32, BoundedRegSpan, Const32, Instruction, Reg, RegSpan},
store::StoreInner,
};
use core::slice;
Expand Down
6 changes: 2 additions & 4 deletions crates/wasmi/src/engine/executor/instrs/select.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::{Executor, InstructionPtr};
use crate::{
core::UntypedVal,
engine::{
bytecode::{AnyConst32, Const32, Instruction, Reg},
utils::unreachable_unchecked,
},
engine::utils::unreachable_unchecked,
ir::{AnyConst32, Const32, Instruction, Reg},
};

impl<'engine> Executor<'engine> {
Expand Down
7 changes: 2 additions & 5 deletions crates/wasmi/src/engine/executor/instrs/store.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use super::{Executor, InstructionPtr};
use crate::{
core::{TrapCode, UntypedVal},
engine::{
bytecode::{Const16, Instruction, Reg},
utils::unreachable_unchecked,
},
ir::{index::Memory, AnyConst16},
engine::utils::unreachable_unchecked,
ir::{index::Memory, AnyConst16, Const16, Instruction, Reg},
store::StoreInner,
Error,
};
Expand Down
16 changes: 7 additions & 9 deletions crates/wasmi/src/engine/executor/instrs/table.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use super::{Executor, InstructionPtr};
use crate::{
core::TrapCode,
engine::{
bytecode::{
index::{Elem, Table},
Const16,
Instruction,
Reg,
},
utils::unreachable_unchecked,
},
engine::utils::unreachable_unchecked,
error::EntityGrowError,
ir::{
index::{Elem, Table},
Const16,
Instruction,
Reg,
},
store::{ResourceLimiterRef, StoreInner},
table::TableEntity,
Error,
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/executor/instrs/unary.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::Executor;
use crate::{core::UntypedVal, engine::bytecode::Reg};
use crate::{core::UntypedVal, ir::Reg};

#[cfg(doc)]
use crate::engine::bytecode::Instruction;
use crate::ir::Instruction;

macro_rules! impl_unary_impls {
( $( (Instruction::$var_name:ident, $fn_name:ident, $op:expr) ),* $(,)? ) => {
Expand Down
10 changes: 2 additions & 8 deletions crates/wasmi/src/engine/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ use self::{
stack::CallFrame,
};
use crate::{
engine::{
bytecode::{Reg, RegSpan},
CallParams,
CallResults,
EngineInner,
ResumableCallBase,
ResumableInvocation,
},
engine::{CallParams, CallResults, EngineInner, ResumableCallBase, ResumableInvocation},
func::HostFuncEntity,
ir::{Reg, RegSpan},
CallHook,
Error,
Func,
Expand Down
7 changes: 4 additions & 3 deletions crates/wasmi/src/engine/executor/stack/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ use super::{err_stack_overflow, BaseValueStackOffset, FrameValueStackOffset};
use crate::{
collections::HeadVec,
core::TrapCode,
engine::{bytecode::RegSpan, executor::InstructionPtr},
engine::executor::InstructionPtr,
ir::RegSpan,
Instance,
};
use std::vec::Vec;

#[cfg(doc)]
use crate::{
engine::bytecode::Instruction,
engine::bytecode::Reg,
engine::executor::stack::ValueStack,
engine::EngineFunc,
ir::Instruction,
ir::Reg,
Global,
Memory,
Table,
Expand Down
3 changes: 2 additions & 1 deletion crates/wasmi/src/engine/executor/stack/values.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::{err_stack_overflow, StackOffsets};
use crate::{
core::{TrapCode, UntypedVal},
engine::{bytecode::Reg, code_map::CompiledFuncRef},
engine::code_map::CompiledFuncRef,
ir::Reg,
};
use core::{
fmt::{self, Debug},
Expand Down
12 changes: 2 additions & 10 deletions crates/wasmi/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ mod utils;
mod tests;

#[cfg(test)]
use self::bytecode::RegSpan;

use self::code_map::CompiledFuncRef;
#[cfg(test)]
use code_map::CompiledFuncRef;
use crate::{core::UntypedVal, ir::Instruction, ir::RegSpan};

pub(crate) use self::{
block_type::BlockType,
Expand Down Expand Up @@ -50,7 +49,6 @@ pub use self::{
traits::{CallParams, CallResults},
translator::{Instr, TranslationError},
};
pub(crate) use crate::ir as bytecode;
use crate::{
collections::arena::{ArenaIndex, GuardedEntity},
module::{FuncIdx, ModuleHeader},
Expand All @@ -67,12 +65,6 @@ use std::{
};
use wasmparser::{FuncToValidate, FuncValidatorAllocations, ValidatorResources};

#[cfg(test)]
use self::bytecode::Instruction;

#[cfg(test)]
use crate::core::UntypedVal;

#[cfg(doc)]
use crate::Store;

Expand Down
13 changes: 11 additions & 2 deletions crates/wasmi/src/engine/resumable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use super::{bytecode::RegSpan, Func};
use crate::{engine::Stack, func::CallResultsTuple, AsContextMut, Engine, Error, Val, WasmResults};
use super::Func;
use crate::{
engine::Stack,
func::CallResultsTuple,
ir::RegSpan,
AsContextMut,
Engine,
Error,
Val,
WasmResults,
};
use core::{fmt, marker::PhantomData, mem::replace, ops::Deref};

/// Returned by [`Engine`] methods for calling a function in a resumable way.
Expand Down
8 changes: 2 additions & 6 deletions crates/wasmi/src/engine/translator/control_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ use super::LabelRef;
#[cfg(doc)]
use super::ValueStack;
use crate::{
engine::{
bytecode::{BoundedRegSpan, RegSpan},
BlockType,
Instr,
TranslationError,
},
engine::{BlockType, Instr, TranslationError},
ir::{BoundedRegSpan, RegSpan},
Engine,
Error,
};
Expand Down
Loading

0 comments on commit 242e5e9

Please sign in to comment.