From f3bb2241f0e985dc63b1eee3fecfff756b79ee7f Mon Sep 17 00:00:00 2001 From: Syrus Date: Mon, 18 May 2020 17:41:25 -0700 Subject: [PATCH] Fixed linting issues --- lib/cache/src/filesystem.rs | 1 - lib/compiler/src/relocation.rs | 2 +- lib/engine-native/src/engine.rs | 18 ++++--- lib/engine-native/src/module.rs | 77 +++++++++++++++++------------- lib/engine-native/src/serialize.rs | 6 +-- src/commands/run.rs | 3 +- 6 files changed, 56 insertions(+), 51 deletions(-) diff --git a/lib/cache/src/filesystem.rs b/lib/cache/src/filesystem.rs index ba0ea0a10..ed9c54aad 100644 --- a/lib/cache/src/filesystem.rs +++ b/lib/cache/src/filesystem.rs @@ -3,7 +3,6 @@ use crate::hash::WasmHash; use std::fs::{create_dir_all, File}; use std::io::{self, Write}; use std::path::PathBuf; -use thiserror::Error; use wasmer::{DeserializeError, Module, SerializeError, Store}; /// Representation of a directory that contains compiled wasm artifacts. diff --git a/lib/compiler/src/relocation.rs b/lib/compiler/src/relocation.rs index 62975174c..5bc7be111 100644 --- a/lib/compiler/src/relocation.rs +++ b/lib/compiler/src/relocation.rs @@ -121,7 +121,7 @@ impl Relocation { .checked_add(reloc_addend as u32) .unwrap(); (reloc_address, reloc_delta_u32 as u64) - }, + } RelocationKind::X86CallPCRel4 | RelocationKind::X86CallPLTRel4 => { let reloc_address = start + self.offset as usize; let reloc_addend = self.addend as isize; diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index 12b92cd38..10ce3fd59 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -8,19 +8,15 @@ use std::path::Path; use std::sync::Arc; use std::sync::Mutex; use tempfile::NamedTempFile; -use wasm_common::entity::PrimaryMap; -use wasm_common::{FunctionType, LocalFunctionIndex, MemoryIndex, SignatureIndex, TableIndex}; -use wasmer_compiler::{Compilation, CompileError, FunctionBody, Target}; +use wasm_common::FunctionType; +use wasmer_compiler::CompileError; #[cfg(feature = "compiler")] use wasmer_compiler::{Compiler, CompilerConfig}; use wasmer_engine::{ CompiledModule as BaseCompiledModule, DeserializeError, Engine, InstantiationError, Resolver, SerializeError, Tunables, }; -use wasmer_runtime::{ - InstanceHandle, MemoryPlan, Module, SignatureRegistry, TablePlan, VMFunctionBody, - VMSharedSignatureIndex, VMTrampoline, -}; +use wasmer_runtime::{InstanceHandle, SignatureRegistry, VMSharedSignatureIndex, VMTrampoline}; /// A WebAssembly `Native` Engine. #[derive(Clone)] @@ -34,9 +30,11 @@ impl NativeEngine { const MAGIC_HEADER_MH_CIGAM_64: &'static [u8] = &[207, 250, 237, 254]; // ELF Magic header for Linux (32 bit) + #[allow(dead_code)] const MAGIC_HEADER_ELF_32: &'static [u8] = &[0x7f, b'E', b'L', b'F', 1]; // ELF Magic header for Linux (64 bit) + #[allow(dead_code)] const MAGIC_HEADER_ELF_64: &'static [u8] = &[0x7f, b'E', b'L', b'F', 2]; /// Create a new `NativeEngine` with the given config @@ -172,7 +170,7 @@ impl Engine for NativeEngine { resolver: &dyn Resolver, ) -> Result { let compiled_module = compiled_module.downcast_ref::().unwrap(); - unsafe { compiled_module.instantiate(&self, resolver, Box::new(())) } + compiled_module.instantiate(&self, resolver, Box::new(())) } /// Finish the instantiation of a WebAssembly module @@ -182,7 +180,7 @@ impl Engine for NativeEngine { handle: &InstanceHandle, ) -> Result<(), InstantiationError> { let compiled_module = compiled_module.downcast_ref::().unwrap(); - unsafe { compiled_module.finish_instantiation(&handle) } + compiled_module.finish_instantiation(&handle) } /// Serializes a WebAssembly module @@ -218,7 +216,7 @@ impl Engine for NativeEngine { let mut file = File::open(&file_ref)?; let mut buffer = [0; 5]; // read up to 5 bytes - file.read(&mut buffer)?; + file.read_exact(&mut buffer)?; if !Self::is_deserializable(&buffer) { return Err(DeserializeError::Incompatible( "The provided bytes are not in any native format Wasmer can understand".to_string(), diff --git a/lib/engine-native/src/module.rs b/lib/engine-native/src/module.rs index d05953412..885047fb6 100644 --- a/lib/engine-native/src/module.rs +++ b/lib/engine-native/src/module.rs @@ -7,28 +7,25 @@ use faerie::{ArtifactBuilder, Decl, Link}; use libloading::{Library, Symbol}; use std::any::Any; use std::error::Error; -use std::ffi::c_void; use std::path::{Path, PathBuf}; use std::process::Command; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use tempfile::NamedTempFile; use wasm_common::entity::{BoxedSlice, EntityRef, PrimaryMap}; use wasm_common::{ - DataInitializer, LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, - MemoryIndex, OwnedDataInitializer, SignatureIndex, TableIndex, FunctionIndex, + DataInitializer, FunctionIndex, LocalFunctionIndex, MemoryIndex, OwnedDataInitializer, + SignatureIndex, TableIndex, }; use wasmer_compiler::CompileError; #[cfg(feature = "compiler")] use wasmer_compiler::ModuleEnvironment; -use wasmer_compiler::{Relocation, RelocationKind, RelocationTarget, Relocations}; +use wasmer_compiler::RelocationTarget; use wasmer_engine::{ - resolve_imports, CompiledModule, DeserializeError, Engine, GlobalFrameInfoRegistration, - InstantiationError, LinkError, Resolver, RuntimeError, SerializableFunctionFrameInfo, - SerializeError, Tunables, + resolve_imports, CompiledModule, DeserializeError, Engine, InstantiationError, Resolver, + RuntimeError, SerializeError, }; use wasmer_runtime::{ - InstanceHandle, LinearMemory, Module, SignatureRegistry, Table, VMFunctionBody, - VMGlobalDefinition, VMSharedSignatureIndex, VMTrampoline, + InstanceHandle, Module, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline, }; use wasmer_runtime::{MemoryPlan, TablePlan}; @@ -36,14 +33,13 @@ use wasmer_runtime::{MemoryPlan, TablePlan}; pub struct NativeModule { sharedobject_path: PathBuf, metadata: ModuleMetadata, + #[allow(dead_code)] library: Library, finished_functions: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, } -type Handle = *mut c_void; - fn to_compile_error(err: impl Error) -> CompileError { CompileError::Codegen(format!("{}", err)) } @@ -97,8 +93,8 @@ impl NativeModule { .collect::>(); // Compile the dynamic function trampolines - let dynamic_function_trampolines = compiler - .compile_dynamic_function_trampolines(&translation.module)?; + let dynamic_function_trampolines = + compiler.compile_dynamic_function_trampolines(&translation.module)?; let data_initializers = translation .data_initializers @@ -228,9 +224,6 @@ impl NativeModule { LibCall::NearestF64 => "wasmer_f64_nearest", LibCall::RaiseTrap => "wasmer_raise_trap", LibCall::Probestack => "wasmer_probestack", - libcall => { - unimplemented!("The `{:?}` libcall is not yet implemented", libcall) - } }; obj.link(Link { from: &function_name, @@ -239,10 +232,10 @@ impl NativeModule { }) .map_err(to_compile_error)?; } - RelocationTarget::CustomSection(custom_section) => { - // do nothing + RelocationTarget::CustomSection(_custom_section) => { + // TODO: Implement custom sections } - RelocationTarget::JumpTable(func_index, jt) => { + RelocationTarget::JumpTable(_func_index, _jt) => { // do nothing } }; @@ -252,12 +245,11 @@ impl NativeModule { let file = NamedTempFile::new().map_err(to_compile_error)?; // Re-open it. - let mut file2 = file.reopen().map_err(to_compile_error)?; let (file, filepath) = file.keep().map_err(to_compile_error)?; obj.write(file).map_err(to_compile_error)?; let shared_file = NamedTempFile::new().map_err(to_compile_error)?; - let (file, shared_filepath) = shared_file.keep().map_err(to_compile_error)?; + let (_file, shared_filepath) = shared_file.keep().map_err(to_compile_error)?; let output = Command::new("gcc") .arg(&filepath) .arg("-o") @@ -281,12 +273,26 @@ impl NativeModule { format!("wasmer_function_{}_{}", metadata.prefix, index.index()) } - fn get_function_call_trampoline_name(metadata: &ModuleMetadata, index: SignatureIndex) -> String { - format!("wasmer_trampoline_function_call_{}_{}", metadata.prefix, index.index()) + fn get_function_call_trampoline_name( + metadata: &ModuleMetadata, + index: SignatureIndex, + ) -> String { + format!( + "wasmer_trampoline_function_call_{}_{}", + metadata.prefix, + index.index() + ) } - fn get_dynamic_function_trampoline_name(metadata: &ModuleMetadata, index: FunctionIndex) -> String { - format!("wasmer_trampoline_dynamic_function_{}_{}", metadata.prefix, index.index()) + fn get_dynamic_function_trampoline_name( + metadata: &ModuleMetadata, + index: FunctionIndex, + ) -> String { + format!( + "wasmer_trampoline_dynamic_function_{}_{}", + metadata.prefix, + index.index() + ) } /// Construct a `NativeModule` from component parts. @@ -329,9 +335,16 @@ impl NativeModule { } // Retrieve dynamic function trampolines (only for imported functions) - let mut finished_dynamic_function_trampolines: PrimaryMap = - PrimaryMap::with_capacity(metadata.module.num_imported_funcs); - for func_index in metadata.module.functions.keys().take(metadata.module.num_imported_funcs) { + let mut finished_dynamic_function_trampolines: PrimaryMap< + FunctionIndex, + *const VMFunctionBody, + > = PrimaryMap::with_capacity(metadata.module.num_imported_funcs); + for func_index in metadata + .module + .functions + .keys() + .take(metadata.module.num_imported_funcs) + { let function_name = Self::get_dynamic_function_trampoline_name(&metadata, func_index); unsafe { let trampoline: Symbol<*const VMFunctionBody> = lib @@ -404,13 +417,13 @@ impl NativeModule { use std::ops::Deref; use std::slice; - let mut size = &mut **symbol.deref(); + let size = &mut **symbol.deref(); let mut readable = &size[..]; - let metadata_len = leb128::read::unsigned(&mut readable).map_err(|e| { + let metadata_len = leb128::read::unsigned(&mut readable).map_err(|_e| { DeserializeError::CorruptedBinary("Can't read metadata size".to_string()) })?; let metadata_slice: &'static [u8] = - unsafe { slice::from_raw_parts(&size[10] as *const u8, metadata_len as usize) }; + slice::from_raw_parts(&size[10] as *const u8, metadata_len as usize); let metadata: ModuleMetadata = bincode::deserialize(metadata_slice) .map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e)))?; let mut engine_inner = engine.inner_mut(); diff --git a/lib/engine-native/src/serialize.rs b/lib/engine-native/src/serialize.rs index ce90d3e7e..71a031ac7 100644 --- a/lib/engine-native/src/serialize.rs +++ b/lib/engine-native/src/serialize.rs @@ -1,11 +1,7 @@ use serde::{Deserialize, Serialize}; use std::sync::Arc; use wasm_common::entity::PrimaryMap; -use wasm_common::{ - Features, LocalFunctionIndex, MemoryIndex, OwnedDataInitializer, SignatureIndex, TableIndex, -}; -use wasmer_compiler::{FunctionBody, JumpTableOffsets, Relocation, SectionBody, SectionIndex}; -use wasmer_engine::SerializableFunctionFrameInfo; +use wasm_common::{Features, LocalFunctionIndex, MemoryIndex, OwnedDataInitializer, TableIndex}; use wasmer_runtime::Module; use wasmer_runtime::{MemoryPlan, TablePlan}; diff --git a/src/commands/run.rs b/src/commands/run.rs index f9725b736..77a35958d 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -146,8 +146,7 @@ impl Run { } #[cfg(feature = "jit")] { - use wasmer_engine_jit::JITEngine; - if JITEngine::is_deserializable(&contents) { + if wasmer_engine_jit::JITEngine::is_deserializable(&contents) { let tunables = Tunables::default(); let engine = JITEngine::headless(tunables); let store = Store::new(Arc::new(engine));