Fix clippy warnings.
This commit fixes the current set of (stable) clippy warnings in the repo.
This commit is contained in:
committed by
Andrew Brown
parent
1176e4f178
commit
9f506692c2
@@ -41,7 +41,10 @@ use cranelift_frontend::{FunctionBuilder, Variable};
|
||||
use wasmparser::{MemoryImmediate, Operator};
|
||||
|
||||
// Clippy warns about "flags: _" but its important to document that the flags field is ignored
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(clippy::unneeded_field_pattern))]
|
||||
#[cfg_attr(
|
||||
feature = "cargo-clippy",
|
||||
allow(clippy::unneeded_field_pattern, clippy::cognitive_complexity)
|
||||
)]
|
||||
/// Translates wasm operators into Cranelift IR instructions. Returns `true` if it inserted
|
||||
/// a return.
|
||||
pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
|
||||
@@ -87,7 +87,7 @@ impl From<BinaryReaderError> for WasmError {
|
||||
/// Convert from a `BinaryReaderError` to a `WasmError`.
|
||||
fn from(e: BinaryReaderError) -> Self {
|
||||
let BinaryReaderError { message, offset } = e;
|
||||
WasmError::InvalidWebAssembly { message, offset }
|
||||
Self::InvalidWebAssembly { message, offset }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,8 +478,7 @@ pub trait ModuleEnvironment<'data> {
|
||||
}
|
||||
|
||||
/// Indicates that a custom section has been found in the wasm file
|
||||
fn custom_section(&mut self, name: &'data str, data: &'data [u8]) -> WasmResult<()> {
|
||||
drop((name, data));
|
||||
fn custom_section(&mut self, _name: &'data str, _data: &'data [u8]) -> WasmResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,8 +409,8 @@ pub fn parse_name_section<'data>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_function_name_subsection<'data>(
|
||||
mut naming_reader: NamingReader<'data>,
|
||||
fn parse_function_name_subsection(
|
||||
mut naming_reader: NamingReader<'_>,
|
||||
) -> Option<HashMap<FuncIndex, &str>> {
|
||||
let mut function_names = HashMap::new();
|
||||
for _ in 0..naming_reader.get_count() {
|
||||
@@ -425,5 +425,5 @@ fn parse_function_name_subsection<'data>(
|
||||
return None;
|
||||
}
|
||||
}
|
||||
return Some(function_names);
|
||||
Some(function_names)
|
||||
}
|
||||
|
||||
@@ -91,55 +91,54 @@ pub enum ControlStackFrame {
|
||||
impl ControlStackFrame {
|
||||
pub fn num_return_values(&self) -> usize {
|
||||
match *self {
|
||||
ControlStackFrame::If {
|
||||
Self::If {
|
||||
num_return_values, ..
|
||||
}
|
||||
| ControlStackFrame::Block {
|
||||
| Self::Block {
|
||||
num_return_values, ..
|
||||
}
|
||||
| ControlStackFrame::Loop {
|
||||
| Self::Loop {
|
||||
num_return_values, ..
|
||||
} => num_return_values,
|
||||
}
|
||||
}
|
||||
pub fn num_param_values(&self) -> usize {
|
||||
match *self {
|
||||
ControlStackFrame::If {
|
||||
Self::If {
|
||||
num_param_values, ..
|
||||
}
|
||||
| ControlStackFrame::Block {
|
||||
| Self::Block {
|
||||
num_param_values, ..
|
||||
}
|
||||
| ControlStackFrame::Loop {
|
||||
| Self::Loop {
|
||||
num_param_values, ..
|
||||
} => num_param_values,
|
||||
}
|
||||
}
|
||||
pub fn following_code(&self) -> Ebb {
|
||||
match *self {
|
||||
ControlStackFrame::If { destination, .. }
|
||||
| ControlStackFrame::Block { destination, .. }
|
||||
| ControlStackFrame::Loop { destination, .. } => destination,
|
||||
Self::If { destination, .. }
|
||||
| Self::Block { destination, .. }
|
||||
| Self::Loop { destination, .. } => destination,
|
||||
}
|
||||
}
|
||||
pub fn br_destination(&self) -> Ebb {
|
||||
match *self {
|
||||
ControlStackFrame::If { destination, .. }
|
||||
| ControlStackFrame::Block { destination, .. } => destination,
|
||||
ControlStackFrame::Loop { header, .. } => header,
|
||||
Self::If { destination, .. } | Self::Block { destination, .. } => destination,
|
||||
Self::Loop { header, .. } => header,
|
||||
}
|
||||
}
|
||||
pub fn original_stack_size(&self) -> usize {
|
||||
match *self {
|
||||
ControlStackFrame::If {
|
||||
Self::If {
|
||||
original_stack_size,
|
||||
..
|
||||
}
|
||||
| ControlStackFrame::Block {
|
||||
| Self::Block {
|
||||
original_stack_size,
|
||||
..
|
||||
}
|
||||
| ControlStackFrame::Loop {
|
||||
| Self::Loop {
|
||||
original_stack_size,
|
||||
..
|
||||
} => original_stack_size,
|
||||
@@ -147,36 +146,36 @@ impl ControlStackFrame {
|
||||
}
|
||||
pub fn is_loop(&self) -> bool {
|
||||
match *self {
|
||||
ControlStackFrame::If { .. } | ControlStackFrame::Block { .. } => false,
|
||||
ControlStackFrame::Loop { .. } => true,
|
||||
Self::If { .. } | Self::Block { .. } => false,
|
||||
Self::Loop { .. } => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exit_is_branched_to(&self) -> bool {
|
||||
match *self {
|
||||
ControlStackFrame::If {
|
||||
Self::If {
|
||||
exit_is_branched_to,
|
||||
..
|
||||
}
|
||||
| ControlStackFrame::Block {
|
||||
| Self::Block {
|
||||
exit_is_branched_to,
|
||||
..
|
||||
} => exit_is_branched_to,
|
||||
ControlStackFrame::Loop { .. } => false,
|
||||
Self::Loop { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_branched_to_exit(&mut self) {
|
||||
match *self {
|
||||
ControlStackFrame::If {
|
||||
Self::If {
|
||||
ref mut exit_is_branched_to,
|
||||
..
|
||||
}
|
||||
| ControlStackFrame::Block {
|
||||
| Self::Block {
|
||||
ref mut exit_is_branched_to,
|
||||
..
|
||||
} => *exit_is_branched_to = true,
|
||||
ControlStackFrame::Loop { .. } => {}
|
||||
Self::Loop { .. } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ use crate::translation_utils::SignatureIndex;
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use std::boxed::Box;
|
||||
|
||||
/// Map of signatures to a function's parameter and return types.
|
||||
pub(crate) type WasmTypes =
|
||||
PrimaryMap<SignatureIndex, (Box<[wasmparser::Type]>, Box<[wasmparser::Type]>)>;
|
||||
|
||||
/// Contains information decoded from the Wasm module that must be referenced
|
||||
/// during each Wasm function's translation.
|
||||
///
|
||||
@@ -14,14 +18,13 @@ pub struct ModuleTranslationState {
|
||||
///
|
||||
/// This is used for translating multi-value Wasm blocks inside functions,
|
||||
/// which are encoded to refer to their type signature via index.
|
||||
pub(crate) wasm_types:
|
||||
PrimaryMap<SignatureIndex, (Box<[wasmparser::Type]>, Box<[wasmparser::Type]>)>,
|
||||
pub(crate) wasm_types: WasmTypes,
|
||||
}
|
||||
|
||||
impl ModuleTranslationState {
|
||||
/// Creates a new empty ModuleTranslationState.
|
||||
pub fn new() -> Self {
|
||||
ModuleTranslationState {
|
||||
Self {
|
||||
wasm_types: PrimaryMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user