Skip to content

Commit 5d4fc88

Browse files
feat: full multi-memory support
Signed-off-by: Henry Gressmann <[email protected]>
1 parent c8c21f8 commit 5d4fc88

File tree

13 files changed

+41
-46
lines changed

13 files changed

+41
-46
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- Full support for Multi-Memory proposal
13+
- Extern tables now correctly update their type after growing
1214
- Increased MSRV to 1.80.0
1315
- Improved support for WebAssembly 2.0 features
1416
- Simplify and optimize the interpreter loop

README.md

+21-27
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,35 @@
1414

1515
- **Tiny**: TinyWasm is designed to be as small as possible without significantly compromising performance or functionality (< 4000 LLOC).
1616
- **Portable**: TinyWasm runs on any platform that Rust can target, including `no_std`, with minimal external dependencies.
17-
- **Safe**: No unsafe code is used in the runtime (`rkyv` which uses unsafe code can be used for serialization, but it is optional).
17+
- **Safe**: No unsafe code is used in the runtime (`rkyv` which uses unsafe code can be used for serialization, but is optional).
1818

1919
## Status
2020

21-
As of version `0.3.0`, TinyWasm successfully passes all the WebAssembly 1.0 tests in the [WebAssembly Test Suite](https://github.com/WebAssembly/testsuite). Work on the 2.0 tests is ongoing. This enables TinyWasm to run most WebAssembly programs, including executing TinyWasm itself compiled to WebAssembly (see [examples/wasm-rust.rs](./examples/wasm-rust.rs)). The results of the testsuites are available [here](https://github.com/explodingcamera/tinywasm/tree/main/crates/tinywasm/tests/generated).
22-
23-
The API is still unstable and may change at any time, so you probably don't want to use it in production _yet_. TinyWasm isn't primarily designed for high performance; it focuses more on simplicity, size, and portability. Benchmarks are currently being reworked and will be available again soon.
24-
25-
**Future Development**: The first major version will focus on improving the API and adding support for [WASI](https://wasi.dev/). While doing so, I also want to further simplify and reduce the codebase's size and improve the parser's performance.
21+
TinyWasm passes all WebAssembly MVP tests from the [WebAssembly core testsuite](https://github.com/WebAssembly/testsuite) and is able to run most WebAssembly programs. Additionally, the current 2.0 Draft is mostly supported, with the exception of Fixed-Width SIMD and Memory64/Multiple Memories. See the [Supported Proposals](#supported-proposals) section for more information.
2622

2723
## Supported Proposals
2824

29-
| Proposal | Implementation Status | Version |
30-
| -------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------- |
31-
| [**Mutable Globals**](https://github.com/WebAssembly/mutable-global/blob/master/proposals/mutable-global/Overview.md) | Fully implemented | 0.2.0 |
32-
| [**Multi-value**](https://github.com/WebAssembly/spec/blob/master/proposals/multi-value/Overview.md) | Fully implemented | 0.2.0 |
33-
| [**Sign-extension operators**](https://github.com/WebAssembly/spec/blob/master/proposals/sign-extension-ops/Overview.md) | Fully implemented | 0.2.0 |
34-
| [**Bulk Memory Operations**](https://github.com/WebAssembly/spec/blob/master/proposals/bulk-memory-operations/Overview.md) | Fully implemented | 0.4.0 |
35-
| [**Reference Types**](https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md) | Partially implemented | N/A |
36-
| [**Multiple Memories**](https://github.com/WebAssembly/multi-memory/blob/master/proposals/multi-memory/Overview.md) | Partially implemented | N/A |
37-
| [**Memory64**](https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md) | Partially implemented | N/A |
25+
**Legend**\
26+
🌑 -- not available\
27+
🚧 -- in development / partialy supported\
28+
🟢 -- fully supported
29+
30+
| Proposal | Status | TinyWasm Version |
31+
| -------------------------------------------------------------------------------------------------------------------------- | ------ | ---------------- |
32+
| [**Mutable Globals**](https://github.com/WebAssembly/mutable-global/blob/master/proposals/mutable-global/Overview.md) | 🟢 | 0.2.0 |
33+
| [**Non-trapping float-to-int Conversion**](https://github.com/WebAssembly/nontrapping-float-to-int-conversions) | 🟢 | 0.2.0 |
34+
| [**Sign-extension operators**](https://github.com/WebAssembly/sign-extension-ops) | 🟢 | 0.2.0 |
35+
| [**Multi-value**](https://github.com/WebAssembly/spec/blob/master/proposals/multi-value/Overview.md) | 🟢 | 0.2.0 |
36+
| [**Bulk Memory Operations**](https://github.com/WebAssembly/spec/blob/master/proposals/bulk-memory-operations/Overview.md) | 🟢 | 0.4.0 |
37+
| [**Reference Types**](https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md) | 🟢 | 0.7.0 |
38+
| [**Multiple Memories**](https://github.com/WebAssembly/multi-memory/blob/master/proposals/multi-memory/Overview.md) | 🟢 | 0.8.0 |
39+
| [**Memory64**](https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md) | 🚧 | N/A |
40+
| [**Fixed-Width SIMD**](https://github.com/webassembly/simd) | 🌑 | N/A |
3841

3942
## Usage
4043

41-
TinyWasm can be used through the `tinywasm-cli` CLI tool or as a library in your Rust project. Documentation can be found [here](https://docs.rs/tinywasm).
42-
43-
### Library
44-
45-
```sh
46-
$ cargo add tinywasm
47-
```
48-
49-
### CLI
50-
51-
The CLI is mainly available for testing purposes, but can also be used to run WebAssembly programs.
44+
See the [examples](./examples) directory and [documentation](https://docs.rs/tinywasm) for more information on how to use TinyWasm.
45+
For testing purposes, you can also use the `tinywasm-cli` tool:
5246

5347
```sh
5448
$ cargo install tinywasm-cli
@@ -78,7 +72,7 @@ Big thanks to the authors of the following projects, which have inspired and inf
7872
- [wazero](https://wazero.io/) - a zero-dependency WebAssembly interpreter written in go
7973
- [wain](https://github.com/rhysd/wain) - a zero-dependency WebAssembly interpreter written in Rust
8074

81-
I encourage you to check these projects out if you're looking for a more mature and feature-complete WebAssembly interpreter.
75+
I encourage you to check these projects out if you're looking for more mature and feature-complete WebAssembly Runtimes.
8276

8377
## License
8478

crates/parser/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ impl Parser {
6060
saturating_float_to_int: true,
6161
function_references: true,
6262
tail_call: true,
63+
multi_memory: true,
6364

6465
gc_types: true,
6566
component_model: false,
@@ -74,7 +75,6 @@ impl Parser {
7475
relaxed_simd: false,
7576
simd: false,
7677
threads: false,
77-
multi_memory: false, // should be working mostly
7878
custom_page_sizes: false,
7979
shared_everything_threads: false,
8080
component_model_multiple_returns: false,

crates/tinywasm/src/imports.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ impl Imports {
392392
}
393393
(ExternVal::Table(table_addr), ImportKind::Table(ty)) => {
394394
let table = store.get_table(table_addr);
395-
Self::compare_table_types(import, &table.kind, ty)?;
395+
let mut kind = table.kind.clone();
396+
kind.size_initial = table.size() as u32;
397+
Self::compare_table_types(import, &kind, ty)?;
396398
imports.tables.push(table_addr);
397399
}
398400
(ExternVal::Memory(memory_addr), ImportKind::Memory(ty)) => {

crates/tinywasm/src/interpreter/executor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
540540
let (mem_from, mem_to) =
541541
self.store.get_mems_mut(self.module.resolve_mem_addr(from), self.module.resolve_mem_addr(to))?;
542542

543-
mem_to.copy_from_slice(dst as usize, mem_from.load(src as usize, size as usize)?)?;
543+
mem_from.copy_from_slice(dst as usize, mem_to.load(src as usize, size as usize)?)?;
544544
}
545545
Ok(())
546546
}

crates/tinywasm/src/store/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,6 @@ impl Store {
368368
for (i, data) in datas.into_iter().enumerate() {
369369
let data_val = match data.kind {
370370
tinywasm_types::DataKind::Active { mem: mem_addr, offset } => {
371-
// a. Assert: memidx == 0
372-
if mem_addr != 0 {
373-
return Err(Error::UnsupportedFeature("data segments for non-zero memories".to_string()));
374-
}
375-
376371
let Some(mem_addr) = mem_addrs.get(mem_addr as usize) else {
377372
return Err(Error::Other(format!("memory {mem_addr} not found for data segment {i}")));
378373
};

0 commit comments

Comments
 (0)