diff --git a/lightbeam/src/backend.rs b/lightbeam/src/backend.rs index 77d351ea2c..b77fdb9d34 100644 --- a/lightbeam/src/backend.rs +++ b/lightbeam/src/backend.rs @@ -1,3 +1,5 @@ +#![allow(clippy::float_cmp)] + use crate::error::Error; use crate::microwasm::{BrTarget, Ieee32, Ieee64, SignlessType, Type, Value, F32, F64, I32, I64}; use crate::module::ModuleContext; @@ -259,7 +261,7 @@ impl GPRs { self.bits |= 1 << gpr; } - fn is_free(&self, gpr: RegId) -> bool { + fn is_free(self, gpr: RegId) -> bool { (self.bits & (1 << gpr)) != 0 } } @@ -629,7 +631,7 @@ impl TranslatedCodeSection { .func_starts .get(idx + 1) .map(|i| i.0) - .unwrap_or(self.exec_buf.len()); + .unwrap_or_else(|| self.exec_buf.len()); self.func_starts[idx].0..end } @@ -2299,7 +2301,7 @@ impl<'this, M: ModuleContext> Context<'this, M> { let label = target .into() .label() - .map(|c| *c) + .copied() .unwrap_or_else(|| self.ret_label()); let cond = match val { @@ -2332,7 +2334,7 @@ impl<'this, M: ModuleContext> Context<'this, M> { let label = target .into() .label() - .map(|c| *c) + .copied() .unwrap_or_else(|| self.ret_label()); let cond = match val { @@ -2834,22 +2836,20 @@ impl<'this, M: ModuleContext> Context<'this, M> { dynasm!(self.asm ; mov DWORD [rsp + out_offset], i as i32 ); - } else { - if let Some(scratch) = self.take_reg(I64) { - dynasm!(self.asm - ; mov Rq(scratch.rq().unwrap()), QWORD i - ; mov [rsp + out_offset], Rq(scratch.rq().unwrap()) - ); + } else if let Some(scratch) = self.take_reg(I64) { + dynasm!(self.asm + ; mov Rq(scratch.rq().unwrap()), QWORD i + ; mov [rsp + out_offset], Rq(scratch.rq().unwrap()) + ); - self.block_state.regs.release(scratch); - } else { - dynasm!(self.asm - ; push rax - ; mov rax, QWORD i - ; mov [rsp + out_offset + WORD_SIZE as i32], rax - ; pop rax - ); - } + self.block_state.regs.release(scratch); + } else { + dynasm!(self.asm + ; push rax + ; mov rax, QWORD i + ; mov [rsp + out_offset + WORD_SIZE as i32], rax + ; pop rax + ); } } (ValueLocation::Stack(in_offset), CCLoc::Reg(out_reg)) => { @@ -4970,7 +4970,7 @@ impl<'this, M: ModuleContext> Context<'this, M> { self.block_state.depth.reserve(1); } - let depth = self.block_state.depth.clone(); + let depth = self.block_state.depth; self.pass_outgoing_args(&locs); // 2 bytes for the 64-bit `mov` opcode + register ident, the rest is the immediate @@ -5083,25 +5083,21 @@ impl<'this, M: ModuleContext> Context<'this, M> { let mut slice = &mut stack[start..end]; - loop { - if let Some((first, rest)) = slice.split_first_mut() { - if let ValueLocation::Reg(vreg) = *first { - if regs.into_iter().any(|r| *r == vreg) { - let old = *first; - *first = self.push_physical(old); - for val in &mut *rest { - if *val == old { - self.free_value(*val); - *val = *first; - } + while let Some((first, rest)) = slice.split_first_mut() { + if let ValueLocation::Reg(vreg) = *first { + if regs.into_iter().any(|r| *r == vreg) { + let old = *first; + *first = self.push_physical(old); + for val in &mut *rest { + if *val == old { + self.free_value(*val); + *val = *first; } } } - - slice = rest; - } else { - break; } + + slice = rest; } mem::replace(&mut self.block_state.stack, stack); @@ -5226,7 +5222,7 @@ impl<'this, M: ModuleContext> Context<'this, M> { ; push Rq(VMCTX) ); self.block_state.depth.reserve(1); - let depth = self.block_state.depth.clone(); + let depth = self.block_state.depth; self.pass_outgoing_args(&locs); @@ -5380,7 +5376,7 @@ impl<'this, M: ModuleContext> Context<'this, M> { ; push Rq(VMCTX) ); self.block_state.depth.reserve(1); - let depth = self.block_state.depth.clone(); + let depth = self.block_state.depth; self.save_volatile(..locs.len()); self.pass_outgoing_args(&locs); diff --git a/lightbeam/src/disassemble.rs b/lightbeam/src/disassemble.rs index 10366b0040..acfe4cfbcd 100644 --- a/lightbeam/src/disassemble.rs +++ b/lightbeam/src/disassemble.rs @@ -19,14 +19,10 @@ pub fn disassemble( let address = i.address(); - loop { - if let Some((offset, op)) = ops.first() { - if offset.0 as u64 <= address { - ops = &ops[1..]; - println!("{}", op); - } else { - break; - } + while let Some((offset, op)) = ops.first() { + if offset.0 as u64 <= address { + ops = &ops[1..]; + println!("{}", op); } else { break; } diff --git a/lightbeam/src/microwasm.rs b/lightbeam/src/microwasm.rs index ab20037288..6d485de51c 100644 --- a/lightbeam/src/microwasm.rs +++ b/lightbeam/src/microwasm.rs @@ -24,9 +24,7 @@ where let p = " "; for op in microwasm { - if op.is_label() { - writeln!(out, "{}", op)?; - } else if op.is_block() { + if op.is_label() || op.is_block() { writeln!(out, "{}", op)?; } else { writeln!(out, "{}{}", p, op)?; diff --git a/wasmtime-debug/src/lib.rs b/wasmtime-debug/src/lib.rs index ea28e59ba5..9519543743 100644 --- a/wasmtime-debug/src/lib.rs +++ b/wasmtime-debug/src/lib.rs @@ -1,5 +1,7 @@ //! Debug utils for WebAssembly using Cranelift. +#![allow(clippy::cast_ptr_alignment)] + use alloc::string::String; use alloc::vec::Vec; use cranelift_codegen::isa::TargetFrontendConfig; @@ -66,9 +68,9 @@ pub fn emit_debugsections_image( vmctx_info: &ModuleVmctxInfo, at: &ModuleAddressMap, ranges: &ValueLabelsRanges, - funcs: &Vec<(*const u8, usize)>, + funcs: &[(*const u8, usize)], ) -> Result, Error> { - let ref func_offsets = funcs + let func_offsets = &funcs .iter() .map(|(ptr, _)| *ptr as u64) .collect::>(); @@ -79,7 +81,7 @@ pub fn emit_debugsections_image( // Assuming all functions in the same code block, looking min/max of its range. assert!(funcs.len() > 0); let mut segment_body: (usize, usize) = (!0, 0); - for (body_ptr, body_len) in funcs.iter() { + for (body_ptr, body_len) in funcs { segment_body.0 = ::core::cmp::min(segment_body.0, *body_ptr as usize); segment_body.1 = ::core::cmp::max(segment_body.1, *body_ptr as usize + body_len); } @@ -168,8 +170,7 @@ fn convert_faerie_elf_to_loadable_file(bytes: &mut Vec, code_ptr: *const u8) // LLDB wants segment with virtual address set, placing them at the end of ELF. let ph_off = bytes.len(); if let Some((sh_offset, v_offset, sh_size)) = segment { - let mut segment = Vec::with_capacity(0x38); - segment.resize(0x38, 0); + let segment = vec![0; 0x38]; unsafe { *(segment.as_ptr() as *mut u32) = /* PT_LOAD */ 0x1; *(segment.as_ptr().offset(0x8) as *mut u64) = sh_offset; diff --git a/wasmtime-debug/src/transform/attr.rs b/wasmtime-debug/src/transform/attr.rs index 75d959d84e..2b9ee70c5b 100644 --- a/wasmtime-debug/src/transform/attr.rs +++ b/wasmtime-debug/src/transform/attr.rs @@ -39,7 +39,7 @@ pub(crate) fn clone_die_attributes<'a, R>( context: &DebugInputContext, addr_tr: &'a AddressTransform, frame_info: Option<&FunctionFrameInfo>, - unit_encoding: &gimli::Encoding, + unit_encoding: gimli::Encoding, out_unit: &mut write::Unit, current_scope_id: write::UnitEntryId, subprogram_range_builder: Option, @@ -58,15 +58,13 @@ where let range_info = if let Some(subprogram_range_builder) = subprogram_range_builder { subprogram_range_builder + } else if entry.tag() == gimli::DW_TAG_compile_unit { + // FIXME currently address_transform operate on a single func range, + // once it is fixed we can properly set DW_AT_ranges attribute. + // Using for now DW_AT_low_pc = 0. + RangeInfoBuilder::Position(0) } else { - if entry.tag() == gimli::DW_TAG_compile_unit { - // FIXME currently address_transform operate on a single func range, - // once it is fixed we can properly set DW_AT_ranges attribute. - // Using for now DW_AT_low_pc = 0. - RangeInfoBuilder::Position(0) - } else { - RangeInfoBuilder::from(entry, context, unit_encoding, cu_low_pc)? - } + RangeInfoBuilder::from(entry, context, unit_encoding, cu_low_pc)? }; range_info.build(addr_tr, out_unit, current_scope_id); @@ -127,7 +125,7 @@ where let low_pc = 0; let mut locs = context.loclists.locations( r, - *unit_encoding, + unit_encoding, low_pc, &context.debug_addr, context.debug_addr_base, @@ -190,7 +188,7 @@ where if let Some(scope_ranges) = scope_ranges { let exprs = expr.build_with_locals(scope_ranges, addr_tr, frame_info, endian); - if exprs.len() == 0 { + if exprs.is_empty() { continue; } let found_single_expr = { diff --git a/wasmtime-debug/src/transform/expression.rs b/wasmtime-debug/src/transform/expression.rs index 7fa43185df..0d5fbaa9ce 100644 --- a/wasmtime-debug/src/transform/expression.rs +++ b/wasmtime-debug/src/transform/expression.rs @@ -176,7 +176,7 @@ impl CompiledExpression { if let [CompiledExpressionPart::Code(_)] = self.parts.as_slice() { true } else { - self.parts.len() == 0 + self.parts.is_empty() } } @@ -195,7 +195,7 @@ impl CompiledExpression { frame_info: Option<&FunctionFrameInfo>, endian: gimli::RunTimeEndian, ) -> alloc::vec::Vec<(write::Address, u64, write::Expression)> { - if scope.len() == 0 { + if scope.is_empty() { return vec![]; } @@ -286,13 +286,13 @@ impl CompiledExpression { )); } - return result; + result } } pub fn compile_expression( expr: &Expression, - encoding: &gimli::Encoding, + encoding: gimli::Encoding, frame_base: Option<&CompiledExpression>, ) -> Result, Error> where @@ -326,7 +326,7 @@ where parts.push(CompiledExpressionPart::Local(label)); } else { let pos = pc.offset_from(&expr.0).into_u64() as usize; - let op = Operation::parse(&mut pc, &expr.0, *encoding)?; + let op = Operation::parse(&mut pc, &expr.0, encoding)?; match op { Operation::Literal { .. } | Operation::PlusConstant { .. } => (), Operation::StackValue => { diff --git a/wasmtime-debug/src/transform/line_program.rs b/wasmtime-debug/src/transform/line_program.rs index 1375d6ccd6..8b6204b4d0 100644 --- a/wasmtime-debug/src/transform/line_program.rs +++ b/wasmtime-debug/src/transform/line_program.rs @@ -43,7 +43,7 @@ pub(crate) fn clone_line_program( unit: &Unit, root: &DebuggingInformationEntry, addr_tr: &AddressTransform, - out_encoding: &gimli::Encoding, + out_encoding: gimli::Encoding, debug_str: &DebugStr, debug_line: &DebugLine, out_strings: &mut write::StringTable, @@ -89,7 +89,7 @@ where line_range: header.line_range(), }; let mut out_program = write::LineProgram::new( - *out_encoding, + out_encoding, line_encoding, out_comp_dir, out_comp_name, diff --git a/wasmtime-debug/src/transform/mod.rs b/wasmtime-debug/src/transform/mod.rs index b18940d11c..4633b61ac9 100644 --- a/wasmtime-debug/src/transform/mod.rs +++ b/wasmtime-debug/src/transform/mod.rs @@ -90,7 +90,7 @@ pub fn transform_dwarf( &context, &addr_tr, &ranges, - &out_encoding, + out_encoding, &vmctx_info, &mut out_units, &mut out_strings, @@ -104,7 +104,7 @@ pub fn transform_dwarf( &vmctx_info, &ranges, &translated, - &out_encoding, + out_encoding, &mut out_units, &mut out_strings, )?; diff --git a/wasmtime-debug/src/transform/range_info_builder.rs b/wasmtime-debug/src/transform/range_info_builder.rs index 0ba45b0487..7a26d0a1ab 100644 --- a/wasmtime-debug/src/transform/range_info_builder.rs +++ b/wasmtime-debug/src/transform/range_info_builder.rs @@ -24,7 +24,7 @@ impl RangeInfoBuilder { pub(crate) fn from( entry: &DebuggingInformationEntry, context: &DebugInputContext, - unit_encoding: &gimli::Encoding, + unit_encoding: gimli::Encoding, cu_low_pc: u64, ) -> Result where @@ -53,7 +53,7 @@ impl RangeInfoBuilder { pub(crate) fn from_ranges_ref( ranges: RangeListsOffset, context: &DebugInputContext, - unit_encoding: &gimli::Encoding, + unit_encoding: gimli::Encoding, cu_low_pc: u64, ) -> Result where @@ -61,7 +61,7 @@ impl RangeInfoBuilder { { let mut ranges = context.rnglists.ranges( ranges, - *unit_encoding, + unit_encoding, cu_low_pc, &context.debug_addr, context.debug_addr_base, @@ -74,17 +74,17 @@ impl RangeInfoBuilder { result.push((range.begin, range.end)); } - return Ok(if result.len() > 0 { + Ok(if result.len() > 0 { RangeInfoBuilder::Ranges(result) } else { RangeInfoBuilder::Undefined - }); + }) } pub(crate) fn from_subprogram_die( entry: &DebuggingInformationEntry, context: &DebugInputContext, - unit_encoding: &gimli::Encoding, + unit_encoding: gimli::Encoding, addr_tr: &AddressTransform, cu_low_pc: u64, ) -> Result @@ -99,7 +99,7 @@ impl RangeInfoBuilder { { let mut ranges = context.rnglists.ranges( r, - *unit_encoding, + unit_encoding, cu_low_pc, &context.debug_addr, context.debug_addr_base, diff --git a/wasmtime-debug/src/transform/simulate.rs b/wasmtime-debug/src/transform/simulate.rs index 9ebfdf658b..eb679b9bfb 100644 --- a/wasmtime-debug/src/transform/simulate.rs +++ b/wasmtime-debug/src/transform/simulate.rs @@ -21,7 +21,7 @@ const PRODUCER_NAME: &str = "wasmtime"; fn generate_line_info( addr_tr: &AddressTransform, translated: &HashSet, - out_encoding: &gimli::Encoding, + out_encoding: gimli::Encoding, w: &WasmFileInfo, comp_dir_id: write::StringId, name_id: write::StringId, @@ -33,7 +33,7 @@ fn generate_line_info( let line_encoding = LineEncoding::default(); let mut out_program = write::LineProgram::new( - *out_encoding, + out_encoding, line_encoding, out_comp_dir, out_comp_name, @@ -181,7 +181,7 @@ fn generate_vars( ) { let vmctx_label = get_vmctx_value_label(); - for (label, _range) in frame_info.value_ranges { + for label in frame_info.value_ranges.keys() { if label.index() == vmctx_label.index() { append_vmctx_info( unit, @@ -206,7 +206,7 @@ fn generate_vars( let loc_list_id = { let endian = gimli::RunTimeEndian::Little; - let expr = CompiledExpression::from_label(label.clone()); + let expr = CompiledExpression::from_label(*label); let mut locs = Vec::new(); for (begin, length, data) in expr.build_with_locals(scope_ranges, addr_tr, Some(frame_info), endian) @@ -254,7 +254,7 @@ pub fn generate_simulated_dwarf( vmctx_info: &ModuleVmctxInfo, ranges: &ValueLabelsRanges, translated: &HashSet, - out_encoding: &gimli::Encoding, + out_encoding: gimli::Encoding, out_units: &mut write::UnitTable, out_strings: &mut write::StringTable, ) -> Result<(), Error> { @@ -288,7 +288,7 @@ pub fn generate_simulated_dwarf( name, )?; - let unit_id = out_units.add(write::Unit::new(*out_encoding, out_program)); + let unit_id = out_units.add(write::Unit::new(out_encoding, out_program)); let unit = out_units.get_mut(unit_id); let root_id = unit.root(); diff --git a/wasmtime-debug/src/transform/unit.rs b/wasmtime-debug/src/transform/unit.rs index d3a092d1a3..68f6e5cc48 100644 --- a/wasmtime-debug/src/transform/unit.rs +++ b/wasmtime-debug/src/transform/unit.rs @@ -157,7 +157,7 @@ pub(crate) fn clone_unit<'a, R>( context: &DebugInputContext, addr_tr: &'a AddressTransform, value_ranges: &'a ValueLabelsRanges, - out_encoding: &gimli::Encoding, + out_encoding: gimli::Encoding, module_info: &ModuleVmctxInfo, out_units: &mut write::UnitTable, out_strings: &mut write::StringTable, @@ -186,7 +186,7 @@ where )?; if entry.tag() == gimli::DW_TAG_compile_unit { - let unit_id = out_units.add(write::Unit::new(*out_encoding, out_line_program)); + let unit_id = out_units.add(write::Unit::new(out_encoding, out_line_program)); let comp_unit = out_units.get_mut(unit_id); let root_id = comp_unit.root(); @@ -206,7 +206,7 @@ where context, addr_tr, None, - &unit.encoding(), + unit.encoding(), comp_unit, root_id, None, @@ -263,7 +263,7 @@ where let range_builder = RangeInfoBuilder::from_subprogram_die( entry, context, - &unit.encoding(), + unit.encoding(), addr_tr, cu_low_pc, )?; @@ -285,7 +285,7 @@ where let ranges = entry.attr_value(gimli::DW_AT_ranges)?; if high_pc.is_some() || ranges.is_some() { let range_builder = - RangeInfoBuilder::from(entry, context, &unit.encoding(), cu_low_pc)?; + RangeInfoBuilder::from(entry, context, unit.encoding(), cu_low_pc)?; current_scope_ranges.push(new_stack_len, range_builder.get_ranges(addr_tr)); Some(range_builder) } else { @@ -302,7 +302,7 @@ where } if let Some(AttributeValue::Exprloc(expr)) = entry.attr_value(gimli::DW_AT_frame_base)? { - if let Some(expr) = compile_expression(&expr, &unit.encoding(), None)? { + if let Some(expr) = compile_expression(&expr, unit.encoding(), None)? { current_frame_base.push(new_stack_len, expr); } } @@ -339,7 +339,7 @@ where context, addr_tr, current_value_range.top(), - &unit.encoding(), + unit.encoding(), &mut comp_unit, die_id, range_builder, diff --git a/wasmtime-environ/src/cache.rs b/wasmtime-environ/src/cache.rs index 27b1ff9f97..6bfaf6bc80 100644 --- a/wasmtime-environ/src/cache.rs +++ b/wasmtime-environ/src/cache.rs @@ -39,13 +39,11 @@ lazy_static! { .map_err(|_| warn!("Failed to get metadata of current executable")) .ok() }) - .and_then(|mtime| { - Some(match mtime.duration_since(std::time::UNIX_EPOCH) { - Ok(duration) => format!("{}", duration.as_millis()), - Err(err) => format!("m{}", err.duration().as_millis()), - }) + .map(|mtime| match mtime.duration_since(std::time::UNIX_EPOCH) { + Ok(duration) => format!("{}", duration.as_millis()), + Err(err) => format!("m{}", err.duration().as_millis()), }) - .unwrap_or("no-mtime".to_string()) + .unwrap_or_else(|| "no-mtime".to_string()) }; } diff --git a/wasmtime-environ/src/cache/config.rs b/wasmtime-environ/src/cache/config.rs index 4487318052..f993bf6586 100644 --- a/wasmtime-environ/src/cache/config.rs +++ b/wasmtime-environ/src/cache/config.rs @@ -103,7 +103,7 @@ static INIT_CALLED: AtomicBool = AtomicBool::new(false); /// If system has not been initialized, it disables it. /// You mustn't call init() after it. pub fn cache_config() -> &'static CacheConfig { - CONFIG.call_once(|| CacheConfig::new_cache_disabled()) + CONFIG.call_once(CacheConfig::new_cache_disabled) } /// Initializes the cache system. Should be called exactly once, @@ -196,7 +196,7 @@ lazy_static! { static ref DEFAULT_CONFIG_PATH: Result = PROJECT_DIRS .as_ref() .map(|proj_dirs| proj_dirs.config_dir().join("wasmtime-cache-config.toml")) - .ok_or("Config file not specified and failed to get the default".to_string()); + .ok_or_else(|| "Config file not specified and failed to get the default".to_string()); } // Default settings, you're welcome to tune them! @@ -312,7 +312,7 @@ generate_deserializer!(deserialize_percent(num: u8, unit: &str) -> Option { } }); -static CACHE_IMPROPER_CONFIG_ERROR_MSG: &'static str = +static CACHE_IMPROPER_CONFIG_ERROR_MSG: &str = "Cache system should be enabled and all settings must be validated or defaulted"; macro_rules! generate_setting_getter { diff --git a/wasmtime-environ/src/cache/worker.rs b/wasmtime-environ/src/cache/worker.rs index 469bccd8eb..8648c1762d 100644 --- a/wasmtime-environ/src/cache/worker.rs +++ b/wasmtime-environ/src/cache/worker.rs @@ -105,7 +105,7 @@ impl Worker { Self { sender: tx, #[cfg(test)] - stats: stats, + stats, } } @@ -610,7 +610,7 @@ impl WorkerThread { (0..=1, true) => enter_dir(vec, &path, level + 1, cache_config), (0..=1, false) => { if level == 0 && path.file_stem() == Some(OsStr::new(".cleanup")) { - if let Some(_) = path.extension() { + if path.extension().is_some() { // assume it's cleanup lock if !is_fs_lock_expired( Some(&entry), @@ -699,9 +699,11 @@ impl WorkerThread { "Failed to get metadata/mtime, deleting the file", stats_path ); + // .into() called for the SystemTimeStub if cfg(test) + #[allow(clippy::identity_conversion)] vec.push(CacheEntry::Recognized { path: mod_path.to_path_buf(), - mtime: stats_mtime.into(), // .into() called for the SystemTimeStub if cfg(test) + mtime: stats_mtime.into(), size: mod_metadata.len(), }) } @@ -715,9 +717,11 @@ impl WorkerThread { "Failed to get metadata/mtime, deleting the file", mod_path ); + // .into() called for the SystemTimeStub if cfg(test) + #[allow(clippy::identity_conversion)] vec.push(CacheEntry::Recognized { path: mod_path.to_path_buf(), - mtime: mod_mtime.into(), // .into() called for the SystemTimeStub if cfg(test) + mtime: mod_mtime.into(), size: mod_metadata.len(), }) } diff --git a/wasmtime-environ/src/cranelift.rs b/wasmtime-environ/src/cranelift.rs index 3857012d81..2a20278927 100644 --- a/wasmtime-environ/src/cranelift.rs +++ b/wasmtime-environ/src/cranelift.rs @@ -298,7 +298,7 @@ impl crate::compilation::Compiler for Cranelift { if let Some(address_transform) = address_transform { address_transforms.push(address_transform); } - value_ranges.push(ranges.unwrap_or(std::collections::HashMap::new())); + value_ranges.push(ranges.unwrap_or_default()); stack_slots.push(sss); traps.push(function_traps); }, diff --git a/wasmtime-environ/src/func_environ.rs b/wasmtime-environ/src/func_environ.rs index 2161ae4439..a0da1c4acb 100644 --- a/wasmtime-environ/src/func_environ.rs +++ b/wasmtime-environ/src/func_environ.rs @@ -239,13 +239,13 @@ impl lightbeam::ModuleContext for FuncEnvironment<'_> { fn defined_func_index(&self, func_index: u32) -> Option { self.module .defined_func_index(FuncIndex::from_u32(func_index)) - .map(|i| i.as_u32()) + .map(DefinedFuncIndex::as_u32) } fn defined_global_index(&self, global_index: u32) -> Option { self.module .defined_global_index(GlobalIndex::from_u32(global_index)) - .map(|i| i.as_u32()) + .map(DefinedGlobalIndex::as_u32) } fn global_type(&self, global_index: u32) -> &Self::GlobalType { @@ -263,13 +263,13 @@ impl lightbeam::ModuleContext for FuncEnvironment<'_> { fn defined_table_index(&self, table_index: u32) -> Option { self.module .defined_table_index(TableIndex::from_u32(table_index)) - .map(|i| i.as_u32()) + .map(DefinedTableIndex::as_u32) } fn defined_memory_index(&self, memory_index: u32) -> Option { self.module .defined_memory_index(MemoryIndex::from_u32(memory_index)) - .map(|i| i.as_u32()) + .map(DefinedMemoryIndex::as_u32) } fn vmctx_vmfunction_import_body(&self, func_index: u32) -> u32 { diff --git a/wasmtime-environ/src/module.rs b/wasmtime-environ/src/module.rs index 88595230ad..3742b9713b 100644 --- a/wasmtime-environ/src/module.rs +++ b/wasmtime-environ/src/module.rs @@ -61,7 +61,7 @@ impl MemoryStyle { // it static. assert!(tunables.static_memory_bound >= memory.minimum); return ( - MemoryStyle::Static { + Self::Static { bound: tunables.static_memory_bound, }, tunables.static_memory_offset_guard_size, @@ -70,10 +70,7 @@ impl MemoryStyle { } // Otherwise, make it dynamic. - ( - MemoryStyle::Dynamic, - tunables.dynamic_memory_offset_guard_size, - ) + (Self::Dynamic, tunables.dynamic_memory_offset_guard_size) } } @@ -111,7 +108,7 @@ pub enum TableStyle { impl TableStyle { /// Decide on an implementation style for the given `Table`. pub fn for_table(_table: Table, _tunables: &Tunables) -> Self { - TableStyle::CallerChecksSignature + Self::CallerChecksSignature } } diff --git a/wasmtime-environ/src/vmoffsets.rs b/wasmtime-environ/src/vmoffsets.rs index 070a739660..b747214840 100644 --- a/wasmtime-environ/src/vmoffsets.rs +++ b/wasmtime-environ/src/vmoffsets.rs @@ -557,11 +557,11 @@ pub struct TargetSharedSignatureIndex(u32); impl TargetSharedSignatureIndex { /// Constructs `TargetSharedSignatureIndex`. pub fn new(value: u32) -> Self { - TargetSharedSignatureIndex(value) + Self(value) } /// Returns index value. - pub fn index(&self) -> u32 { + pub fn index(self) -> u32 { self.0 } } diff --git a/wasmtime-jit/src/action.rs b/wasmtime-jit/src/action.rs index 44306b9e84..6b7da3ba8c 100644 --- a/wasmtime-jit/src/action.rs +++ b/wasmtime-jit/src/action.rs @@ -28,18 +28,18 @@ impl RuntimeValue { /// Return the type of this `RuntimeValue`. pub fn value_type(self) -> ir::Type { match self { - RuntimeValue::I32(_) => ir::types::I32, - RuntimeValue::I64(_) => ir::types::I64, - RuntimeValue::F32(_) => ir::types::F32, - RuntimeValue::F64(_) => ir::types::F64, - RuntimeValue::V128(_) => ir::types::I8X16, + Self::I32(_) => ir::types::I32, + Self::I64(_) => ir::types::I64, + Self::F32(_) => ir::types::F32, + Self::F64(_) => ir::types::F64, + Self::V128(_) => ir::types::I8X16, } } /// Assuming this `RuntimeValue` holds an `i32`, return that value. pub fn unwrap_i32(self) -> i32 { match self { - RuntimeValue::I32(x) => x, + Self::I32(x) => x, _ => panic!("unwrapping value of type {} as i32", self.value_type()), } } @@ -47,7 +47,7 @@ impl RuntimeValue { /// Assuming this `RuntimeValue` holds an `i64`, return that value. pub fn unwrap_i64(self) -> i64 { match self { - RuntimeValue::I64(x) => x, + Self::I64(x) => x, _ => panic!("unwrapping value of type {} as i64", self.value_type()), } } @@ -60,7 +60,7 @@ impl RuntimeValue { /// Assuming this `RuntimeValue` holds an `f32`, return the bits of that value as a `u32`. pub fn unwrap_f32_bits(self) -> u32 { match self { - RuntimeValue::F32(x) => x, + Self::F32(x) => x, _ => panic!("unwrapping value of type {} as f32", self.value_type()), } } @@ -73,7 +73,7 @@ impl RuntimeValue { /// Assuming this `RuntimeValue` holds an `f64`, return the bits of that value as a `u64`. pub fn unwrap_f64_bits(self) -> u64 { match self { - RuntimeValue::F64(x) => x, + Self::F64(x) => x, _ => panic!("unwrapping value of type {} as f64", self.value_type()), } } @@ -82,11 +82,11 @@ impl RuntimeValue { impl fmt::Display for RuntimeValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - RuntimeValue::I32(x) => write!(f, "{}: i32", x), - RuntimeValue::I64(x) => write!(f, "{}: i64", x), - RuntimeValue::F32(x) => write!(f, "{}: f32", x), - RuntimeValue::F64(x) => write!(f, "{}: f64", x), - RuntimeValue::V128(x) => write!(f, "{:?}: v128", x.to_vec()), + Self::I32(x) => write!(f, "{}: i32", x), + Self::I64(x) => write!(f, "{}: i64", x), + Self::F32(x) => write!(f, "{}: f32", x), + Self::F64(x) => write!(f, "{}: f64", x), + Self::V128(x) => write!(f, "{:?}: v128", x.to_vec()), } } } diff --git a/wasmtime-obj/src/context.rs b/wasmtime-obj/src/context.rs index f16ff1b2a7..084f52ce8c 100644 --- a/wasmtime-obj/src/context.rs +++ b/wasmtime-obj/src/context.rs @@ -1,3 +1,5 @@ +#![allow(clippy::cast_ptr_alignment)] + use alloc::boxed::Box; use alloc::vec::Vec; use core::ptr; @@ -19,8 +21,7 @@ pub fn layout_vmcontext( ) -> (Box<[u8]>, Box<[TableRelocation]>) { let ofs = VMOffsets::new(target_config.pointer_bytes(), &module); let out_len = ofs.size_of_vmctx() as usize; - let mut out = Vec::with_capacity(out_len); - out.resize(out_len, 0); + let mut out = vec![0; out_len]; // Assign unique indicies to unique signatures. let mut signature_registry = HashMap::new(); diff --git a/wasmtime-runtime/src/export.rs b/wasmtime-runtime/src/export.rs index db7fb6d482..f71bfebacc 100644 --- a/wasmtime-runtime/src/export.rs +++ b/wasmtime-runtime/src/export.rs @@ -56,7 +56,7 @@ impl Export { vmctx: *mut VMContext, signature: ir::Signature, ) -> Self { - Export::Function { + Self::Function { address, vmctx, signature, @@ -69,7 +69,7 @@ impl Export { vmctx: *mut VMContext, table: TablePlan, ) -> Self { - Export::Table { + Self::Table { definition, vmctx, table, @@ -82,7 +82,7 @@ impl Export { vmctx: *mut VMContext, memory: MemoryPlan, ) -> Self { - Export::Memory { + Self::Memory { definition, vmctx, memory, @@ -95,7 +95,7 @@ impl Export { vmctx: *mut VMContext, global: Global, ) -> Self { - Export::Global { + Self::Global { definition, vmctx, global, diff --git a/wasmtime-runtime/src/instance.rs b/wasmtime-runtime/src/instance.rs index 40c8e33d22..99af6441a0 100644 --- a/wasmtime-runtime/src/instance.rs +++ b/wasmtime-runtime/src/instance.rs @@ -475,8 +475,8 @@ impl Instance { } else if let Some(start_export) = self.module.exports.get("_start") { // As a compatibility measure, if the module doesn't have a start // function but does have a _start function exported, call that. - match start_export { - &wasmtime_environ::Export::Function(func_index) => { + match *start_export { + wasmtime_environ::Export::Function(func_index) => { let sig = &self.module.signatures[self.module.functions[func_index]]; // No wasm params or returns; just the vmctx param. if sig.params.len() == 1 && sig.returns.is_empty() { @@ -491,8 +491,8 @@ impl Instance { // As a further compatibility measure, if the module doesn't have a // start function or a _start function exported, but does have a main // function exported, call that. - match main_export { - &wasmtime_environ::Export::Function(func_index) => { + match *main_export { + wasmtime_environ::Export::Function(func_index) => { let sig = &self.module.signatures[self.module.functions[func_index]]; // No wasm params or returns; just the vmctx param. if sig.params.len() == 1 && sig.returns.is_empty() { diff --git a/wasmtime-runtime/src/jit_int.rs b/wasmtime-runtime/src/jit_int.rs index c83709b341..eed8cfda66 100644 --- a/wasmtime-runtime/src/jit_int.rs +++ b/wasmtime-runtime/src/jit_int.rs @@ -53,8 +53,8 @@ pub struct GdbJitImageRegistration { impl GdbJitImageRegistration { /// Registers JIT image using __jit_debug_register_code - pub fn register(file: Vec) -> GdbJitImageRegistration { - GdbJitImageRegistration { + pub fn register(file: Vec) -> Self { + Self { entry: unsafe { register_gdb_jit_image(&file) }, file, } @@ -83,7 +83,7 @@ unsafe fn register_gdb_jit_image(file: &[u8]) -> *mut JITCodeEntry { symfile_size: file.len() as u64, })); // Add it to the linked list in the JIT descriptor. - if __jit_debug_descriptor.first_entry != ptr::null_mut() { + if !__jit_debug_descriptor.first_entry.is_null() { (*__jit_debug_descriptor.first_entry).prev_entry = entry; } __jit_debug_descriptor.first_entry = entry; @@ -100,12 +100,12 @@ unsafe fn register_gdb_jit_image(file: &[u8]) -> *mut JITCodeEntry { unsafe fn unregister_gdb_jit_image(entry: *mut JITCodeEntry) { // Remove the code entry corresponding to the code from the linked list. - if (*entry).prev_entry != ptr::null_mut() { + if !(*entry).prev_entry.is_null() { (*(*entry).prev_entry).next_entry = (*entry).next_entry; } else { __jit_debug_descriptor.first_entry = (*entry).next_entry; } - if (*entry).next_entry != ptr::null_mut() { + if !(*entry).next_entry.is_null() { (*(*entry).next_entry).prev_entry = (*entry).prev_entry; } // Point the relevant_entry field of the descriptor at the code entry. diff --git a/wasmtime-runtime/src/table.rs b/wasmtime-runtime/src/table.rs index 06c3bb0030..13b55f6c7d 100644 --- a/wasmtime-runtime/src/table.rs +++ b/wasmtime-runtime/src/table.rs @@ -24,13 +24,12 @@ impl Table { unimplemented!("tables of types other than anyfunc ({})", ty) } }; - assert!( - plan.table.minimum <= core::u32::MAX, - "Invariant check: vec.len() <= u32::MAX" - ); match plan.style { TableStyle::CallerChecksSignature => Self { - vec: vec![VMCallerCheckedAnyfunc::default(); plan.table.minimum as usize], + vec: vec![ + VMCallerCheckedAnyfunc::default(); + usize::try_from(plan.table.minimum).unwrap() + ], maximum: plan.table.maximum, }, } @@ -59,10 +58,6 @@ impl Table { return None; } }; - assert!( - new_len <= core::u32::MAX, - "Invariant check: vec.len() <= u32::MAX" - ); self.vec.resize( usize::try_from(new_len).unwrap(), VMCallerCheckedAnyfunc::default(), diff --git a/wasmtime-runtime/src/vmcontext.rs b/wasmtime-runtime/src/vmcontext.rs index df1842f0c8..5bd51d902a 100644 --- a/wasmtime-runtime/src/vmcontext.rs +++ b/wasmtime-runtime/src/vmcontext.rs @@ -450,13 +450,13 @@ mod test_vmshared_signature_index { impl VMSharedSignatureIndex { /// Create a new `VMSharedSignatureIndex`. pub fn new(value: u32) -> Self { - VMSharedSignatureIndex(value) + Self(value) } } impl Default for VMSharedSignatureIndex { fn default() -> Self { - VMSharedSignatureIndex::new(u32::MAX) + Self::new(u32::MAX) } } @@ -573,7 +573,7 @@ mod test_vm_invoke_argument { impl VMInvokeArgument { /// Create a new invocation argument filled with zeroes pub fn new() -> Self { - VMInvokeArgument([0; 16]) + Self([0; 16]) } }