Skip to content

Commit 9dcfeed

Browse files
docs: update changelog, architecture, contributing
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 9e533d2 commit 9dcfeed

File tree

5 files changed

+55
-47
lines changed

5 files changed

+55
-47
lines changed

ARCHITECTURE.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
# TinyWasm's Architecture
22

33
TinyWasm follows the general Runtime Structure described in the [WebAssembly Specification](https://webassembly.github.io/spec/core/exec/runtime.html).
4-
Some key differences are:
54

6-
- **Type Storage**: Types are inferred from usage context rather than stored explicitly, with all values held as `u64`.
7-
- **Stack Design**: Implements a specific stack for values, labels, and frames to simplify the implementation and enable optimizations.
8-
- **Bytecode Format**: Adopts a custom bytecode format to reduce memory usage and improve performance by allowing direct execution without the need for decoding.
9-
- **Global State Access**: Allows cross-module access to the `Store`'s global state, optimizing imports and exports access. Access requires a module instance reference, maintaining implicit ownership through a reference count.
10-
- **Non-thread-safe Store**: Designed for efficiency in single-threaded applications.
11-
- **JIT Compilation Support**: Prepares for JIT compiler integration with function instances designed to accommodate `WasmFunction`, `HostFunction`, or future `JitFunction`.
12-
- **`no_std` Environment Support**: Offers compatibility with `no_std` environments by allowing disabling of `std` feature
13-
- **Call Frame Execution**: Executes call frames in a single loop rather than recursively, using a single stack for all frames, facilitating easier pause, resume, and step-through.
5+
Key runtime layout:
146

15-
## Bytecode Format
7+
- Values are stored in four fixed-capacity typed stacks: `stack_32` (`i32`/`f32`), `stack_64` (`i64`/`f64`), `stack_128` (`v128`), and `stack_ref` (`funcref`/`externref`).
8+
- Locals are allocated in those value stacks. Each `CallFrame` stores `locals_base`, and local ops index from that base.
9+
- Calls use a separate fixed-capacity `CallStack` of `CallFrame`s.
10+
- Structured control (`block`/`loop`/`if`/`br*`) is lowered during parsing to jump-oriented instructions: `Jump`, `JumpIfZero`, `BranchTable*`, `DropKeep*`, and `Return`.
11+
- The interpreter executes this lowered bytecode in a single iterative loop.
1612

17-
To improve performance and reduce code size, instructions are encoded as enum variants instead of opcodes.
18-
This allows preprocessing the bytecode into a more memory aligned format, which can be loaded directly into memory and executed without decoding later. This can skip the decoding step entirely on resource-constrained devices where memory is limited. See this [blog post](https://wasmer.io/posts/improving-with-zero-copy-deserialization) by Wasmer
19-
for more details which inspired this design.
13+
## Precompiled Modules
2014

21-
Some instructions are split into multiple variants to reduce the size of the enum (e.g. `br_table` and `br_label`).
22-
Additionally, label instructions contain offsets relative to the current instruction to make branching faster and easier to implement.
23-
Also, `End` instructions are split into `End` and `EndBlock`. Others are also combined, especially in cases where the stack can be skipped.
15+
`TinyWasmModule` can be serialized to `.twasm` (`serialize_twasm`) and loaded later (`from_twasm`).
16+
This allows deployments that execute precompiled modules without enabling the parser in the runtime binary.
2417

25-
See [instructions.rs](./crates/types/src/instructions.rs) for the full list of instructions.
18+
See:
2619

27-
This is a area that can still be improved. While being able to load pre-processes bytecode directly into memory is nice, in-place decoding could achieve similar speeds, see [A fast in-place interpreter for WebAssembly](https://arxiv.org/abs/2205.01183).
20+
- [visit.rs](./crates/parser/src/visit.rs)
21+
- [instructions.rs](./crates/types/src/instructions.rs)
22+
- [value_stack.rs](./crates/tinywasm/src/interpreter/stack/value_stack.rs)
23+
- [call_stack.rs](./crates/tinywasm/src/interpreter/stack/call_stack.rs)

CHANGELOG.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Support for the custom memory page sizes proposal ([#22](https://github.com/explodingcamera/tinywasm/pull/22) by [@danielstuart14](https://github.com/danielstuart14))
1313
- Support for the `tail_call` proposal
1414
- Support for the `memory64` proposal
15-
- Groundwork for the `simd` proposal
15+
- Support for the fixed-width `simd` proposal
16+
- Support for the `relaxed_simd` proposal
17+
- Support for the `wide_arithmetic` proposal
18+
- New `Engine` API (`tinywasm::Engine` and `engine::Config`) for runtime configuration
19+
- Resumable function execution with fuel/time-budget APIs (`call_resumable`, `resume_with_fuel`, `resume_with_time_budget`, `ExecProgress`)
20+
- Host-function fuel APIs: `FuncContext::charge_fuel` and `FuncContext::remaining_fuel`
21+
- `engine::FuelPolicy` and `engine::Config::fuel_policy` for fuel accounting behavior
1622
- New `canonicalize_nans` feature flag to enable canonicalizing NaN values in the `f32`, `f64`, and `v128` types
1723

24+
### Changed
25+
26+
- Locals are now stored in the typed value stacks instead of a separate locals structure
27+
- Structured control flow is fully lowered to jump-oriented internal instructions during parsing
28+
- Stack and call-stack limits are configured via `engine::Config`
29+
1830
### Breaking Changes
1931

2032
- New backwards-incompatible version of the twasm format based on `postcard` (thanks [@dragonnn](https://github.com/dragonnn))
2133
- `RefNull` has been removed and replaced with new `FuncRef` and `ExternRef` structs
22-
- Increased MSRV to 1.83.0
23-
- `tinywasm::Error` is now `non_exhaustive`, `Error::ParseError` has been rename to `Error::Parser` and `Error::Twasm` has been added.
34+
- `Store::new` now takes an `Engine`; use `Store::default()` for default settings
35+
- `Error`, `Trap`, and `LinkingError` are now `#[non_exhaustive]`
36+
- `Trap` variant discriminant values changed (if you cast variants to integers)
37+
- `tinywasm::interpreter` is no longer a public module; `InterpreterRuntime` and `TinyWasmValue` are no longer public API
38+
- `FuncHandle::name` was removed
39+
- Cargo feature `simd` was removed
40+
- Cargo feature `tinywasm-parser` was renamed to`parser`
41+
- Cargo feature `logging` was renamed to `log`
42+
- Increased MSRV to 1.90
43+
- `Error::ParseError` was renamed to `Error::Parser`, and `Error::Twasm` was added
2444

2545
### Fixed
2646

2747
- Fixed archive **no_std** support which was broken in the previous release, and added more tests to ensure it stays working
48+
- `ModuleInstance::exported_memory` and `FuncContext::exported_memory` are now actually immutable ([#41](https://github.com/explodingcamera/tinywasm/pull/41))
2849
- Check returns in untyped host functions ([#27](https://github.com/explodingcamera/tinywasm/pull/27)) (thanks [@WhaleKit](https://github.com/WhaleKit))
2950

3051
## [0.8.0] - 2024-08-29

CONTRIBUTING.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
# Contributing
22

3-
Thank you for considering contributing to this project! This document outlines the process for contributing to this project. For small changes or bug fixes, feel free to open a pull request directly. For larger changes, please open an issue first to discuss the proposed changes. Also, please ensure that you open up your pull request against the `next` branch and [allow maintainers of the project to edit your code](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork).
3+
Thank you for considering a contribution. For small fixes, feel free to open a pull request directly. For larger changes, please open an issue first so we can discuss the approach. Please target the `next` branch and [allow maintainers to edit your PR branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork).
44

5-
## 1. Clone the Repository
5+
## Code of Conduct
66

7-
Ensure you clone this repository with the `--recursive` flag to include the submodules:
7+
This project follows the [Contributor Covenant 3.0 Code of Conduct](https://www.contributor-covenant.org/version/3/0/code_of_conduct/).
88

9-
```bash
10-
git clone --recursive https://github.com/explodingcamera/tinywasm.git
11-
```
12-
13-
If you have already cloned the repository, you can initialize the submodules with:
14-
15-
```bash
16-
git submodule update --init --recursive
17-
```
18-
19-
This is required to run the WebAssembly test suite.
20-
21-
## 2. Set up the Development Environment
9+
## Development
2210

2311
This project mostly uses a pretty standard Rust setup. Some common tasks:
2412

@@ -32,14 +20,17 @@ $ cargo test
3220
# Run only the WebAssembly MVP (1.0) test suite
3321
$ cargo test-wasm-1
3422

35-
# Run only the full WebAssembly test suite (2.0)
23+
# Run only the full WebAssembly 2.0 test suite
3624
$ cargo test-wasm-2
3725

38-
# Run a specific test (run without arguments to see available tests)
39-
$ cargo test --test {test_name}
26+
# Run only the full WebAssembly 3.0 test suite
27+
$ cargo test-wasm-3
4028

4129
# Run a single WAST test file
42-
$ cargo test-wast {path}
30+
$ cargo test-wast ./wasm-testsuite/data/wasm-v1/{file}.wast
31+
32+
# Run custom wasm tests from crates/tinywasm/tests/wasm-custom
33+
$ cargo test-wasm-custom
4334

4435
# Run a specific example (run without arguments to see available examples)
4536
# The wasm test files required to run the `wasm-rust` examples are not
@@ -51,20 +42,20 @@ $ cargo run --example {example_name}
5142

5243
### Profiling
5344

54-
Either [samply](https://github.com/mstange/samply/) or [cargo-flamegraph](https://github.com/flamegraph-rs/flamegraph) are recommended for profiling.
45+
Use [samply](https://github.com/mstange/samply/) for profiling.
5546

5647
Example usage:
5748

5849
```bash
5950
cargo install --locked samply
60-
cargo samply --example wasm-rust -- selfhosted
51+
samply record -- cargo run --release --example wasm-rust -- selfhosted
6152
```
6253

63-
# Commits
54+
## Commits
6455

6556
This project uses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages. For pull requests, the commit messages will be squashed so you don't need to worry about this too much. However, it is still recommended to follow this convention for consistency.
6657

67-
# Branches
58+
## Branches
6859

6960
- `main`: The main branch. This branch is used for the latest stable release.
7061
- `next`: The next branch. Development happens here.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ serde={version="1.0", features=["derive"]}
1919

2020
[workspace.package]
2121
version="0.9.0-alpha.0"
22-
rust-version="1.93"
22+
rust-version="1.90"
2323
edition="2024"
2424
license="MIT OR Apache-2.0"
2525
authors=["Henry Gressmann <mail@henrygressmann.de>"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## Current Status
1010

11-
`tinywasm` passes all WebAssembly MVP and WebAssembly 2.0 tests from the [WebAssembly core testsuite](https://github.com/WebAssembly/testsuite) and is able to run most WebAssembly programs. Additionally, support for WebAssembly 3.0 is mostly done. See the [Supported Proposals](#supported-proposals) section for more information.
11+
`tinywasm` passes 100% of WebAssembly MVP and WebAssembly 2.0 tests from the [WebAssembly core testsuite](https://github.com/WebAssembly/testsuite) and is able to run most WebAssembly programs. Additionally, support for WebAssembly 3.0 is on the way. See the [Supported Proposals](#supported-proposals) section for more information.
1212

1313
## Usage
1414

0 commit comments

Comments
 (0)