Fix linter

This commit is contained in:
ptitSeb
2022-08-18 16:58:04 +02:00
parent c7c1507b8b
commit f599df0240
17 changed files with 82 additions and 82 deletions

View File

@@ -101,7 +101,11 @@ impl Memory {
}
/// Creates a new host `Memory` from provided JavaScript memory.
pub fn new_raw(store: &mut impl AsStoreMut, js_memory: js_sys::WebAssembly::Memory, ty: MemoryType) -> Result<Self, MemoryError> {
pub fn new_raw(
store: &mut impl AsStoreMut,
js_memory: js_sys::WebAssembly::Memory,
ty: MemoryType,
) -> Result<Self, MemoryError> {
let vm_memory = VMMemory::new(js_memory, ty);
Ok(Self::from_vm_export(store, vm_memory))
}

View File

@@ -182,27 +182,23 @@ impl Imports {
}
pub struct ImportsIterator<'a> {
iter: std::collections::hash_map::Iter<'a, (String, String), Extern>
iter: std::collections::hash_map::Iter<'a, (String, String), Extern>,
}
impl<'a> ImportsIterator<'a>
{
impl<'a> ImportsIterator<'a> {
fn new(imports: &'a Imports) -> Self {
let iter = imports.map.iter();
Self { iter }
}
}
impl<'a> Iterator
for ImportsIterator<'a> {
impl<'a> Iterator for ImportsIterator<'a> {
type Item = (&'a str, &'a str, &'a Extern);
fn next(&mut self) -> Option<Self::Item> {
self.iter
.next()
.map(|(k, v)| {
(k.0.as_str(), k.1.as_str(), v)
})
.map(|(k, v)| (k.0.as_str(), k.1.as_str(), v))
}
}

View File

@@ -10,7 +10,7 @@ use std::mem::MaybeUninit;
use std::slice;
#[cfg(feature = "tracing")]
use tracing::warn;
use wasmer_types::{Pages, LinearMemory};
use wasmer_types::{LinearMemory, Pages};
use wasmer_vm::{InternalStoreHandle, MemoryError, StoreHandle, VMExtern, VMMemory};
use super::MemoryView;
@@ -63,7 +63,7 @@ impl Memory {
/// Create a memory object from an existing memory and attaches it to the store
pub fn new_from_existing(new_store: &mut impl AsStoreMut, memory: VMMemory) -> Self {
Self {
handle: StoreHandle::new(new_store.objects_mut(), memory)
handle: StoreHandle::new(new_store.objects_mut(), memory),
}
}
@@ -152,8 +152,7 @@ impl Memory {
/// Attempts to clone this memory (if its clonable)
pub fn try_clone(&self, store: &impl AsStoreRef) -> Option<VMMemory> {
let mem = self.handle.get(store.as_store_ref().objects());
mem.try_clone()
.map(|mem| mem.into())
mem.try_clone().map(|mem| mem.into())
}
pub(crate) fn to_vm_extern(&self) -> VMExtern {

View File

@@ -4,7 +4,7 @@ use std::convert::TryInto;
use std::marker::PhantomData;
use std::mem::MaybeUninit;
use std::slice;
use wasmer_types::{Pages, LinearMemory};
use wasmer_types::{LinearMemory, Pages};
use super::memory::MemoryBuffer;
use super::Memory;

View File

@@ -1071,7 +1071,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
expected,
timeout,
)?;
state.push1(res); }
state.push1(res);
}
Operator::MemoryAtomicNotify { memarg } => {
let heap_index = MemoryIndex::from_u32(memarg.memory);
let heap = state.get_heap(builder.func, memarg.memory, environ)?;

View File

@@ -4,7 +4,8 @@ use crate::LinkError;
use more_asserts::assert_ge;
use wasmer_types::entity::{BoxedSlice, EntityRef, PrimaryMap};
use wasmer_types::{
ExternType, FunctionIndex, ImportError, ImportIndex, MemoryIndex, ModuleInfo, TableIndex, LinearMemory,
ExternType, FunctionIndex, ImportError, ImportIndex, LinearMemory, MemoryIndex, ModuleInfo,
TableIndex,
};
use wasmer_vm::{

View File

@@ -1,8 +1,8 @@
// This file contains code from external sources.
// Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md
use super::state::ModuleTranslationState;
use crate::lib::std::string::ToString;
use crate::lib::std::borrow::ToOwned;
use crate::lib::std::string::ToString;
use crate::lib::std::{boxed::Box, string::String, vec::Vec};
use crate::translate_module;
use crate::wasmparser::{Operator, Range, Type};

View File

@@ -76,8 +76,8 @@ pub use crate::compilation::target::{
};
pub use crate::serialize::{MetadataHeader, SerializableCompilation, SerializableModule};
pub use error::{
CompileError, DeserializeError, ImportError, MiddlewareError, ParseCpuFeatureError,
PreInstantiationError, SerializeError, WasmError, WasmResult, MemoryError,
CompileError, DeserializeError, ImportError, MemoryError, MiddlewareError,
ParseCpuFeatureError, PreInstantiationError, SerializeError, WasmError, WasmResult,
};
/// The entity module, with common helpers for Rust structures
@@ -103,9 +103,7 @@ pub use types::{
pub use value::{RawValue, ValueType};
pub use crate::libcalls::LibCall;
pub use crate::memory::{
MemoryStyle, LinearMemory, VMMemoryDefinition
};
pub use crate::memory::{LinearMemory, MemoryStyle, VMMemoryDefinition};
pub use crate::table::TableStyle;
pub use crate::trapcode::TrapCode;
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};

View File

@@ -1,14 +1,14 @@
use crate::{Pages, ValueType};
use core::ptr::NonNull;
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use core::ptr::NonNull;
use std::convert::{TryFrom, TryInto};
use std::iter::Sum;
use std::ops::{Add, AddAssign};
use super::MemoryType;
use super::MemoryError;
use super::MemoryType;
/// Implementation styles for WebAssembly linear memory.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, RkyvSerialize, RkyvDeserialize, Archive)]
@@ -132,7 +132,8 @@ unsafe impl MemorySize for Memory64 {
/// Represents memory that is used by the WebAsssembly module
pub trait LinearMemory
where Self: std::fmt::Debug + Send
where
Self: std::fmt::Debug + Send,
{
/// Returns the type for this memory.
fn ty(&self) -> MemoryType;
@@ -183,10 +184,10 @@ unsafe impl Sync for VMMemoryDefinition {}
#[cfg(test)]
mod test_vmmemory_definition {
use super::VMMemoryDefinition;
use crate::ModuleInfo;
use crate::VMOffsets;
use memoffset::offset_of;
use std::mem::size_of;
use crate::ModuleInfo;
#[test]
fn check_vmmemory_definition_offsets() {

View File

@@ -5,8 +5,8 @@ use std::convert::TryFrom;
use std::mem;
use std::ptr::{self, NonNull};
use wasmer_types::entity::EntityRef;
use wasmer_types::{VMOffsets, VMMemoryDefinition};
use wasmer_types::{LocalMemoryIndex, LocalTableIndex, ModuleInfo};
use wasmer_types::{VMMemoryDefinition, VMOffsets};
/// This is an intermediate type that manages the raw allocation and
/// metadata when creating an [`Instance`].

View File

@@ -14,9 +14,9 @@ use crate::store::{InternalStoreHandle, StoreObjects};
use crate::table::TableElement;
use crate::trap::{catch_traps, Trap, TrapCode};
use crate::vmcontext::{
VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext, VMFunctionContext,
VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport,
VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline, memory_copy, memory_fill,
memory_copy, memory_fill, VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext,
VMFunctionContext, VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport,
VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline,
};
use crate::{FunctionBodyPtr, MaybeInstanceOwned, TrapHandlerFn, VMFunctionBody};
use crate::{VMFuncRef, VMFunction, VMGlobal, VMMemory, VMTable};
@@ -35,9 +35,9 @@ use std::sync::Arc;
use wasmer_types::entity::{packed_option::ReservedValue, BoxedSlice, EntityRef, PrimaryMap};
use wasmer_types::{
DataIndex, DataInitializer, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, GlobalInit,
LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryIndex,
ModuleInfo, Pages, SignatureIndex, TableIndex, TableInitializer, VMOffsets, LinearMemory,
MemoryError, VMMemoryDefinition
LinearMemory, LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex,
MemoryError, MemoryIndex, ModuleInfo, Pages, SignatureIndex, TableIndex, TableInitializer,
VMMemoryDefinition, VMOffsets,
};
/// A WebAssembly instance.

View File

@@ -46,7 +46,6 @@ pub use crate::global::*;
pub use crate::imports::Imports;
pub use crate::instance::{InstanceAllocator, InstanceHandle};
pub use crate::memory::VMMemory;
pub use wasmer_types::MemoryError;
pub use crate::mmap::Mmap;
pub use crate::probestack::PROBESTACK;
pub use crate::sig_registry::SignatureRegistry;
@@ -57,13 +56,14 @@ pub use crate::table::{TableElement, VMTable};
pub use crate::trap::*;
pub use crate::vmcontext::{
VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionContext,
VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport,
VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline,
VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryImport,
VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline,
};
pub use wasmer_types::LibCall;
pub use wasmer_types::{MemoryStyle, VMMemoryDefinition};
pub use wasmer_types::MemoryError;
use wasmer_types::RawValue;
pub use wasmer_types::TableStyle;
pub use wasmer_types::{MemoryStyle, VMMemoryDefinition};
pub use wasmer_types::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
#[deprecated(

View File

@@ -10,7 +10,9 @@ use more_asserts::assert_ge;
use std::cell::UnsafeCell;
use std::convert::TryInto;
use std::ptr::NonNull;
use wasmer_types::{Bytes, MemoryStyle, MemoryType, Pages, MemoryError, LinearMemory, VMMemoryDefinition};
use wasmer_types::{
Bytes, LinearMemory, MemoryError, MemoryStyle, MemoryType, Pages, VMMemoryDefinition,
};
// The memory mapped area
#[derive(Debug)]
@@ -23,8 +25,7 @@ struct WasmMmap {
vm_memory_definition: MaybeInstanceOwned<VMMemoryDefinition>,
}
impl WasmMmap
{
impl WasmMmap {
fn get_vm_memory_definition(&self) -> NonNull<VMMemoryDefinition> {
self.vm_memory_definition.as_ptr()
}
@@ -92,14 +93,12 @@ impl WasmMmap
Mmap::accessible_reserved(new_bytes, request_bytes).map_err(MemoryError::Region)?;
let copy_len = self.alloc.len() - conf.offset_guard_size;
new_mmap.as_mut_slice()[..copy_len]
.copy_from_slice(&self.alloc.as_slice()[..copy_len]);
new_mmap.as_mut_slice()[..copy_len].copy_from_slice(&self.alloc.as_slice()[..copy_len]);
self.alloc = new_mmap;
} else if delta_bytes > 0 {
// Make the newly allocated pages accessible.
self
.alloc
self.alloc
.make_accessible(prev_bytes, delta_bytes)
.map_err(MemoryError::Region)?;
}
@@ -132,8 +131,7 @@ struct VMMemoryConfig {
offset_guard_size: usize,
}
impl VMMemoryConfig
{
impl VMMemoryConfig {
fn ty(&self, minimum: Pages) -> MemoryType {
let mut out = self.memory;
out.minimum = minimum;
@@ -155,8 +153,8 @@ pub struct VMOwnedMemory {
config: VMMemoryConfig,
}
unsafe impl Send for VMOwnedMemory { }
unsafe impl Sync for VMOwnedMemory { }
unsafe impl Send for VMOwnedMemory {}
unsafe impl Sync for VMOwnedMemory {}
impl VMOwnedMemory {
/// Create a new linear memory instance with specified minimum and maximum number of wasm pages.
@@ -256,14 +254,12 @@ impl VMOwnedMemory {
offset_guard_size: offset_guard_bytes,
memory: *memory,
style: style.clone(),
}
},
})
}
}
impl LinearMemory
for VMOwnedMemory
{
impl LinearMemory for VMOwnedMemory {
/// Returns the type for this memory.
fn ty(&self) -> MemoryType {
let minimum = self.mmap.size();
@@ -299,9 +295,7 @@ for VMOwnedMemory
}
}
impl Into<VMMemory>
for VMOwnedMemory
{
impl Into<VMMemory> for VMOwnedMemory {
fn into(self) -> VMMemory {
VMMemory(Box::new(self))
}
@@ -311,17 +305,13 @@ for VMOwnedMemory
#[derive(Debug)]
pub struct VMMemory(Box<dyn LinearMemory + 'static>);
impl Into<VMMemory>
for Box<dyn LinearMemory + 'static>
{
impl Into<VMMemory> for Box<dyn LinearMemory + 'static> {
fn into(self) -> VMMemory {
VMMemory(self)
}
}
impl LinearMemory
for VMMemory
{
impl LinearMemory for VMMemory {
/// Returns the type for this memory.
fn ty(&self) -> MemoryType {
self.0.ty()
@@ -356,17 +346,14 @@ for VMMemory
}
}
impl VMMemory
{
impl VMMemory {
/// Creates a new linear memory instance of the correct type with specified
/// minimum and maximum number of wasm pages.
///
/// This creates a `Memory` with owned metadata: this can be used to create a memory
/// that will be imported into Wasm modules.
pub fn new(memory: &MemoryType, style: &MemoryStyle) -> Result<VMMemory, MemoryError> {
Ok(
Self(Box::new(VMOwnedMemory::new(memory, style)?))
)
Ok(Self(Box::new(VMOwnedMemory::new(memory, style)?)))
}
/// Create a new linear memory instance with specified minimum and maximum number of wasm pages.
@@ -381,9 +368,11 @@ impl VMMemory
style: &MemoryStyle,
vm_memory_location: NonNull<VMMemoryDefinition>,
) -> Result<VMMemory, MemoryError> {
Ok(
Self(Box::new(VMOwnedMemory::from_definition(memory, style, vm_memory_location)?))
)
Ok(Self(Box::new(VMOwnedMemory::from_definition(
memory,
style,
vm_memory_location,
)?)))
}
/// Creates VMMemory from a custom implementation - the following into implementations
@@ -392,7 +381,8 @@ impl VMMemory
/// - VMSharedMemory -> VMMemory
/// - Box<dyn LinearMemory + 'static> -> VMMemory
pub fn from_custom<IntoVMMemory>(memory: IntoVMMemory) -> VMMemory
where IntoVMMemory: Into<VMMemory>
where
IntoVMMemory: Into<VMMemory>,
{
memory.into()
}

View File

@@ -267,9 +267,9 @@ impl<T> MaybeInstanceOwned<T> {
}
}
impl<T> std::fmt::Debug
for MaybeInstanceOwned<T>
where T: std::fmt::Debug
impl<T> std::fmt::Debug for MaybeInstanceOwned<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
@@ -277,7 +277,7 @@ where T: std::fmt::Debug
write!(f, "host(")?;
p.as_ref().fmt(f)?;
write!(f, ")")
},
}
MaybeInstanceOwned::Instance(p) => {
write!(f, "instance(")?;
unsafe { p.as_ref().fmt(f)? };

View File

@@ -313,7 +313,12 @@ mod test_vmglobal_import {
/// # Safety
/// The memory is not copied atomically and is not synchronized: it's the
/// caller's responsibility to synchronize.
pub(crate) unsafe fn memory_copy(mem: &VMMemoryDefinition, dst: u32, src: u32, len: u32) -> Result<(), Trap> {
pub(crate) unsafe fn memory_copy(
mem: &VMMemoryDefinition,
dst: u32,
src: u32,
len: u32,
) -> Result<(), Trap> {
// https://webassembly.github.io/reference-types/core/exec/instructions.html#exec-memory-copy
if src
.checked_add(len)
@@ -347,7 +352,12 @@ pub(crate) unsafe fn memory_copy(mem: &VMMemoryDefinition, dst: u32, src: u32, l
/// # Safety
/// The memory is not filled atomically and is not synchronized: it's the
/// caller's responsibility to synchronize.
pub(crate) unsafe fn memory_fill(mem: &VMMemoryDefinition, dst: u32, val: u32, len: u32) -> Result<(), Trap> {
pub(crate) unsafe fn memory_fill(
mem: &VMMemoryDefinition,
dst: u32,
val: u32,
len: u32,
) -> Result<(), Trap> {
if dst
.checked_add(len)
.map_or(true, |m| usize::try_from(m).unwrap() > mem.current_length)