Skip to content

Commit

Permalink
make special smoldot tail resume tests pass under regmach
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Nov 30, 2023
1 parent 9e6e025 commit 0a4c5da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 5 additions & 3 deletions crates/wasmi/src/engine/regmach/executor/instrs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use self::{call::CallOutcome, return_::ReturnOutcome};
use self::{call::{CallOutcome}, return_::ReturnOutcome};
use crate::{
core::{TrapCode, UntypedValue},
engine::{
Expand Down Expand Up @@ -27,6 +27,7 @@ use crate::{
FuncRef,
StoreInner,
};
pub use self::call::CallKind;

mod binary;
mod branch;
Expand All @@ -45,8 +46,8 @@ mod unary;

macro_rules! forward_call {
($expr:expr) => {{
if let CallOutcome::Call { results, host_func } = $expr? {
return Ok(WasmOutcome::Call { results, host_func });
if let CallOutcome::Call { results, host_func, call_kind } = $expr? {
return Ok(WasmOutcome::Call { results, host_func, call_kind });
}
}};
}
Expand All @@ -73,6 +74,7 @@ pub enum WasmOutcome {
Call {
results: RegisterSpan,
host_func: Func,
call_kind: CallKind,
},
}

Expand Down
11 changes: 9 additions & 2 deletions crates/wasmi/src/engine/regmach/executor/instrs/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub enum CallOutcome {
Call {
results: RegisterSpan,
host_func: Func,
call_kind: CallKind,
},
}

Expand Down Expand Up @@ -341,13 +342,19 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> {
let offset = self.value_stack.extend_zeros(max_inout);
let offset_sp = unsafe { self.value_stack.stack_ptr_at(offset) };
if matches!(params, CallParams::Some) {
self.ip = self.copy_call_params(offset_sp);
let new_ip = self.copy_call_params(offset_sp);
if matches!(call_kind, CallKind::Nested) {
self.ip = new_ip;
}
}
if matches!(call_kind, CallKind::Nested) {
self.update_instr_ptr_at(1);
}
self.update_instr_ptr_at(1);
self.cache.reset();
Ok(CallOutcome::Call {
results,
host_func: *func,
call_kind,
})
}
}
Expand Down
9 changes: 7 additions & 2 deletions crates/wasmi/src/engine/regmach/executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use self::instrs::{execute_instrs, WasmOutcome};
use self::instrs::{execute_instrs, WasmOutcome, CallKind};
pub use super::Stack;
use super::{stack::CallFrame, TaggedTrap};
use crate::{
Expand Down Expand Up @@ -175,14 +175,15 @@ impl<'engine> EngineExecutor<'engine> {
WasmOutcome::Call {
results,
ref host_func,
call_kind,
} => {
let instance = *self
.stack
.calls
.peek()
.expect("caller must be on the stack")
.instance();
self.execute_host_func(&mut ctx, results, host_func, &instance)?;
self.execute_host_func(&mut ctx, results, host_func, &instance, call_kind)?;
}
}
}
Expand All @@ -194,6 +195,7 @@ impl<'engine> EngineExecutor<'engine> {
results: RegisterSpan,
func: &Func,
instance: &Instance,
call_kind: CallKind,
) -> Result<(), TaggedTrap> {
let func_entity = match ctx.as_context().store.inner.resolve_func(func) {
FuncEntity::Wasm(wasm_func) => {
Expand All @@ -206,6 +208,9 @@ impl<'engine> EngineExecutor<'engine> {
func_entity,
HostFuncCaller::wasm(results, instance),
);
if matches!(call_kind, CallKind::Tail) {
self.stack.calls.pop();
}
if self.stack.calls.peek().is_some() {
// Case: There is a frame on the call stack.
//
Expand Down

0 comments on commit 0a4c5da

Please sign in to comment.