Skip to content

Commit

Permalink
Deny many warnings in CI; fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed May 13, 2020
1 parent e01588e commit e77cbd8
Show file tree
Hide file tree
Showing 28 changed files with 67 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ jobs:
- run: cargo test --release
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects -D mutable-borrow-reservation-conflict" # TODO: add `-D missing-docs`
- name: Build and Test C API
run: |
make capi
make test-capi-cranelift
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects -D mutable-borrow-reservation-conflict" # TODO: add `-D missing-docs`
if: matrix.os != 'windows-latest'
- name: Build C API on Windows
run: make capi
if: matrix.os == 'windows-latest'
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects -D mutable-borrow-reservation-conflict" # TODO: add `-D missing-docs`
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ use test_generator::{
with_features, with_test_module, Testsuite,
};

fn is_truthy_env(name: &str) -> bool {
env::var(name).map(|n| n == "1").unwrap_or_default()
}

fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=tests/ignores.txt");
Expand Down
3 changes: 1 addition & 2 deletions lib/api/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::RuntimeError;
use crate::{ExternType, FunctionType, GlobalType, MemoryType, TableType, ValType};
use std::cmp::max;
use std::slice;
use wasm_common::{Bytes, HostFunction, Pages, ValueType, WasmTypeList, WithEnv, WithoutEnv};
use wasmer_engine::Engine as _;
use wasm_common::{HostFunction, Pages, ValueType, WasmTypeList, WithEnv, WithoutEnv};
use wasmer_runtime::{
wasmer_call_trampoline, Export, ExportFunction, ExportGlobal, ExportMemory, ExportTable,
LinearMemory, MemoryError, Table as RuntimeTable, VMCallerCheckedAnyfunc, VMContext,
Expand Down
5 changes: 3 additions & 2 deletions lib/api/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::Path;
use std::sync::Arc;
use thiserror::Error;
use wasmer_compiler::{CompileError, WasmError};
use wasmer_engine::{CompiledModule, DeserializeError, Engine, Resolver, SerializeError};
use wasmer_engine::{CompiledModule, DeserializeError, Resolver, SerializeError};
use wasmer_runtime::{ExportsIterator, ImportsIterator, InstanceHandle, Module as ModuleInfo};

#[derive(Error, Debug)]
Expand Down Expand Up @@ -74,6 +74,7 @@ impl Module {
/// let bytes: Vec<u8> = vec![];
/// let module = Module::new(&store, bytes)?;
/// ```
#[allow(unreachable_code)]
pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result<Module, CompileError> {
#[cfg(feature = "wat")]
{
Expand Down Expand Up @@ -206,7 +207,7 @@ impl Module {
Ok(Self::from_compiled_module(store, compiled))
}

fn from_compiled_module(store: &Store, compiled: Arc<CompiledModule>) -> Self {
fn from_compiled_module(store: &Store, compiled: Arc<dyn CompiledModule>) -> Self {
Module {
store: store.clone(),
compiled,
Expand Down
6 changes: 4 additions & 2 deletions lib/api/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#[cfg(all(feature = "compiler", feature = "engine"))]
use crate::tunables::Tunables;
use std::sync::Arc;
#[cfg(feature = "compiler")]
#[cfg(all(feature = "compiler", feature = "engine"))]
use wasmer_compiler::CompilerConfig;

use std::sync::Arc;
use wasmer_engine::Engine;

#[derive(Clone)]
Expand Down
5 changes: 5 additions & 0 deletions lib/compiler-cranelift/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! Wasmer Cranelift compiler build script.
//!
//! Sets the git revsion? for $PURPOSE
//! TODO(syrus): explain what's happening here
use std::process::Command;
use std::str;

Expand Down
14 changes: 5 additions & 9 deletions lib/compiler-cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,22 @@ use crate::func_environ::{get_func_name, FuncEnvironment};
use crate::sink::{RelocSink, TrapSink};
use crate::trampoline::{make_wasm_trampoline, FunctionBuilderContext};
use crate::translator::{
compiled_function_unwind_info, irlibcall_to_libcall, irreloc_to_relocationkind,
signature_to_cranelift_ir, transform_jump_table, FuncTranslator,
compiled_function_unwind_info, signature_to_cranelift_ir, transform_jump_table, FuncTranslator,
};
use cranelift_codegen::ir::{self, ExternalName};
use cranelift_codegen::ir;
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::{binemit, isa, Context};
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use wasm_common::entity::{EntityRef, PrimaryMap};
use wasm_common::entity::PrimaryMap;
use wasm_common::{
Features, FunctionIndex, FunctionType, LocalFunctionIndex, MemoryIndex, SignatureIndex,
TableIndex,
Features, FunctionType, LocalFunctionIndex, MemoryIndex, SignatureIndex, TableIndex,
};
use wasmer_compiler::CompileError;
use wasmer_compiler::{
Compilation, CompiledFunction, CompiledFunctionFrameInfo, Compiler, FunctionBody,
FunctionBodyData, SourceLoc, TrapInformation,
FunctionBodyData,
};
use wasmer_compiler::{CompilerConfig, ModuleTranslationState, Target};
use wasmer_compiler::{Relocation, RelocationTarget};
use wasmer_runtime::TrapCode;
use wasmer_runtime::{MemoryPlan, Module, TablePlan};

/// A compiler that compiles a WebAssembly module with Cranelift, translating the Wasm to Cranelift IR,
Expand Down
7 changes: 2 additions & 5 deletions lib/compiler-cranelift/src/sink.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Support for compiling with Cranelift.
use crate::translator::{
irlibcall_to_libcall, irreloc_to_relocationkind, signature_to_cranelift_ir,
transform_jump_table, FuncTranslator,
};
use crate::translator::{irlibcall_to_libcall, irreloc_to_relocationkind};
use cranelift_codegen::binemit;
use cranelift_codegen::ir::{self, ExternalName};
use wasm_common::entity::EntityRef;
Expand Down Expand Up @@ -136,7 +133,7 @@ fn translate_ir_trapcode(trap: ir::TrapCode) -> TrapCode {
ir::TrapCode::BadConversionToInteger => TrapCode::BadConversionToInteger,
ir::TrapCode::UnreachableCodeReached => TrapCode::UnreachableCodeReached,
ir::TrapCode::Interrupt => TrapCode::Interrupt,
ir::TrapCode::User(user_code) => unimplemented!("User trap code not supported"),
ir::TrapCode::User(_user_code) => unimplemented!("User trap code not supported"),
// ir::TrapCode::User(user_code) => TrapCode::User(user_code),
}
}
4 changes: 2 additions & 2 deletions lib/compiler-cranelift/src/trampoline/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! ```
use super::binemit::TrampolineRelocSink;
use crate::translator::{
compiled_function_unwind_info, signature_to_cranelift_ir, transform_jump_table,
compiled_function_unwind_info, signature_to_cranelift_ir, /*transform_jump_table, */
};
use cranelift_codegen::ir::InstBuilder;
use cranelift_codegen::isa::TargetIsa;
Expand All @@ -16,7 +16,7 @@ use cranelift_codegen::Context;
use cranelift_codegen::{binemit, ir};
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use wasm_common::FunctionType;
use wasmer_compiler::{CompileError, CompiledFunction, CompiledFunctionFrameInfo, FunctionBody};
use wasmer_compiler::{CompileError, FunctionBody};

/// Create a trampoline for invoking a WebAssembly function.
pub fn make_wasm_trampoline(
Expand Down
3 changes: 3 additions & 0 deletions lib/compiler-cranelift/src/translator/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use wasmer_compiler::WasmResult;
/// The value of a WebAssembly global variable.
#[derive(Clone, Copy)]
pub enum GlobalVariable {
#[allow(dead_code)]
/// This is a constant global with a value known at compile time.
Const(ir::Value),

Expand All @@ -29,10 +30,12 @@ pub enum GlobalVariable {
ty: ir::Type,
},

#[allow(dead_code)]
/// This is a global variable that needs to be handled by the environment.
Custom,
}

#[allow(dead_code)]
/// How to return from functions.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum ReturnMode {
Expand Down
3 changes: 3 additions & 0 deletions lib/compiler-cranelift/src/translator/func_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ pub struct FuncTranslationState {
functions: HashMap<FunctionIndex, (ir::FuncRef, usize)>,
}

// TODO: review this comment it seems to be not true, `FuncTranslationState` is _not_ exposed
// publicly from this crate.
// Public methods that are exposed to non-`wasmer_compiler` API consumers.
impl FuncTranslationState {
#[allow(dead_code)]
/// True if the current translation state expresses reachable code, false if it is unreachable.
#[inline]
pub fn reachable(&self) -> bool {
Expand Down
10 changes: 5 additions & 5 deletions lib/compiler/src/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{Addend, CodeOffset, JumpTable};
use serde::{Deserialize, Serialize};
use std::fmt;
use wasm_common::entity::PrimaryMap;
use wasm_common::{FunctionIndex, LocalFunctionIndex};
use wasm_common::LocalFunctionIndex;
use wasmer_runtime::libcalls::LibCall;

/// Relocation kinds for every ISA.
Expand Down Expand Up @@ -106,23 +106,23 @@ impl Relocation {
/// The function returns the relocation address and the delta.
pub fn for_address(&self, start: usize, target_func_address: u64) -> (usize, u64) {
match self.kind {
RelocationKind::Abs8 => unsafe {
RelocationKind::Abs8 => {
let reloc_address = start + self.offset as usize;
let reloc_addend = self.addend as isize;
let reloc_abs = (target_func_address)
.checked_add(reloc_addend as u64)
.unwrap();
(reloc_address, reloc_abs)
},
RelocationKind::X86PCRel4 => unsafe {
}
RelocationKind::X86PCRel4 => {
let reloc_address = start + self.offset as usize;
let reloc_addend = self.addend as isize;
let reloc_delta_u32 = (target_func_address as u32)
.wrapping_sub(reloc_address as u32)
.checked_add(reloc_addend as u32)
.unwrap();
(reloc_address, reloc_delta_u32 as u64)
},
}
RelocationKind::X86CallPCRel4 => {
let reloc_address = start + self.offset as usize;
let reloc_addend = self.addend as isize;
Expand Down
1 change: 0 additions & 1 deletion lib/compiler/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use enumset::{EnumSet, EnumSetType};
pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple};

use crate::std::boxed::Box;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use raw_cpuid::CpuId;

Expand Down
1 change: 0 additions & 1 deletion lib/compiler/src/translator/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::WasmError;
use thiserror::Error;
use wasmparser::BinaryReaderError;

/// Return an `Err(WasmError::Unsupported(msg))` where `msg` the string built by calling `format!`
Expand Down
11 changes: 5 additions & 6 deletions lib/engine-jit/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ use crate::{CodeMemory, CompiledModule};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use wasm_common::entity::PrimaryMap;
use wasm_common::{FunctionType, LocalFunctionIndex, MemoryIndex, SignatureIndex, TableIndex};
use wasmer_compiler::{Compilation, CompileError, FunctionBody, Target};
use wasm_common::{FunctionType, LocalFunctionIndex, SignatureIndex};
use wasmer_compiler::{CompileError, FunctionBody};
#[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,
InstanceHandle, Module, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline,
};

/// A WebAssembly `JIT` Engine.
Expand Down Expand Up @@ -129,7 +128,7 @@ impl Engine for JITEngine {
resolver: &dyn Resolver,
) -> Result<InstanceHandle, InstantiationError> {
let compiled_module = compiled_module.downcast_ref::<CompiledModule>().unwrap();
unsafe { compiled_module.instantiate(&self, resolver, Box::new(())) }
compiled_module.instantiate(&self, resolver, Box::new(()))
}

/// Finish the instantiation of a WebAssembly module
Expand All @@ -139,7 +138,7 @@ impl Engine for JITEngine {
handle: &InstanceHandle,
) -> Result<(), InstantiationError> {
let compiled_module = compiled_module.downcast_ref::<CompiledModule>().unwrap();
unsafe { compiled_module.finish_instantiation(&handle) }
compiled_module.finish_instantiation(&handle)
}

/// Serializes a WebAssembly module
Expand Down
2 changes: 1 addition & 1 deletion lib/engine-jit/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use wasmer_runtime::VMFunctionBody;
/// Links a module, patching the allocated functions with the
/// required relocations and jump tables.
pub fn link_module(
module: &Module,
_module: &Module,
allocated_functions: &PrimaryMap<LocalFunctionIndex, *mut [VMFunctionBody]>,
jt_offsets: &PrimaryMap<LocalFunctionIndex, JumpTableOffsets>,
relocations: Relocations,
Expand Down
14 changes: 6 additions & 8 deletions lib/engine-jit/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
use crate::engine::{JITEngine, JITEngineInner};
use crate::link::link_module;
use crate::serialize::{SerializableCompilation, SerializableModule};
use serde::{Deserialize, Serialize};
use std::any::Any;
use std::sync::{Arc, Mutex};
use wasm_common::entity::{BoxedSlice, EntityRef, PrimaryMap};
use wasm_common::entity::{BoxedSlice, PrimaryMap};
use wasm_common::{
DataInitializer, LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex,
MemoryIndex, OwnedDataInitializer, SignatureIndex, TableIndex,
DataInitializer, LocalFunctionIndex, MemoryIndex, OwnedDataInitializer, SignatureIndex,
TableIndex,
};
use wasmer_compiler::CompileError;
#[cfg(feature = "compiler")]
use wasmer_compiler::ModuleEnvironment;
use wasmer_engine::{
register_frame_info, resolve_imports, CompiledModule as BaseCompiledModule, DeserializeError,
Engine, GlobalFrameInfoRegistration, InstantiationError, LinkError, Resolver, RuntimeError,
SerializableFunctionFrameInfo, SerializeError, Tunables,
Engine, GlobalFrameInfoRegistration, InstantiationError, Resolver, RuntimeError,
SerializableFunctionFrameInfo, SerializeError,
};
use wasmer_runtime::{
InstanceHandle, LinearMemory, Module, SignatureRegistry, Table, VMFunctionBody,
VMGlobalDefinition, VMSharedSignatureIndex,
InstanceHandle, Module, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex,
};

use wasmer_runtime::{MemoryPlan, TablePlan};
Expand Down
8 changes: 4 additions & 4 deletions lib/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use wasmer_runtime::{InstanceHandle, VMSharedSignatureIndex, VMTrampoline};
/// such as: JIT or Native.
pub trait Engine {
/// Get the tunables
fn tunables(&self) -> &Tunables;
fn tunables(&self) -> &dyn Tunables;

/// Register a signature
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex;
Expand All @@ -30,7 +30,7 @@ pub trait Engine {
fn validate(&self, binary: &[u8]) -> Result<(), CompileError>;

/// Compile a WebAssembly binary
fn compile(&self, binary: &[u8]) -> Result<Arc<CompiledModule>, CompileError>;
fn compile(&self, binary: &[u8]) -> Result<Arc<dyn CompiledModule>, CompileError>;

/// Instantiates a WebAssembly module
unsafe fn instantiate(
Expand All @@ -50,13 +50,13 @@ pub trait Engine {
fn serialize(&self, compiled_module: &dyn CompiledModule) -> Result<Vec<u8>, SerializeError>;

/// Deserializes a WebAssembly module
fn deserialize(&self, bytes: &[u8]) -> Result<Arc<CompiledModule>, DeserializeError>;
fn deserialize(&self, bytes: &[u8]) -> Result<Arc<dyn CompiledModule>, DeserializeError>;

/// Deserializes a WebAssembly module from a path
fn deserialize_from_file(
&self,
file_ref: &Path,
) -> Result<Arc<CompiledModule>, DeserializeError> {
) -> Result<Arc<dyn CompiledModule>, DeserializeError> {
// TODO: Return an IoDeserializeError, so we don't need to map the error
let bytes =
std::fs::read(file_ref).map_err(|e| DeserializeError::Generic(format!("{}", e)))?;
Expand Down
3 changes: 0 additions & 3 deletions lib/engine/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use crate::error::InstantiationError;
use std::sync::Arc;
use wasmer_runtime::InstanceHandle;
use wasmer_runtime::Module;

use downcast_rs::{impl_downcast, Downcast};
Expand Down
5 changes: 3 additions & 2 deletions lib/engine/src/trap/frame_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl ModuleFrameInfo {
}

fn process_function_debug_info(&mut self, local_index: LocalFunctionIndex) {
let mut func = self.frame_infos.get_mut(local_index).unwrap();
let func = self.frame_infos.get_mut(local_index).unwrap();
let processed: CompiledFunctionFrameInfo = match func {
SerializableFunctionFrameInfo::Processed(_) => {
// This should be a no-op on processed info
Expand Down Expand Up @@ -187,7 +187,8 @@ impl GlobalFrameInfo {
pub fn maybe_process_frame(&mut self, pc: usize) -> Option<()> {
let module = self.module_info_mut(pc)?;
let func = module.function_info(pc)?;
module.process_function_debug_info(func.local_index);
let func_local_index = func.local_index;
module.process_function_debug_info(func_local_index);
Some(())
}

Expand Down
Loading

0 comments on commit e77cbd8

Please sign in to comment.