Skip to content

Commit

Permalink
Improve imports formatting (wasmi-labs#289)
Browse files Browse the repository at this point in the history
* rustfmt: use imports_granualarity = "Crate"

* apply rustfmt: imports_granularity = "Crate"

* rustfmt: use imports_layout = "HorizontalVertical"

* rustfmt: apply imports_layout = "HorizontalVertical"

* use nightly rustfmt toolchain in GitHub Actions CI
  • Loading branch information
Robbepop authored Dec 24, 2021
1 parent dfd1eed commit aea0581
Show file tree
Hide file tree
Showing 27 changed files with 280 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
toolchain: nightly
override: true
components: rustfmt
- uses: actions-rs/cargo@v1
Expand Down
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
imports_granularity = "Crate"
imports_layout = "HorizontalVertical"
edition = "2021"
3 changes: 1 addition & 2 deletions benches/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::env;
use std::process;
use std::{env, process};

fn main() {
println!("cargo:rerun-if-changed=./wasm-kernel/");
Expand Down
3 changes: 1 addition & 2 deletions examples/interpret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

extern crate wasmi;

use std::env::args;
use std::fs::File;
use std::{env::args, fs::File};
use wasmi::{ImportsBuilder, Module, ModuleInstance, NopExternals, RuntimeValue};

fn load_from_file(filename: &str) -> Module {
Expand Down
19 changes: 14 additions & 5 deletions examples/tictactoe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
extern crate parity_wasm;
extern crate wasmi;

use std::env;
use std::fmt;
use std::fs::File;
use std::{env, fmt, fs::File};
use wasmi::{
Error as InterpreterError, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder,
ModuleImportResolver, ModuleInstance, ModuleRef, RuntimeArgs, RuntimeValue, Signature, Trap,
Error as InterpreterError,
Externals,
FuncInstance,
FuncRef,
HostError,
ImportsBuilder,
ModuleImportResolver,
ModuleInstance,
ModuleRef,
RuntimeArgs,
RuntimeValue,
Signature,
Trap,
ValueType,
};

Expand Down
27 changes: 21 additions & 6 deletions src/bin/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@
extern crate wasmi;

use std::env::args;
use std::fs::File;
use wasmi::memory_units::*;
use std::{env::args, fs::File};
use wasmi::{
Error, FuncInstance, FuncRef, GlobalDescriptor, GlobalInstance, GlobalRef, ImportsBuilder,
MemoryDescriptor, MemoryInstance, MemoryRef, Module, ModuleImportResolver, ModuleInstance,
NopExternals, RuntimeValue, Signature, TableDescriptor, TableInstance, TableRef,
memory_units::*,
Error,
FuncInstance,
FuncRef,
GlobalDescriptor,
GlobalInstance,
GlobalRef,
ImportsBuilder,
MemoryDescriptor,
MemoryInstance,
MemoryRef,
Module,
ModuleImportResolver,
ModuleInstance,
NopExternals,
RuntimeValue,
Signature,
TableDescriptor,
TableInstance,
TableRef,
};

fn load_from_file(filename: &str) -> Module {
Expand Down
17 changes: 10 additions & 7 deletions src/func.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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 crate::{
host::Externals,
isa,
module::ModuleInstance,
runner::{check_function_args, Interpreter, InterpreterState, StackRecycler},
types::ValueType,
value::RuntimeValue,
Signature,
Trap,
};
use alloc::{
borrow::Cow,
rc::{Rc, Weak},
Expand Down
4 changes: 1 addition & 3 deletions src/global.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::types::ValueType;
use crate::value::RuntimeValue;
use crate::Error;
use crate::{types::ValueType, value::RuntimeValue, Error};
use alloc::rc::Rc;
use core::cell::Cell;
use parity_wasm::elements::ValueType as EValueType;
Expand Down
7 changes: 5 additions & 2 deletions src/host.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::value::{FromRuntimeValue, RuntimeValue};
use crate::{Trap, TrapKind};
use crate::{
value::{FromRuntimeValue, RuntimeValue},
Trap,
TrapKind,
};

use downcast_rs::{impl_downcast, DowncastSync};

Expand Down
17 changes: 10 additions & 7 deletions src/imports.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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 crate::{
func::FuncRef,
global::GlobalRef,
memory::MemoryRef,
module::ModuleRef,
table::TableRef,
types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor},
Error,
Signature,
};
use alloc::{collections::BTreeMap, string::String};

/// Resolver of a module's dependencies.
Expand Down
25 changes: 13 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,21 +423,22 @@ mod value;
#[cfg(test)]
mod tests;

pub use self::func::{FuncInstance, FuncInvocation, FuncRef, ResumableError};
pub use self::global::{GlobalInstance, GlobalRef};
pub use self::host::{Externals, HostError, NopExternals, RuntimeArgs};
pub use self::imports::{ImportResolver, ImportsBuilder, ModuleImportResolver};
pub use self::memory::{MemoryInstance, MemoryRef, LINEAR_MEMORY_PAGE_SIZE};
pub use self::module::{ExternVal, ModuleInstance, ModuleRef, NotStartedModuleRef};
pub use self::runner::{StackRecycler, DEFAULT_CALL_STACK_LIMIT, DEFAULT_VALUE_STACK_LIMIT};
pub use self::table::{TableInstance, TableRef};
pub use self::types::{GlobalDescriptor, MemoryDescriptor, Signature, TableDescriptor, ValueType};
pub use self::value::{Error as ValueError, FromRuntimeValue, LittleEndianConvert, RuntimeValue};
pub use self::{
func::{FuncInstance, FuncInvocation, FuncRef, ResumableError},
global::{GlobalInstance, GlobalRef},
host::{Externals, HostError, NopExternals, RuntimeArgs},
imports::{ImportResolver, ImportsBuilder, ModuleImportResolver},
memory::{MemoryInstance, MemoryRef, LINEAR_MEMORY_PAGE_SIZE},
module::{ExternVal, ModuleInstance, ModuleRef, NotStartedModuleRef},
runner::{StackRecycler, DEFAULT_CALL_STACK_LIMIT, DEFAULT_VALUE_STACK_LIMIT},
table::{TableInstance, TableRef},
types::{GlobalDescriptor, MemoryDescriptor, Signature, TableDescriptor, ValueType},
value::{Error as ValueError, FromRuntimeValue, LittleEndianConvert, RuntimeValue},
};

/// WebAssembly-specific sizes and units.
pub mod memory_units {
pub use memory_units::wasm32::*;
pub use memory_units::{size_of, ByteSize, Bytes, RoundUpTo};
pub use memory_units::{size_of, wasm32::*, ByteSize, Bytes, RoundUpTo};
}

/// Deserialized module prepared for instantiation.
Expand Down
14 changes: 8 additions & 6 deletions src/memory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::memory_units::{Bytes, Pages, RoundUpTo};
use crate::value::LittleEndianConvert;
use crate::Error;
use crate::{
memory_units::{Bytes, Pages, RoundUpTo},
value::LittleEndianConvert,
Error,
};
use alloc::{rc::Rc, string::ToString, vec::Vec};
use core::{
cell::{Cell, Ref, RefCell, RefMut},
cmp, fmt,
cmp,
fmt,
ops::Range,
u32,
};
Expand Down Expand Up @@ -577,8 +580,7 @@ impl MemoryInstance {
mod tests {

use super::{MemoryInstance, MemoryRef, LINEAR_MEMORY_PAGE_SIZE};
use crate::memory_units::Pages;
use crate::Error;
use crate::{memory_units::Pages, Error};
use alloc::rc::Rc;

#[test]
Expand Down
46 changes: 29 additions & 17 deletions src/module.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
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 crate::{
func::{FuncBody, FuncInstance, FuncRef},
global::{GlobalInstance, GlobalRef},
host::Externals,
imports::ImportResolver,
memory::MemoryRef,
memory_units::Pages,
runner::StackRecycler,
table::TableRef,
types::{GlobalDescriptor, MemoryDescriptor, TableDescriptor},
Error,
MemoryInstance,
Module,
RuntimeValue,
Signature,
TableInstance,
Trap,
};
use alloc::{
borrow::ToOwned,
collections::BTreeMap,
rc::Rc,
string::{String, ToString},
vec::Vec,
};
use core::cell::{Ref, RefCell};
use core::fmt;
use core::{
cell::{Ref, RefCell},
fmt,
};
use parity_wasm::elements::{External, InitExpr, Instruction, Internal, ResizableLimits, Type};
use validation::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};

Expand Down Expand Up @@ -831,10 +841,12 @@ pub fn check_limits(limits: &ResizableLimits) -> Result<(), Error> {
#[cfg(test)]
mod tests {
use super::{ExternVal, ModuleInstance};
use crate::func::FuncInstance;
use crate::imports::ImportsBuilder;
use crate::tests::parse_wat;
use crate::types::{Signature, ValueType};
use crate::{
func::FuncInstance,
imports::ImportsBuilder,
tests::parse_wat,
types::{Signature, ValueType},
};

#[should_panic]
#[test]
Expand Down
6 changes: 4 additions & 2 deletions src/nan_preserving_float.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(missing_docs)]

use core::cmp::{Ordering, PartialEq, PartialOrd};
use core::ops::{Add, Div, Mul, Neg, Rem, Sub};
use core::{
cmp::{Ordering, PartialEq, PartialOrd},
ops::{Add, Div, Mul, Neg, Rem, Sub},
};
use num_traits::float::FloatCore;

macro_rules! impl_binop {
Expand Down
18 changes: 13 additions & 5 deletions src/prepare/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ 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::{
func::{
require_label,
top_label,
BlockFrame,
FunctionValidationContext,
StackValueType,
StartedWith,
},
stack::StackWithLimit,
util::Locals,
Error,
FuncValidator,
};
use validation::stack::StackWithLimit;
use validation::util::Locals;
use validation::{Error, FuncValidator};

/// Type of block frame.
#[derive(Debug, Clone, Copy)]
Expand Down
3 changes: 2 additions & 1 deletion src/prepare/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ pub fn compile_module(module: Module) -> Result<CompiledModule, Error> {
pub fn deny_floating_point(module: &Module) -> Result<(), Error> {
use parity_wasm::elements::{
Instruction::{self, *},
Type, ValueType,
Type,
ValueType,
};

if let Some(code) = module.code_section() {
Expand Down
38 changes: 24 additions & 14 deletions src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
#![allow(clippy::unnecessary_wraps)]

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::{
func::{FuncInstance, FuncInstanceInternal, FuncRef},
host::Externals,
isa,
memory::MemoryRef,
memory_units::Pages,
module::ModuleRef,
nan_preserving_float::{F32, F64},
value::{
ArithmeticOps,
ExtendInto,
Float,
Integer,
LittleEndianConvert,
RuntimeValue,
TransmuteInto,
TryTruncateInto,
WrapInto,
},
Signature,
Trap,
TrapKind,
ValueType,
};
use crate::{Signature, Trap, TrapKind, ValueType};
use alloc::{boxed::Box, vec::Vec};
use core::fmt;
use core::ops;
use core::{u32, usize};
use core::{fmt, ops, u32, usize};
use parity_wasm::elements::Local;
use validation::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};

Expand Down
8 changes: 2 additions & 6 deletions src/table.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use crate::func::FuncRef;
use crate::module::check_limits;
use crate::Error;
use crate::{func::FuncRef, module::check_limits, Error};
use alloc::{rc::Rc, vec::Vec};
use core::cell::RefCell;
use core::fmt;
use core::u32;
use core::{cell::RefCell, fmt, u32};
use parity_wasm::elements::ResizableLimits;

/// Reference to a table (See [`TableInstance`] for details).
Expand Down
Loading

0 comments on commit aea0581

Please sign in to comment.