Skip to content

Commit 1f4febf

Browse files
committed
refactor Stack::push_loop
It is not possible to push the copy instructions after pinning the label hich is required for the method. Therefore this needs to happen before the call to push_loop and push_loop itself has to (debug) assert that this has been done properly.
1 parent 625df92 commit 1f4febf

File tree

1 file changed

+6
-10
lines changed
  • crates/wasmi/src/engine/translator/func2/stack

1 file changed

+6
-10
lines changed

crates/wasmi/src/engine/translator/func2/stack/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,10 @@ impl Stack {
189189

190190
/// Pushes a Wasm `loop` onto the [`Stack`].
191191
///
192-
/// # Note
193-
///
194-
/// Calls `f` for every non [`Operand::Temp`] operand on the [`Stack`]
195-
/// that is also a parameter to the pushed Wasm `loop` control frame.
196-
///
197192
/// # Panics (debug)
198193
///
199-
/// If `consume_fuel` is `None` and fuel metering is enabled.
194+
/// - If `consume_fuel` is `None` and fuel metering is enabled.
195+
/// - If any of the Wasm `loop` operand parameters are _not_ [`Operand::Temp`].
200196
///
201197
/// # Errors
202198
///
@@ -206,15 +202,15 @@ impl Stack {
206202
ty: BlockType,
207203
label: LabelRef,
208204
consume_fuel: Option<Instr>,
209-
mut f: impl FnMut(Operand) -> Result<(), Error>,
210205
) -> Result<(), Error> {
211206
debug_assert!(!self.controls.is_empty());
212207
debug_assert!(self.is_fuel_metering_enabled() == consume_fuel.is_some());
213208
let len_params = usize::from(ty.len_params(&self.engine));
214209
let block_height = self.height() - len_params;
215-
for depth in 0..block_height {
216-
f(self.operand_to_temp(depth))?;
217-
}
210+
debug_assert!(self
211+
.operands
212+
.peek(len_params)
213+
.all(|operand| operand.is_temp()));
218214
self.controls
219215
.push_loop(ty, block_height, label, consume_fuel);
220216
Ok(())

0 commit comments

Comments
 (0)