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

Add support for Wasm multi-memory proposal #1191

Merged
merged 44 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
715517c
add Memory index type
Robbepop Sep 19, 2024
e8f185b
adjust load instructions for multi-memory proposal
Robbepop Sep 19, 2024
0977f79
improve docs for 16-bit offset variants
Robbepop Sep 19, 2024
3a326b7
re-design store instruction for multi-memory proposal
Robbepop Sep 20, 2024
18bb311
minor fix in store instruction docs
Robbepop Sep 20, 2024
94ad77b
adjust executor to support re-designed load instructions
Robbepop Sep 20, 2024
e58032f
fix docs for fetch_ptr_and_offset
Robbepop Sep 20, 2024
a74e265
adjust executor to support new and re-designed store instructions
Robbepop Sep 20, 2024
329b05e
optionally encode Instruction::MemoryIndex after load_at instructions
Robbepop Sep 20, 2024
42b5623
implement translation of new load instruction
Robbepop Sep 20, 2024
491ea22
apply clippy suggestion
Robbepop Sep 20, 2024
9af585c
apply rustfmt
Robbepop Sep 20, 2024
ed6db0c
fix 32_store16_imm snake name
Robbepop Sep 20, 2024
22cd154
teach Wasmi translator to encode the new store instruction
Robbepop Sep 20, 2024
bdedac4
update encoding docs of store_at instructions
Robbepop Sep 21, 2024
2bbea4f
add multi-memory support to wasmi::Config
Robbepop Sep 21, 2024
d86cf88
support optional MemoryIndex param for store instrs in executor
Robbepop Sep 21, 2024
1171e07
add #[inline] to fetch_optional_memory
Robbepop Sep 21, 2024
744df8d
improve docs of TableFill instructions
Robbepop Sep 21, 2024
b20c22d
update docs for bulk memory instructions
Robbepop Sep 21, 2024
37f20c3
implement multi-memory support for bulk-memory instrs in translator a…
Robbepop Sep 21, 2024
7af9d91
disable multi-memory for MVP test config
Robbepop Sep 21, 2024
546d8dc
fix bug in load instruction translation
Robbepop Sep 21, 2024
3ae639d
apply rustfmt
Robbepop Sep 21, 2024
3295a95
fix memory_size translation tests
Robbepop Sep 21, 2024
ebfa681
update and fix load instruction translation tests
Robbepop Sep 21, 2024
2d02eb6
fix translation of memory.grow
Robbepop Sep 21, 2024
5455786
update and fix memory.grow translation tests
Robbepop Sep 21, 2024
1d25c05
update and fix memory.copy translation tests
Robbepop Sep 21, 2024
84cf5ef
fix and adjust memory.fill translation tests
Robbepop Sep 22, 2024
1f14e2d
fix and adjust memory.init translation tests
Robbepop Sep 22, 2024
157eadc
adjust and fix some store instruction translation tests
Robbepop Sep 22, 2024
6b00542
add store_imm16 translation test
Robbepop Sep 22, 2024
1508c00
update and fix remaining store translation tests
Robbepop Sep 22, 2024
152b83c
fix bug in executor for memory.grow
Robbepop Sep 22, 2024
1e1e46a
fix clippy warnings
Robbepop Sep 22, 2024
3c68b6a
remove commented out code
Robbepop Sep 23, 2024
7471329
remove commented out code (2)
Robbepop Sep 23, 2024
99c49fd
remove outdated debug assertion
Robbepop Sep 23, 2024
4b0f4fe
include multi-memory spec tests
Robbepop Sep 23, 2024
1f0434a
update Wasm spec testsuite by 1 rev
Robbepop Sep 23, 2024
901de10
fix bug in memory.copy execution
Robbepop Sep 23, 2024
3540174
Merge branch 'main' into rf-impl-multi-memory-proposal
Robbepop Sep 24, 2024
48292e0
improve naming of locals
Robbepop Sep 24, 2024
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
848 changes: 696 additions & 152 deletions crates/ir/src/for_each_op.rs

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions crates/ir/src/immeditate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@
}
}

impl From<i8> for AnyConst16 {
fn from(value: i8) -> Self {
Self(value as u8 as u16 as i16)
}
}

impl From<i16> for AnyConst16 {
fn from(value: i16) -> Self {
Self(value)
Expand All @@ -460,6 +466,18 @@
}
}

impl From<AnyConst16> for i8 {
fn from(value: AnyConst16) -> Self {
value.0 as i8

Check warning on line 471 in crates/ir/src/immeditate.rs

View check run for this annotation

Codecov / codecov/patch

crates/ir/src/immeditate.rs#L471

Added line #L471 was not covered by tests
}
}

impl From<AnyConst16> for i16 {
fn from(value: AnyConst16) -> Self {
value.0

Check warning on line 477 in crates/ir/src/immeditate.rs

View check run for this annotation

Codecov / codecov/patch

crates/ir/src/immeditate.rs#L476-L477

Added lines #L476 - L477 were not covered by tests
}
}

impl From<AnyConst16> for i32 {
fn from(value: AnyConst16) -> Self {
Self::from(value.0)
Expand Down
9 changes: 9 additions & 0 deletions crates/ir/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ macro_rules! for_each_index {
InternalFunc(pub(crate) u32);
/// A Wasm global variable index.
Global(pub(crate) u32);
/// A Wasm linear memory index.
Memory(pub(crate) u32);
/// A Wasm table index.
Table(pub(crate) u32);
/// A Wasm data segment index.
Expand All @@ -30,6 +32,13 @@ macro_rules! for_each_index {
};
}

impl Memory {
/// Returns `true` if `self` refers to the default linear memory which always is at index 0.
pub fn is_default(&self) -> bool {
self.0 == 0
}
}

macro_rules! define_index {
(
$(
Expand Down
3 changes: 1 addition & 2 deletions crates/ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ mod tests;

use wasmi_core as core;

use self::immeditate::AnyConst16;
#[doc(inline)]
pub use self::{
error::Error,
immeditate::{AnyConst32, Const16, Const32},
immeditate::{AnyConst16, AnyConst32, Const16, Const32},
index::Instr,
index::Reg,
primitive::{BlockFuel, BranchOffset, BranchOffset16, Comparator, ComparatorAndOffset, Sign},
Expand Down
1 change: 1 addition & 0 deletions crates/ir/src/visit_regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl_host_visitor_for!(
Func,
FuncType,
Global,
Memory,
Table,
Elem,
Data,
Expand Down
17 changes: 16 additions & 1 deletion crates/wasmi/src/engine/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
saturating_float_to_int: bool,
/// Is `true` if the [`multi-value`] Wasm proposal is enabled.
multi_value: bool,
/// Is `true` if the [`multi-memory`] Wasm proposal is enabled.
multi_memory: bool,
/// Is `true` if the [`bulk-memory`] Wasm proposal is enabled.
bulk_memory: bool,
/// Is `true` if the [`reference-types`] Wasm proposal is enabled.
Expand Down Expand Up @@ -176,6 +178,7 @@
sign_extension: true,
saturating_float_to_int: true,
multi_value: true,
multi_memory: true,
bulk_memory: true,
reference_types: true,
tail_call: true,
Expand Down Expand Up @@ -266,6 +269,18 @@
self
}

/// Enable or disable the [`multi-memory`] Wasm proposal for the [`Config`].
///
/// # Note
///
/// Enabled by default.
///
/// [`multi-memory`]: https://github.com/WebAssembly/multi-memory
pub fn wasm_multi_memory(&mut self, enable: bool) -> &mut Self {
self.multi_memory = enable;
self

Check warning on line 281 in crates/wasmi/src/engine/config.rs

View check run for this annotation

Codecov / codecov/patch

crates/wasmi/src/engine/config.rs#L281

Added line #L281 was not covered by tests
}

/// Enable or disable the [`bulk-memory`] Wasm proposal for the [`Config`].
///
/// # Note
Expand Down Expand Up @@ -419,7 +434,7 @@
simd: false,
relaxed_simd: false,
threads: false,
multi_memory: false,
multi_memory: self.multi_memory,
exceptions: false,
memory64: false,
memory_control: false,
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/executor/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ impl CachedInstance {
///
/// It is the callers responsibility to use this method only when the caches are fresh.
#[inline]
pub unsafe fn get_memory(&self, index: u32) -> Option<Memory> {
pub unsafe fn get_memory(&self, index: index::Memory) -> Option<Memory> {
let instance = unsafe { self.as_ref() };
instance.get_memory(index)
instance.get_memory(u32::from(index))
}

/// Returns the [`Table`] at the `index` if any.
Expand Down
Loading
Loading