Skip to content

Add PrunedStore and use it in Wasmi's executor #1449

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

Merged
merged 49 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
96ee4e7
add TypedStore internal parts of Store
Robbepop Mar 30, 2025
80c1487
put TypedStore's data into a Box
Robbepop Mar 30, 2025
7f83380
rename TypedStore to TypedStoreInner
Robbepop Mar 30, 2025
a4e214d
add test asserting equal sizes for all TypedStoreInner<T>
Robbepop Mar 30, 2025
cb55ee6
move data field to last position
Robbepop Mar 30, 2025
e5e77b9
add PrunedStore definitions and tests
Robbepop Mar 30, 2025
161fac1
change expect -> allow
Robbepop Mar 30, 2025
d55b17f
rename store field to pruned
Robbepop Mar 30, 2025
c374e2d
move id field from PrunedStore to Store<T>
Robbepop Mar 30, 2025
5cf8ece
make Wasmi executor use Store::call_host_func
Robbepop Mar 30, 2025
3fb3843
rename FuncParams to FuncInOut
Robbepop Mar 30, 2025
d0a37b0
move func_inout.rs into wasmi::func submodule
Robbepop Mar 30, 2025
a4cd674
fix intra doc links
Robbepop Mar 30, 2025
3c14228
add call_host_func trampoline to Store<T>
Robbepop Mar 30, 2025
f0ed76e
improve Debug impl for ResourceLimiterQuery
Robbepop Mar 30, 2025
f284636
apply rustfmt
Robbepop Mar 30, 2025
04d068d
properly silence warning
Robbepop Mar 30, 2025
72a9bed
use proper signatures in PrunedStore::inner[_mut] methods
Robbepop Mar 30, 2025
7d2f42b
make PrunedStore::restore a static method
Robbepop Mar 30, 2025
096e391
add PrunedStore::call_host_func method
Robbepop Mar 30, 2025
c5b2a0b
make PrunedStore a transparent type
Robbepop Mar 30, 2025
6094ea7
generalize PrunedStore restoration
Robbepop Mar 30, 2025
7c177a3
refactor and clean-up new design
Robbepop Mar 30, 2025
cc92fc2
make use of PrunedStore in call
Robbepop Mar 30, 2025
d5e73be
add TypedStore::store_inner_and_resource_limiter_ref
Robbepop Mar 30, 2025
0e2aa82
port Wasmi's executor to PrunedStore
Robbepop Mar 30, 2025
1affe19
apply clippy suggestions
Robbepop Mar 30, 2025
151f106
clean-up PruneStore::inner[_mut] methods
Robbepop Mar 30, 2025
8956859
make PrunedStore::restore method private
Robbepop Mar 30, 2025
8653597
put #[inline] on PrunedStore::restore method
Robbepop Mar 30, 2025
cd69b90
add unlikely to PrunedStore::restore check
Robbepop Mar 30, 2025
a9edf3c
unsilence warnings
Robbepop Mar 30, 2025
3599657
put some inlines where it makes sense
Robbepop Mar 30, 2025
7900728
make Store::prune method crate private
Robbepop Mar 30, 2025
0189ade
Merge branch 'main' into rf-add-pruned-store
Robbepop Mar 31, 2025
437c47d
Merge branch 'main' into rf-add-pruned-store
Robbepop Mar 31, 2025
7b72444
Merge branch 'main' into rf-add-pruned-store
Robbepop Mar 31, 2025
333eb16
revert some unnecessary changes compared to `main`
Robbepop Mar 31, 2025
62a5996
Merge branch 'main' into rf-add-pruned-store
Robbepop Mar 31, 2025
dabe8a0
Merge branch 'main' into rf-add-pruned-store
Robbepop Mar 31, 2025
e8c9f1a
use imported type_name
Robbepop Mar 31, 2025
a0579c0
fix docs
Robbepop Apr 1, 2025
7be71f3
deduplicate code in PrunedStore
Robbepop Apr 1, 2025
9fd2f14
add missing docs to PrunedStore API
Robbepop Apr 1, 2025
21a0fb1
apply rustfmt
Robbepop Apr 1, 2025
a1f241e
apply inline(always) to execute_branch_binop op-handlers
Robbepop Apr 2, 2025
2462f0e
fix most of the call instruction regressions
Robbepop Apr 2, 2025
82206c1
remove commented out inline annotations
Robbepop Apr 3, 2025
601776d
put inline on merge_call_frame
Robbepop Apr 3, 2025
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
35 changes: 16 additions & 19 deletions crates/wasmi/src/engine/executor/instrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
},
ir::{index, BlockFuel, Const16, Instruction, Offset64Hi, Reg, ShiftAmount},
memory::DataSegment,
store::StoreInner,
store::{PrunedStore, StoreInner},
table::ElementSegment,
Error,
Func,
FuncRef,
Global,
Memory,
Store,
Table,
};

Expand Down Expand Up @@ -64,8 +63,8 @@
///
/// If the execution encounters a trap.
#[inline(never)]
pub fn execute_instrs<'engine, T>(
store: &mut Store<T>,
pub fn execute_instrs<'engine>(
store: &mut PrunedStore,
stack: &'engine mut Stack,
code_map: &'engine CodeMap,
) -> Result<(), Error> {
Expand Down Expand Up @@ -119,7 +118,7 @@

/// Executes the function frame until it returns or traps.
#[inline(always)]
fn execute<T>(mut self, store: &mut Store<T>) -> Result<(), Error> {
fn execute(mut self, store: &mut PrunedStore) -> Result<(), Error> {

Check warning on line 121 in crates/wasmi/src/engine/executor/instrs.rs

View check run for this annotation

Codecov / codecov/patch

crates/wasmi/src/engine/executor/instrs.rs#L121

Added line #L121 was not covered by tests
use Instruction as Instr;
loop {
match *self.ip.get() {
Expand Down Expand Up @@ -410,24 +409,22 @@
self.execute_return_call_internal(store.inner_mut(), EngineFunc::from(func))?
}
Instr::ReturnCallImported0 { func } => {
forward_return!(self.execute_return_call_imported_0::<T>(store, func)?)
forward_return!(self.execute_return_call_imported_0(store, func)?)
}
Instr::ReturnCallImported { func } => {
forward_return!(self.execute_return_call_imported::<T>(store, func)?)
forward_return!(self.execute_return_call_imported(store, func)?)
}
Instr::ReturnCallIndirect0 { func_type } => {
forward_return!(self.execute_return_call_indirect_0::<T>(store, func_type)?)
forward_return!(self.execute_return_call_indirect_0(store, func_type)?)

Check warning on line 418 in crates/wasmi/src/engine/executor/instrs.rs

View check run for this annotation

Codecov / codecov/patch

crates/wasmi/src/engine/executor/instrs.rs#L418

Added line #L418 was not covered by tests
}
Instr::ReturnCallIndirect0Imm16 { func_type } => {
forward_return!(
self.execute_return_call_indirect_0_imm16::<T>(store, func_type)?
)
forward_return!(self.execute_return_call_indirect_0_imm16(store, func_type)?)
}
Instr::ReturnCallIndirect { func_type } => {
forward_return!(self.execute_return_call_indirect::<T>(store, func_type)?)
forward_return!(self.execute_return_call_indirect(store, func_type)?)
}
Instr::ReturnCallIndirectImm16 { func_type } => {
forward_return!(self.execute_return_call_indirect_imm16::<T>(store, func_type)?)
forward_return!(self.execute_return_call_indirect_imm16(store, func_type)?)
}
Instr::CallInternal0 { results, func } => self.execute_call_internal_0(
store.inner_mut(),
Expand All @@ -438,22 +435,22 @@
self.execute_call_internal(store.inner_mut(), results, EngineFunc::from(func))?
}
Instr::CallImported0 { results, func } => {
self.execute_call_imported_0::<T>(store, results, func)?
self.execute_call_imported_0(store, results, func)?
}
Instr::CallImported { results, func } => {
self.execute_call_imported::<T>(store, results, func)?
self.execute_call_imported(store, results, func)?
}
Instr::CallIndirect0 { results, func_type } => {
self.execute_call_indirect_0::<T>(store, results, func_type)?
self.execute_call_indirect_0(store, results, func_type)?
}
Instr::CallIndirect0Imm16 { results, func_type } => {
self.execute_call_indirect_0_imm16::<T>(store, results, func_type)?
self.execute_call_indirect_0_imm16(store, results, func_type)?
}
Instr::CallIndirect { results, func_type } => {
self.execute_call_indirect::<T>(store, results, func_type)?
self.execute_call_indirect(store, results, func_type)?
}
Instr::CallIndirectImm16 { results, func_type } => {
self.execute_call_indirect_imm16::<T>(store, results, func_type)?
self.execute_call_indirect_imm16(store, results, func_type)?
}
Instr::Select { result, lhs } => self.execute_select(result, lhs),
Instr::SelectImm32Rhs { result, lhs } => self.execute_select_imm32_rhs(result, lhs),
Expand Down
2 changes: 2 additions & 0 deletions crates/wasmi/src/engine/executor/instrs/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl Executor<'_> {
}

/// Executes a generic fused compare and branch instruction with raw inputs.
#[inline(always)]
fn execute_branch_binop<T>(
&mut self,
lhs: Reg,
Expand Down Expand Up @@ -309,6 +310,7 @@ macro_rules! impl_execute_branch_binop {
impl<'engine> Executor<'engine> {
$(
#[doc = concat!("Executes an [`Instruction::", stringify!($op_name), "`].")]
#[inline(always)]
pub fn $fn_name(&mut self, lhs: Reg, rhs: Reg, offset: BranchOffset16) {
self.execute_branch_binop::<$ty>(lhs, rhs, offset, $op)
}
Expand Down
Loading
Loading