Skip to content

Commit

Permalink
Fix clippy warning and refactor BlockType (#966)
Browse files Browse the repository at this point in the history
* remove ValueType from BlockType::Returns variant

not used

* return usize from BlockType::len_{params,results}
  • Loading branch information
Robbepop authored Mar 24, 2024
1 parent 1992c7e commit 3afac58
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions crates/wasmi/src/engine/block_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum BlockTypeInner {
/// A block type with no parameters and no results.
Empty,
/// A block type with no parameters and exactly one result.
Returns(ValueType),
Returns,
/// A general block type with parameters and results.
FuncType(DedupFuncType),
}
Expand Down Expand Up @@ -53,8 +53,8 @@ impl BlockType {
}

/// Creates a [`BlockType`] with no parameters and a single result type.
fn returns(return_type: ValueType) -> Self {
Self::from_inner(BlockTypeInner::Returns(return_type))
fn returns(_return_type: ValueType) -> Self {
Self::from_inner(BlockTypeInner::Returns)
}

/// Creates a [`BlockType`] with parameters and results.
Expand All @@ -63,22 +63,22 @@ impl BlockType {
}

/// Returns the number of parameters of the [`BlockType`].
pub fn len_params(&self, engine: &Engine) -> u32 {
pub fn len_params(&self, engine: &Engine) -> usize {
match &self.inner {
BlockTypeInner::Empty | BlockTypeInner::Returns(_) => 0,
BlockTypeInner::Empty | BlockTypeInner::Returns => 0,
BlockTypeInner::FuncType(func_type) => {
engine.resolve_func_type(func_type, |func_type| func_type.params().len() as u32)
engine.resolve_func_type(func_type, |func_type| func_type.params().len())
}
}
}

/// Returns the number of results of the [`BlockType`].
pub fn len_results(&self, engine: &Engine) -> u32 {
pub fn len_results(&self, engine: &Engine) -> usize {
match &self.inner {
BlockTypeInner::Empty => 0,
BlockTypeInner::Returns(_) => 1,
BlockTypeInner::Returns => 1,
BlockTypeInner::FuncType(func_type) => {
engine.resolve_func_type(func_type, |func_type| func_type.results().len() as u32)
engine.resolve_func_type(func_type, |func_type| func_type.results().len())
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmi/src/engine/translator/control_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl BlockControlFrame {
/// Returns an iterator over the registers holding the branching parameters of the [`BlockControlFrame`].
pub fn branch_params(&self, engine: &Engine) -> RegisterSpanIter {
self.branch_params
.iter(self.block_type().len_results(engine) as usize)
.iter(self.block_type().len_results(engine))
}

/// Returns the label for the branch destination of the [`BlockControlFrame`].
Expand Down Expand Up @@ -213,7 +213,7 @@ impl LoopControlFrame {
/// Returns an iterator over the registers holding the branching parameters of the [`LoopControlFrame`].
pub fn branch_params(&self, engine: &Engine) -> RegisterSpanIter {
self.branch_params
.iter(self.block_type().len_params(engine) as usize)
.iter(self.block_type().len_params(engine))
}

/// Returns the label for the branch destination of the [`LoopControlFrame`].
Expand Down Expand Up @@ -383,7 +383,7 @@ impl IfControlFrame {
/// Returns an iterator over the registers holding the branching parameters of the [`IfControlFrame`].
pub fn branch_params(&self, engine: &Engine) -> RegisterSpanIter {
self.branch_params
.iter(self.block_type().len_results(engine) as usize)
.iter(self.block_type().len_results(engine))
}

/// Returns the label for the branch destination of the [`IfControlFrame`].
Expand Down
10 changes: 5 additions & 5 deletions crates/wasmi/src/engine/translator/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ impl<'a> VisitOperator<'a> for FuncTranslator {
let fuel_instr = self.fuel_instr();
let stack_height = BlockHeight::new(self.engine(), self.alloc.stack.height(), block_type)?;
let end_label = self.alloc.instr_encoder.new_label();
let len_block_params = block_type.len_params(self.engine()) as usize;
let len_branch_params = block_type.len_results(self.engine()) as usize;
let len_block_params = block_type.len_params(self.engine());
let len_branch_params = block_type.len_results(self.engine());
let branch_params = self.alloc_branch_params(len_block_params, len_branch_params)?;
self.alloc.control_stack.push_frame(BlockControlFrame::new(
block_type,
Expand All @@ -157,7 +157,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator {
return Ok(());
}
// Copy `loop` parameters over to where it expects its branch parameters.
let len_block_params = block_type.len_params(self.engine()) as usize;
let len_block_params = block_type.len_params(self.engine());
self.alloc
.stack
.pop_n(len_block_params, &mut self.alloc.buffer.providers);
Expand Down Expand Up @@ -210,8 +210,8 @@ impl<'a> VisitOperator<'a> for FuncTranslator {
let stack_height = BlockHeight::new(self.engine(), self.alloc.stack.height(), block_type)?;
self.preserve_locals()?;
let end_label = self.alloc.instr_encoder.new_label();
let len_block_params = block_type.len_params(self.engine()) as usize;
let len_branch_params = block_type.len_results(self.engine()) as usize;
let len_block_params = block_type.len_params(self.engine());
let len_branch_params = block_type.len_results(self.engine());
let branch_params = self.alloc_branch_params(len_block_params, len_branch_params)?;
let (reachability, fuel_instr) = match condition {
TypedProvider::Const(condition) => {
Expand Down

0 comments on commit 3afac58

Please sign in to comment.