Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use named fields for {Elem,Data}Drop instructions #1182

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/wasmi/src/engine/bytecode/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ impl Instruction {
}
}

/// Creates a new [`Instruction::DataDrop`] from the given `data`.
pub fn data_drop(data: impl Into<Data>) -> Self {
Self::DataDrop { data: data.into() }
}

/// Creates a new [`Instruction::ElemDrop`] from the given `elem`.
pub fn elem_drop(elem: impl Into<Elem>) -> Self {
Self::ElemDrop { elem: elem.into() }
}

/// Creates a new [`Instruction::DataIndex`] from the given `index`.
pub fn data_index(index: impl Into<Data>) -> Self {
Self::DataIndex {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/bytecode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5049,9 +5049,9 @@ pub enum Instruction {
},

/// A Wasm `elem.drop` equalivalent Wasmi instruction.
ElemDrop(Elem),
ElemDrop { elem: Elem },
/// A Wasm `data.drop` equalivalent Wasmi instruction.
DataDrop(Data),
DataDrop { data: Data },

/// Wasm `memory.size` instruction.
MemorySize {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/bytecode/visit_regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@
| Instr::TableGrowImm { result, value, .. } => {
host_visitor!(visitor => Res(result), value)
}
| Instr::ElemDrop(_) | Instr::DataDrop(_) => {}
| Instr::ElemDrop { .. } | Instr::DataDrop { .. } => {}

Check warning on line 589 in crates/wasmi/src/engine/bytecode/visit_regs.rs

View check run for this annotation

Codecov / codecov/patch

crates/wasmi/src/engine/bytecode/visit_regs.rs#L589

Added line #L589 was not covered by tests
| Instr::MemorySize { result } => host_visitor!(visitor => Res(result)),
| Instr::MemoryGrow { result, delta } => host_visitor!(visitor => Res(result), delta),
| Instr::MemoryGrowBy { result, .. } => host_visitor!(visitor => Res(result)),
Expand Down
6 changes: 2 additions & 4 deletions crates/wasmi/src/engine/executor/instrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,10 +1224,8 @@ impl<'engine> Executor<'engine> {
delta,
value,
} => self.execute_table_grow_imm(store, result, delta, value)?,
Instr::ElemDrop(element_index) => {
self.execute_element_drop(&mut store.inner, element_index)
}
Instr::DataDrop(data_index) => self.execute_data_drop(&mut store.inner, data_index),
Instr::ElemDrop { elem } => self.execute_element_drop(&mut store.inner, elem),
Instr::DataDrop { data } => self.execute_data_drop(&mut store.inner, data),
Instr::MemorySize { result } => self.execute_memory_size(&store.inner, result),
Instr::MemoryGrow { result, delta } => {
self.execute_memory_grow(store, result, delta)?
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/translator/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3077,7 +3077,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator {

fn visit_data_drop(&mut self, data_index: u32) -> Self::Output {
bail_unreachable!(self);
self.push_fueled_instr(Instruction::DataDrop(data_index.into()), FuelCosts::entity)?;
self.push_fueled_instr(Instruction::data_drop(data_index), FuelCosts::entity)?;
Ok(())
}

Expand Down Expand Up @@ -3197,7 +3197,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator {

fn visit_elem_drop(&mut self, elem_index: u32) -> Self::Output {
bail_unreachable!(self);
self.push_fueled_instr(Instruction::ElemDrop(elem_index.into()), FuelCosts::entity)?;
self.push_fueled_instr(Instruction::elem_drop(elem_index), FuelCosts::entity)?;
Ok(())
}

Expand Down
Loading