-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
bulk-memory
Wasm proposal (#628)
* add bulk-memory-operations Wasm spec tests They are currently all failing obviously since bulk-memory has not yet been implemented. The goal is to implement bulk-memory until all tests pass in this PR. * add bulk_memory flag to Config * refactor Wasm spec test suite runners * refactor define_X_tests macros * add comment about mutable-global * remove ModuleError::Unsupported Those errors are now panics which makes more sense considering the fact that the wasmparser crate already filters out all of those items unless there is a bug. And if there is a bug we should panic instead of properly managing the error. * cleanup after last commit to use panics instead of unsupported error * implement initial skeleton for passive data segments * export DataSegmentKind from the data module and use it * refactor data segments minimally * add skeleton for passive Wasm element segments * refactor InitExpr * add InstanceDataSegment to InstanceEntity * add data segments to instance and store * implement memory.init Wasm instruction * replace todo!() with unimplemented!() * fix doc links * implement DataDrop wasmi instruction * add missing docs * remove commented out line * add wasmi memory.fill instruction * implement wasmi memory.copy instruction * remove unused APIs * fix bug in bulk-memory instructions implemented so far * move memory query down * fix bug in some bulk-memory instruction impls Now 3 of the 8 bulk-memory Wasm spec tests pass! * adjust InitExpr and module::ElementSegment * fix bugs * add element segments to the store * implement table.init and elem.drop Wasm instructions * update wast from 0.44 to 0.45 * update wast 0.45 -> 0.46 * update wast 0.46 -> 0.52 * implement Wasm table.copy instruction * implement user facing Table::copy API * update Wasm testsuite revision Many tests are failing now. Next steps are to make them pass again. * cleanup in tests * fix typo * fix Wasm spectest suite test case * remove some forwarding methods in Store * fix remaining bugs * fix code after merge * rename tests * expect failure for all reference-types related tests * fix internal doc link
- Loading branch information
Showing
24 changed files
with
1,399 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use crate::{module, module::FuncIdx, store::Stored, AsContextMut}; | ||
use alloc::sync::Arc; | ||
use wasmi_arena::ArenaIndex; | ||
|
||
/// A raw index to a element segment entity. | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct ElementSegmentIdx(u32); | ||
|
||
impl ArenaIndex for ElementSegmentIdx { | ||
fn into_usize(self) -> usize { | ||
self.0 as usize | ||
} | ||
|
||
fn from_usize(value: usize) -> Self { | ||
let value = value.try_into().unwrap_or_else(|error| { | ||
panic!("index {value} is out of bounds as element segment index: {error}") | ||
}); | ||
Self(value) | ||
} | ||
} | ||
|
||
/// A Wasm data segment reference. | ||
#[derive(Debug, Copy, Clone)] | ||
#[repr(transparent)] | ||
pub struct ElementSegment(Stored<ElementSegmentIdx>); | ||
|
||
impl ElementSegment { | ||
/// Creates a new linear memory reference. | ||
pub fn from_inner(stored: Stored<ElementSegmentIdx>) -> Self { | ||
Self(stored) | ||
} | ||
|
||
/// Returns the underlying stored representation. | ||
pub fn as_inner(&self) -> &Stored<ElementSegmentIdx> { | ||
&self.0 | ||
} | ||
|
||
/// Allocates a new [`ElementSegment`] on the store. | ||
/// | ||
/// # Errors | ||
/// | ||
/// If more than [`u32::MAX`] much linear memory is allocated. | ||
pub fn new(mut ctx: impl AsContextMut, segment: &module::ElementSegment) -> Self { | ||
let entity = ElementSegmentEntity::from(segment); | ||
ctx.as_context_mut() | ||
.store | ||
.inner | ||
.alloc_element_segment(entity) | ||
} | ||
} | ||
|
||
/// An instantiated [`ElementSegmentEntity`]. | ||
/// | ||
/// # Note | ||
/// | ||
/// With the `bulk-memory` Wasm proposal it is possible to interact | ||
/// with element segments at runtime. Therefore Wasm instances now have | ||
/// a need to have an instantiated representation of data segments. | ||
#[derive(Debug)] | ||
pub struct ElementSegmentEntity { | ||
/// The underlying items of the instance element segment. | ||
/// | ||
/// # Note | ||
/// | ||
/// These items are just readable after instantiation. | ||
/// Using Wasm `elem.drop` simply replaces the instance | ||
/// with an empty one. | ||
items: Option<Arc<[Option<FuncIdx>]>>, | ||
} | ||
|
||
impl From<&'_ module::ElementSegment> for ElementSegmentEntity { | ||
fn from(segment: &'_ module::ElementSegment) -> Self { | ||
match segment.kind() { | ||
module::ElementSegmentKind::Passive => Self { | ||
items: Some(segment.clone_items()), | ||
}, | ||
module::ElementSegmentKind::Active(_) => Self::empty(), | ||
} | ||
} | ||
} | ||
|
||
impl ElementSegmentEntity { | ||
/// Create an empty [`ElementSegmentEntity`] representing dropped element segments. | ||
fn empty() -> Self { | ||
Self { items: None } | ||
} | ||
|
||
/// Returns the items of the [`ElementSegmentEntity`]. | ||
pub fn items(&self) -> &[Option<FuncIdx>] { | ||
self.items | ||
.as_ref() | ||
.map(|items| &items[..]) | ||
.unwrap_or_else(|| &[]) | ||
} | ||
|
||
/// Drops the items of the [`ElementSegmentEntity`]. | ||
pub fn drop_items(&mut self) { | ||
self.items = None; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.