Skip to content

Commit

Permalink
Fix clippy warnings, apply ⛳
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed May 14, 2020
1 parent 6e6196a commit 09efdfe
Show file tree
Hide file tree
Showing 39 changed files with 292 additions and 293 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> anyhow::Result<()> {
let mut spectests = Testsuite {
buffer: String::new(),
path: vec![],
ignores: ignores.clone(),
ignores,
};

let backends = vec!["singlepass", "cranelift", "llvm"];
Expand Down
7 changes: 6 additions & 1 deletion lib/api/src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ impl Exports {
self.map.len()
}

/// Return whether or not there are no exports
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Insert a new export into this `Exports` map.
pub fn insert<S, E>(&mut self, name: S, value: E)
where
Expand All @@ -84,7 +89,7 @@ impl Exports {
/// type checking manually, please use `get_extern`.
pub fn get<'a, T: Exportable<'a>>(&'a self, name: &str) -> Result<&T, ExportError> {
match self.map.get(name) {
None => return Err(ExportError::Missing(name.to_string())),
None => Err(ExportError::Missing(name.to_string())),
Some(extern_) => T::get_self_from_extern(extern_),
}
}
Expand Down
20 changes: 11 additions & 9 deletions lib/api/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ pub enum Extern {
impl Extern {
pub fn ty(&self) -> ExternType {
match self {
Extern::Function(ft) => ExternType::Function(ft.ty().clone()),
Extern::Memory(ft) => ExternType::Memory(ft.ty().clone()),
Extern::Table(tt) => ExternType::Table(tt.ty().clone()),
Extern::Global(gt) => ExternType::Global(gt.ty().clone()),
Extern::Function(ft) => ExternType::Function(ft.ty()),
Extern::Memory(ft) => ExternType::Memory(*ft.ty()),
Extern::Table(tt) => ExternType::Table(*tt.ty()),
Extern::Global(gt) => ExternType::Global(*gt.ty()),
}
}

Expand Down Expand Up @@ -161,7 +161,9 @@ impl Global {

pub fn set(&self, val: Val) -> Result<(), RuntimeError> {
if self.ty().mutability != Mutability::Var {
return Err(RuntimeError::new(format!("immutable global cannot be set")));
return Err(RuntimeError::new(
"immutable global cannot be set".to_string(),
));
}
if val.ty() != self.ty().ty {
return Err(RuntimeError::new(format!(
Expand Down Expand Up @@ -309,7 +311,7 @@ impl Table {
src_index,
len,
)
.map_err(|e| RuntimeError::from_trap(e))?;
.map_err(RuntimeError::from_trap)?;
Ok(())
}

Expand Down Expand Up @@ -447,7 +449,7 @@ impl Memory {
Memory {
store: store.clone(),
owned_by_store: false,
exported: wasmer_export.clone(),
exported: wasmer_export,
}
}
}
Expand Down Expand Up @@ -644,10 +646,10 @@ impl Function {
}

// Load the return values out of `values_vec`.
for (index, value_type) in signature.results().iter().enumerate() {
for (index, &value_type) in signature.results().iter().enumerate() {
unsafe {
let ptr = values_vec.as_ptr().add(index);
results[index] = Val::read_value_from(ptr, value_type.clone());
results[index] = Val::read_value_from(ptr, value_type);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl Instance {
.map(|export| {
let name = export.name().to_string();
let export = handle.lookup(&name).expect("export");
let extern_ = Extern::from_export(store, export.clone());
(name.to_string(), extern_)
let extern_ = Extern::from_export(store, export);
(name, extern_)
})
.collect::<Exports>();

Expand Down
4 changes: 2 additions & 2 deletions lib/cache/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl WasmHash {
/// is, in fact, a wasm module.
pub fn generate(wasm: &[u8]) -> Self {
let hash = blake3::hash(wasm);
WasmHash::new(hash.into())
Self::new(hash.into())
}

pub(crate) fn into_array(self) -> [u8; 32] {
Expand Down Expand Up @@ -56,7 +56,7 @@ impl FromStr for WasmHash {
));
}
use std::convert::TryInto;
Ok(WasmHash(bytes[0..32].try_into().map_err(|e| {
Ok(Self(bytes[0..32].try_into().map_err(|e| {
DeserializeError::Generic(format!("Could not get first 32 bytes: {}", e))
})?))
}
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler-cranelift/src/trampoline/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn make_wasm_trampoline(
})
.collect::<Vec<_>>();

let new_sig = builder.import_signature(signature.clone());
let new_sig = builder.import_signature(signature);

let call = builder
.ins()
Expand Down
8 changes: 4 additions & 4 deletions lib/compiler-cranelift/src/translator/translation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ pub fn signature_to_cranelift_ir(
target_config: &TargetFrontendConfig,
) -> ir::Signature {
let mut sig = ir::Signature::new(target_config.default_call_conv);
sig.params.extend(signature.params().iter().map(|ty| {
let cret_arg: ir::Type = type_to_irtype(ty.clone(), target_config)
sig.params.extend(signature.params().iter().map(|&ty| {
let cret_arg: ir::Type = type_to_irtype(ty, target_config)
.expect("only numeric types are supported in function signatures");
AbiParam::new(cret_arg)
}));
sig.returns.extend(signature.results().iter().map(|ty| {
let cret_arg: ir::Type = type_to_irtype(ty.clone(), target_config)
sig.returns.extend(signature.results().iter().map(|&ty| {
let cret_arg: ir::Type = type_to_irtype(ty, target_config)
.expect("only numeric types are supported in function signatures");
AbiParam::new(cret_arg)
}));
Expand Down
7 changes: 6 additions & 1 deletion lib/compiler/src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl SectionBody {
}

/// Extends the section by appending bytes from another section.
pub fn append(&mut self, body: &SectionBody) {
pub fn append(&mut self, body: &Self) {
self.0.extend(&body.0);
}

Expand All @@ -68,4 +68,9 @@ impl SectionBody {
pub fn len(&self) -> usize {
self.0.len()
}

/// Returns whether or not the section body is empty.
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
34 changes: 17 additions & 17 deletions lib/compiler/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,47 @@ impl CpuFeature {

if let Some(info) = cpuid.get_feature_info() {
if info.has_sse2() {
features.insert(CpuFeature::SSE2);
features.insert(Self::SSE2);
}
if info.has_sse3() {
features.insert(CpuFeature::SSE3);
features.insert(Self::SSE3);
}
if info.has_ssse3() {
features.insert(CpuFeature::SSSE3);
features.insert(Self::SSSE3);
}
if info.has_sse41() {
features.insert(CpuFeature::SSE41);
features.insert(Self::SSE41);
}
if info.has_sse42() {
features.insert(CpuFeature::SSE42);
features.insert(Self::SSE42);
}
if info.has_popcnt() {
features.insert(CpuFeature::POPCNT);
features.insert(Self::POPCNT);
}
if info.has_avx() {
features.insert(CpuFeature::AVX);
features.insert(Self::AVX);
}
}
if let Some(info) = cpuid.get_extended_feature_info() {
if info.has_bmi1() {
features.insert(CpuFeature::BMI1);
features.insert(Self::BMI1);
}
if info.has_bmi2() {
features.insert(CpuFeature::BMI2);
features.insert(Self::BMI2);
}
if info.has_avx2() {
features.insert(CpuFeature::AVX2);
features.insert(Self::AVX2);
}
if info.has_avx512dq() {
features.insert(CpuFeature::AVX512DQ);
features.insert(Self::AVX512DQ);
}
if info.has_avx512vl() {
features.insert(CpuFeature::AVX512VL);
features.insert(Self::AVX512VL);
}
}
if let Some(info) = cpuid.get_extended_function_info() {
if info.has_lzcnt() {
features.insert(CpuFeature::LZCNT);
features.insert(Self::LZCNT);
}
}
features
Expand All @@ -111,8 +111,8 @@ pub struct Target {

impl Target {
/// Creates a new target given a triple
pub fn new(triple: Triple, cpu_features: EnumSet<CpuFeature>) -> Target {
Target {
pub fn new(triple: Triple, cpu_features: EnumSet<CpuFeature>) -> Self {
Self {
triple,
cpu_features,
}
Expand All @@ -131,8 +131,8 @@ impl Target {

/// The default for the Target will use the HOST as the triple
impl Default for Target {
fn default() -> Target {
Target {
fn default() -> Self {
Self {
triple: Triple::host(),
cpu_features: CpuFeature::for_host(),
}
Expand Down
12 changes: 6 additions & 6 deletions lib/compiler/src/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ impl CompiledFunctionUnwindInfo {
/// Retuns true is no unwind info data.
pub fn is_empty(&self) -> bool {
match self {
CompiledFunctionUnwindInfo::Windows(d) => d.is_empty(),
CompiledFunctionUnwindInfo::FrameLayout(c, _, _) => c.is_empty(),
Self::Windows(d) => d.is_empty(),
Self::FrameLayout(c, _, _) => c.is_empty(),
}
}

/// Returns size of serilized unwind info.
pub fn len(&self) -> usize {
match self {
CompiledFunctionUnwindInfo::Windows(d) => d.len(),
CompiledFunctionUnwindInfo::FrameLayout(c, _, _) => c.len(),
Self::Windows(d) => d.len(),
Self::FrameLayout(c, _, _) => c.len(),
}
}

/// Serializes data into byte array.
pub fn serialize(&self, dest: &mut [u8], relocs: &mut Vec<FunctionTableReloc>) {
match self {
CompiledFunctionUnwindInfo::Windows(d) => {
Self::Windows(d) => {
dest.copy_from_slice(d);
}
CompiledFunctionUnwindInfo::FrameLayout(code, _fde_offset, r) => {
Self::FrameLayout(code, _fde_offset, r) => {
dest.copy_from_slice(code);
r.iter().for_each(move |r| {
assert_eq!(r.2, 8);
Expand Down
2 changes: 1 addition & 1 deletion lib/engine-jit/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl JITEngineInner {
}

/// Compile the given function bodies.
pub(crate) fn allocate<'data>(
pub(crate) fn allocate(
&mut self,
module: &Module,
functions: &PrimaryMap<LocalFunctionIndex, FunctionBody>,
Expand Down
10 changes: 10 additions & 0 deletions lib/engine-jit/src/function_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ impl FunctionTable {
self.functions.len()
}

/// Returns whether or not the function table is empty.
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Adds a function to the table based off of the start offset, end offset, and unwind offset.
///
/// The offsets are from the "module base", which is provided when the table is published.
Expand Down Expand Up @@ -131,6 +136,11 @@ impl FunctionTable {
self.functions.len()
}

/// Returns whether or not the function table is empty.
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Adds a function to the table based off of the start offset, end offset, and unwind offset.
///
/// The offsets are from the "module base", which is provided when the table is published.
Expand Down
9 changes: 3 additions & 6 deletions lib/engine-jit/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ impl CompiledModule {
let mut jit_compiler = jit.compiler_mut();
let tunables = jit.tunables();

let translation = environ
.translate(data)
.map_err(|error| CompileError::Wasm(error))?;
let translation = environ.translate(data).map_err(CompileError::Wasm)?;

let memory_plans: PrimaryMap<MemoryIndex, MemoryPlan> = translation
.module
Expand Down Expand Up @@ -132,15 +130,14 @@ impl CompiledModule {
}

/// Deserialize a CompiledModule
pub fn deserialize(jit: &JITEngine, bytes: &[u8]) -> Result<CompiledModule, DeserializeError> {
pub fn deserialize(jit: &JITEngine, bytes: &[u8]) -> Result<Self, DeserializeError> {
// let r = flexbuffers::Reader::get_root(bytes).map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e)))?;
// let serializable = SerializableModule::deserialize(r).map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e)))?;

let serializable: SerializableModule = bincode::deserialize(bytes)
.map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e)))?;

Self::from_parts(&mut jit.compiler_mut(), serializable)
.map_err(|e| DeserializeError::Compiler(e))
Self::from_parts(&mut jit.compiler_mut(), serializable).map_err(DeserializeError::Compiler)
}

/// Construct a `CompiledModule` from component parts.
Expand Down
14 changes: 7 additions & 7 deletions lib/engine/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ fn get_extern_from_import(module: &Module, import_index: &ImportIndex) -> Extern
ExternType::Function(func)
}
ImportIndex::Table(index) => {
let table = module.tables[*index].clone();
let table = module.tables[*index];
ExternType::Table(table)
}
ImportIndex::Memory(index) => {
let memory = module.memories[*index].clone();
let memory = module.memories[*index];
ExternType::Memory(memory)
}
ImportIndex::Global(index) => {
let global = module.globals[*index].clone();
let global = module.globals[*index];
ExternType::Global(global)
}
}
Expand All @@ -65,19 +65,19 @@ fn get_extern_from_export(
) -> ExternType {
match export {
Export::Function(ref f) => {
let func = signatures.lookup(f.signature).unwrap().clone();
let func = signatures.lookup(f.signature).unwrap();
ExternType::Function(func)
}
Export::Table(ref t) => {
let table = t.plan().table.clone();
let table = t.plan().table;
ExternType::Table(table)
}
Export::Memory(ref m) => {
let memory = m.plan().memory.clone();
let memory = m.plan().memory;
ExternType::Memory(memory)
}
Export::Global(ref g) => {
let global = g.global.clone();
let global = g.global;
ExternType::Global(global)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'de> Deserialize<'de> for SerializableFunctionFrameInfo {
where
D: Deserializer<'de>,
{
Ok(SerializableFunctionFrameInfo::Unprocessed(
Ok(Self::Unprocessed(
deserializer.deserialize_byte_buf(FunctionFrameInfoVisitor)?,
))
}
Expand Down
Loading

0 comments on commit 09efdfe

Please sign in to comment.