Skip to content

Commit

Permalink
chore: Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
xdoardo committed Jan 15, 2025
1 parent 77e21da commit 19d21ff
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 70 deletions.
7 changes: 6 additions & 1 deletion lib/c-api/src/wasm_c_api/types/extern_.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::super::externals::wasm_extern_t;
use super::{
wasm_functype_t, wasm_globaltype_t, wasm_memorytype_t, wasm_tabletype_t, WasmFunctionType,
WasmGlobalType, WasmMemoryType, WasmTableType,
WasmGlobalType, WasmMemoryType, WasmTableType, WasmTagType,
};
use std::convert::{TryFrom, TryInto};
use std::mem;
Expand All @@ -18,6 +18,7 @@ pub enum wasm_externkind_enum {
WASM_EXTERN_GLOBAL = 1,
WASM_EXTERN_TABLE = 2,
WASM_EXTERN_MEMORY = 3,
WASM_EXTERN_TAG = 4,
}

impl From<ExternType> for wasm_externkind_enum {
Expand All @@ -32,6 +33,7 @@ impl From<&ExternType> for wasm_externkind_enum {
ExternType::Global(_) => Self::WASM_EXTERN_GLOBAL,
ExternType::Table(_) => Self::WASM_EXTERN_TABLE,
ExternType::Memory(_) => Self::WASM_EXTERN_MEMORY,
ExternType::Tag(_) => Self::WASM_EXTERN_TAG,
}
}
}
Expand All @@ -42,6 +44,7 @@ pub(crate) enum WasmExternType {
Global(WasmGlobalType),
Table(WasmTableType),
Memory(WasmMemoryType),
Tag(WasmTagType),
}

#[allow(non_camel_case_types)]
Expand All @@ -66,6 +69,7 @@ impl wasm_externtype_t {
ExternType::Memory(memory_type) => {
WasmExternType::Memory(WasmMemoryType::new(memory_type))
}
ExternType::Tag(tag_type) => WasmExternType::Tag(WasmTagType::new(tag_type)),
},
}
}
Expand Down Expand Up @@ -110,6 +114,7 @@ pub unsafe extern "C" fn wasm_externtype_kind(
WasmExternType::Global(_) => wasm_externkind_enum::WASM_EXTERN_GLOBAL,
WasmExternType::Table(_) => wasm_externkind_enum::WASM_EXTERN_TABLE,
WasmExternType::Memory(_) => wasm_externkind_enum::WASM_EXTERN_MEMORY,
WasmExternType::Tag(_) => wasm_externkind_enum::WASM_EXTERN_TAG,
}) as wasm_externkind_t
}

Expand Down
2 changes: 2 additions & 0 deletions lib/c-api/src/wasm_c_api/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod import;
mod memory;
mod mutability;
mod table;
mod tag;
mod value;

pub use export::*;
Expand All @@ -18,6 +19,7 @@ pub use import::*;
pub use memory::*;
pub use mutability::*;
pub use table::*;
use tag::*;
pub use value::*;

#[allow(non_camel_case_types)]
Expand Down
10 changes: 10 additions & 0 deletions lib/c-api/src/wasm_c_api/types/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use wasmer_types::TagType;

#[derive(Debug, Clone)]
pub(crate) struct WasmTagType {}

impl WasmTagType {
pub(crate) fn new(_tag_type: TagType) -> Self {
panic!()
}
}
3 changes: 3 additions & 0 deletions lib/c-api/src/wasm_c_api/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum wasm_valkind_enum {
WASM_F64 = 3,
WASM_EXTERNREF = 128,
WASM_FUNCREF = 129,
WASM_EXNREF = 130,
}

impl From<Type> for wasm_valkind_enum {
Expand All @@ -24,6 +25,7 @@ impl From<Type> for wasm_valkind_enum {
Type::V128 => todo!("no v128 type in Wasm C API yet!"),
Type::ExternRef => Self::WASM_EXTERNREF,
Type::FuncRef => Self::WASM_FUNCREF,
Type::ExceptionRef => Self::WASM_EXNREF,
}
}
}
Expand All @@ -38,6 +40,7 @@ impl From<wasm_valkind_enum> for Type {
WASM_F64 => Type::F64,
WASM_EXTERNREF => Type::ExternRef,
WASM_FUNCREF => Type::FuncRef,
WASM_EXNREF => Type::ExternRef,
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion lib/c-api/src/wasm_c_api/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ impl std::fmt::Debug for wasm_val_t {
Ok(wasm_valkind_enum::WASM_EXTERNREF) => {
ds.field("anyref", &unsafe { self.of.wref });
}

Ok(wasm_valkind_enum::WASM_FUNCREF) => {
ds.field("funcref", &unsafe { self.of.wref });
}
Ok(wasm_valkind_enum::WASM_EXNREF) => {
ds.field("exnref", &unsafe { self.of.wref });
}
Err(_) => {
ds.field("value", &"Invalid value type");
}
Expand Down Expand Up @@ -152,6 +154,7 @@ pub unsafe extern "C" fn wasm_val_copy(
},
wasm_valkind_enum::WASM_EXTERNREF => wasm_val_inner { wref: val.of.wref },
wasm_valkind_enum::WASM_FUNCREF => wasm_val_inner { wref: val.of.wref },
wasm_valkind_enum::WASM_EXNREF => wasm_val_inner { wref: val.of.wref },
}
}); otherwise ());
}
Expand Down Expand Up @@ -188,6 +191,7 @@ impl TryFrom<wasm_valkind_t> for wasm_valkind_enum {
3 => wasm_valkind_enum::WASM_F64,
128 => wasm_valkind_enum::WASM_EXTERNREF,
129 => wasm_valkind_enum::WASM_FUNCREF,
130 => wasm_valkind_enum::WASM_EXNREF,
_ => return Err("valkind value out of bounds"),
})
}
Expand All @@ -214,6 +218,7 @@ impl TryFrom<&wasm_val_t> for Value {
return Err("EXTERNREF not supported at this time")
}
wasm_valkind_enum::WASM_FUNCREF => return Err("FUNCREF not supported at this time"),
wasm_valkind_enum::WASM_EXNREF => return Err("EXNREF not supported at this time"),
})
}
}
Expand Down
14 changes: 5 additions & 9 deletions lib/compiler-llvm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl SymbolRegistry for ShortNames {
}

impl LLVMCompiler {
#[allow(clippy::too_many_arguments)]
fn compile_native_object(
&self,
target: &Target,
Expand Down Expand Up @@ -311,15 +312,14 @@ impl Compiler for LLVMCompiler {
.relocations
.iter()
.filter(|v| v.kind.needs_got())
.for_each(|v| _ = got_targets.insert(v.reloc_target.clone()));
.for_each(|v| _ = got_targets.insert(v.reloc_target));

compiled_function
.custom_sections
.iter()
.map(|v| v.1.relocations.iter())
.flatten()
.flat_map(|v| v.1.relocations.iter())
.filter(|v| v.kind.needs_got())
.for_each(|v| _ = got_targets.insert(v.reloc_target.clone()));
.for_each(|v| _ = got_targets.insert(v.reloc_target));

if compiled_function
.eh_frame_section_indices
Expand Down Expand Up @@ -449,11 +449,7 @@ impl Compiler for LLVMCompiler {

map.insert(reloc, i);
}
let got_data: Vec<u8> = got_data
.into_iter()
.map(|v| v.to_ne_bytes())
.flatten()
.collect();
let got_data: Vec<u8> = got_data.into_iter().flat_map(|v| v.to_ne_bytes()).collect();
let index = SectionIndex::from_u32(module_custom_sections.len() as u32);
module_custom_sections.push(CustomSection {
protection: CustomSectionProtection::Read,
Expand Down
47 changes: 21 additions & 26 deletions lib/compiler-llvm/src/translator/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {

fn get_or_insert_global_tag(&mut self, tag: u32) -> BasicValueEnum<'ctx> {
if let Some(tag) = self.tags_cache.get(&tag) {
return tag.clone();
return *tag;
}

let tag_ty = self
Expand All @@ -1455,7 +1455,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {

let tag_glbl = tag_glbl.as_basic_value_enum();

self.tags_cache.insert(tag, tag_glbl.clone());
self.tags_cache.insert(tag, tag_glbl);
tag_glbl
}

Expand All @@ -1465,7 +1465,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
signature: &FunctionType,
) -> Result<inkwell::types::StructType<'ctx>, CompileError> {
if let Some(ty) = self.exception_types_cache.get(&tag) {
return Ok(ty.clone());
return Ok(*ty);
}
let types = signature
.params()
Expand All @@ -1474,7 +1474,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
.collect::<Result<Vec<_>, CompileError>>()?;

let ty = self.context.struct_type(&types, false);
self.exception_types_cache.insert(tag, ty.clone());
self.exception_types_cache.insert(tag, ty);
Ok(ty)
}

Expand All @@ -1489,7 +1489,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
if size == 4 {
(tag + 2099) as usize
} else if size == 8 {
let mut base = vec!['w' as u8, 'a' as u8, 's' as u8, 'm' as u8];
let mut base = vec![b'w', b'a', b's', b'm'];
base.append(&mut tag.to_be_bytes().to_vec());
u64::from_be_bytes(base.try_into().unwrap()) as usize
} else {
Expand Down Expand Up @@ -12341,7 +12341,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {

// Read each value from the data ptr.
let values = params
.into_iter()
.iter()
.enumerate()
.map(|(i, v)| {
let name = format!("value{i}");
Expand Down Expand Up @@ -12414,7 +12414,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {

// Read each value from the data ptr.
let mut values = params
.into_iter()
.iter()
.enumerate()
.map(|(i, v)| {
let name = format!("value{i}");
Expand Down Expand Up @@ -12524,26 +12524,21 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
let params = signature.params();
let values = self.state.popn_save_extra(params.len())?;

values
.iter()
.enumerate()
.map(|(i, (v, _))| {
let t = type_to_llvm(self.intrinsics, params[i])?;
if t != v.get_type() {
return Err(CompileError::Codegen(format!(
"Incompatible types: {:?} != {:?}",
t,
v.get_type()
)));
}
values.iter().enumerate().try_for_each(|(i, (v, _))| {
let t = type_to_llvm(self.intrinsics, params[i])?;
if t != v.get_type() {
return Err(CompileError::Codegen(format!(
"Incompatible types: {:?} != {:?}",
t,
v.get_type()
)));
}

Ok(())
})
.collect::<Result<(), CompileError>>()?;
Ok(())
})?;

let exception_type: inkwell::types::StructType = self
.get_or_insert_exception_type(tag_index, signature)?
.clone();
let exception_type: inkwell::types::StructType =
self.get_or_insert_exception_type(tag_index, signature)?;

let size = exception_type.size_of().unwrap();

Expand Down Expand Up @@ -12626,7 +12621,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {

err!(self.builder.build_invoke(
self.intrinsics.rethrow,
&[exc.into()],
&[exc],
unreachable_block,
pad,
"throw",
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler-llvm/src/translator/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,15 @@ impl<'ctx> State<'ctx> {
}

pub(crate) fn get_landingpad(&mut self) -> Option<BasicBlock<'ctx>> {
self.landingpads.back().map(|v| v.catch_block.clone())
self.landingpads.back().map(|v| v.catch_block)
}

pub(crate) fn get_landingpad_for_tag(&mut self, tag: u32) -> Option<BasicBlock<'ctx>> {
// Check if we have a matching landingpad in scope.
if let Some(v) = self.landingpads_scope.get(&tag) {
v.back().cloned()
} else {
self.landingpads.back().map(|v| v.catch_block.clone())
self.landingpads.back().map(|v| v.catch_block)
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/compiler/src/engine/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub struct Artifact {
/// module, corresponding to `ArtifactBuildVariant::Plain`, or loaded
/// from an archive, corresponding to `ArtifactBuildVariant::Archived`.
#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))]
#[allow(clippy::large_enum_variant)]
pub enum ArtifactBuildVariant {
Plain(ArtifactBuild),
Archived(ArtifactBuildFromArchive),
Expand Down
4 changes: 3 additions & 1 deletion lib/compiler/src/engine/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::{
use wasmer_types::{entity::PrimaryMap, LocalFunctionIndex, ModuleInfo};
use wasmer_vm::{libcalls::function_pointer, SectionBodyPtr};

#[allow(clippy::too_many_arguments)]
fn apply_relocation(
body: usize,
r: &impl RelocationLike,
Expand Down Expand Up @@ -255,7 +256,7 @@ fn apply_relocation(
RelocationKind::MachoArm64RelocPointerToGot => unsafe {
if let Some(got) = got_info {
let base = got.0;
let base = std::mem::transmute::<usize, *const usize>(base);
let base = base as *const usize;

if let Some(reloc_idx) = got.1.map.get(&reloc_target) {
let got_address = base.wrapping_add(*reloc_idx);
Expand All @@ -279,6 +280,7 @@ fn apply_relocation(

/// Links a module, patching the allocated functions with the
/// required relocations and jump tables.
#[allow(clippy::too_many_arguments)]
pub fn link_module<'a>(
_module: &ModuleInfo,
allocated_functions: &PrimaryMap<LocalFunctionIndex, FunctionExtent>,
Expand Down
1 change: 0 additions & 1 deletion lib/compiler/src/engine/unwind/systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ impl UnwindRegistry {
// Skip over the CIE and zero-length FDEs.
// LLVM's libunwind emits a warning on zero-length FDEs.
if current != start && len != 0 {
println!("Hehe!");
__register_frame(current);
self.registrations.push(current as usize);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/compiler/src/types/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ pub enum RelocationKind {

impl RelocationKind {
pub fn needs_got(&self) -> bool {
match self {
RelocationKind::MachoArm64RelocGotLoadPage21
| RelocationKind::MachoArm64RelocGotLoadPageoff12
| RelocationKind::MachoArm64RelocPointerToGot
| RelocationKind::MachoX86_64RelocGotLoad
| RelocationKind::MachoX86_64RelocGot => true,
_ => false,
}
matches!(
self,
Self::MachoArm64RelocGotLoadPage21
| Self::MachoArm64RelocGotLoadPageoff12
| Self::MachoArm64RelocPointerToGot
| Self::MachoX86_64RelocGotLoad
| Self::MachoX86_64RelocGot
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,12 @@ impl TagType {

/// Return types.
pub fn results(&self) -> &[Type] {
&self.ty.results()
self.ty.results()
}

/// Parameter types.
pub fn params(&self) -> &[Type] {
&self.ty.params()
self.ty.params()
}

/// Create a new [`TagType`] with the given kind and the associated type.
Expand Down
1 change: 1 addition & 0 deletions lib/types/src/vmoffsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ impl VMOffsets {
/// Offsets for `VMTag` imports.
impl VMOffsets {
/// Return the size of `VMTagImport`.
#[allow(clippy::identity_op)]
pub const fn size_of_vmtag_import(&self) -> u8 {
1 * self.pointer_size
}
Expand Down
Loading

0 comments on commit 19d21ff

Please sign in to comment.