Skip to content

Commit 7b9b3ec

Browse files
feat: add host typed reference / gc APIs (#54)
- add Store-aware handles for references, GC objects, and exceptions - simplify host value conversion, rooting, and exception propagation - update examples, tests, and documentation - Remove deprecated APIs Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 3e2e964 commit 7b9b3ec

66 files changed

Lines changed: 3402 additions & 2350 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ARCHITECTURE.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- Added support for the WebAssembly function-references proposal
13-
- Added basic support for the WebAssembly garbage-collection proposal
14-
- Added support for the WebAssembly exception-handling proposal, including tags, `try_table`, `throw`, and `throw_ref`
15-
- Added support for the WebAssembly compact-imports proposal
16-
- Added `WasmValue::ty` and `WasmValue::matches_type`
17-
- Added `ValueLane` for mapping WebAssembly value types to their physical 32-bit, 64-bit, or 128-bit storage lane.
18-
- Added a `validate` feature to `tinywasm` and `tinywasm-parser` (enabled by default) to optionally skip wasmparser validation for faster parsing of trusted modules.
19-
- Added optional parse-time operand deduplication to reduce precompiled module and `.twasm` archive size.
20-
- Added a `ResourceLimiter` trait, configurable through `engine::Config::with_resource_limiter`, to bound guest memory, table, and logical GC heap growth.
12+
- Support for the typed function references, garbage collection, exception handling, and compact import section proposals.
13+
- `ResourceLimiter` callbacks for memory and table allocation or growth
14+
- A default `validate` Cargo feature & parser option to skip wasm validation
15+
- Optional parse-time operand deduplication to reduce `.twasm` archive size
2116

2217
### Changed
2318

24-
- `HostFunction` is now a reusable definition, and module instantiation borrows `Imports` so host imports can be shared across stores.
25-
- Host function callbacks now require `Send + Sync` so the same definition can be used safely with multiple stores.
26-
- Typed function tuples now support up to 20 parameters or results. `WasmTupleChain` is deprecated. Use untyped functions for larger signatures.
27-
- Module types now use one dense recursive type space, while function types are resolved through `Function::ty(&Store)`.
28-
- Globals are stored in separate 32-bit, 64-bit, and 128-bit value lanes, avoiding tagged value conversion during guest execution.
29-
- Linear memory now uses a single contiguous `Vec`-backed storage with const-generic fixed-width loads and stores.
30-
- Increased the minimum supported Rust version from 1.95 to 1.98.
19+
- Typed functions now support tuples up to arity 20 and `[u8; 16]` values for `v128`.
20+
- Module types now use one recursive type space. Runtime function types are available through `Function::ty(&Store)`.
21+
- Linear memory now uses contiguous `Vec`-backed storage.
22+
- The minimum supported Rust version increased from 1.95 to 1.98.
23+
- The internal instruction represetaions size was reduced from 16 to 8 bytes.
3124

3225
### Fixed
3326

34-
- Directly defined imports now reject handles from a different `Store`.
27+
- Instantiation now rejects directly defined imports that contain handles from another `Store`.
3528
- Tail calls to host functions now return directly to the caller frame.
36-
- Fixed Memory64 bulk-memory operations and optimized stores using the wrong value-stack lane.
37-
- Fixed `memory.init` bounds checks and operand lowering.
38-
- Fixed Memory64 default limits and host-size handling, including 32-bit targets.
29+
- Memory64 bulk-memory operations and optimized stores now use the correct value-stack lanes.
30+
- `memory.init` now performs correct bounds checks and operand lowering.
31+
- Memory64 now uses the correct default limits and host-size conversions, including on 32-bit targets.
3932

4033
### Breaking Changes
4134

42-
- `HostFunction::from` and `HostFunction::from_untyped` no longer take a `Store` and now return reusable `HostFunction` definitions
43-
- `ModuleInstance::instantiate` and `instantiate_no_start` now borrow `Imports`.
44-
- `Store::id` now returns `u32` instead of `usize`.
45-
- `Parser::new` now takes `ParserOptions`, use `Parser::default()` for default settings. `Parser::with_options` was removed.
46-
- Renamed `ModuleInstanceAddr` to `ModuleInstanceId`.
47-
- Removed `HostFunction::ty` and `WasmFunction::ty`. Use `Function::ty(&Store)` for runtime function types.
48-
- Changed `TableType::element_type` and `Element::ty` from `WasmType` to `RefType`, and replaced module `table_types` with `TableDefinition { ty, init }`.
49-
- Removed the pluggable memory backend system (`LinearMemory`, `MemoryBackend`, `VecMemory`, `PagedMemory`, `LazyLinearMemory`, and `Config::with_memory_backend`). Linear memory is always `Vec`-backed. To limit initial memory allocation and growth, configure a `ResourceLimiter` with `Config::with_resource_limiter`.
50-
- Removed the local-memory allocation analysis (`LocalMemoryAllocation` and `ParserOptions::optimize_local_memory_allocation`). Local memories are always allocated eagerly.
51-
- Removed `Config::with_trap_on_oom`. A `ResourceLimiter` can return a trap when rejecting a memory or table allocation or growth request.
52-
- `Table::grow` now returns `Result<Option<usize>>`, matching `Memory::grow`. Growth limits and allocation failures return `None`, while limiter-provided traps return an error.
35+
- `Function::call` and `Function::call_resumable` now write to caller-provided result slices. Untyped host callbacks also receive a result slice and return `Result<()>`.
36+
- Creating a `HostFunction` no longer requires a `Store`. Definitions require `Send + Sync` and can be reused across stores. Module instantiation now borrows `Imports` so the same imports can also be reused.
37+
- `HostFunction::ty` and `WasmFunction::ty` were removed. Use `Function::ty(&Store)` for runtime types.
38+
- Function and managed reference handles are tied to their originating `Store`. Managed references keep their referents live, so `WasmValue` is no longer `Copy`. Nullable typed references use `Option<T>`, while bare typed references are non-null.
39+
- The `Memory`, `Table`, `Global`, and `Tag` constructors were renamed from `new` to `try_new`.
40+
- `Store::id` now returns `u32`, and `ModuleInstanceAddr` was renamed to `ModuleInstanceId`.
41+
- Element types now use `RefType`, and module definitions use `TableDefinition { ty, init }`. `Table::grow` now returns `Result<Option<usize>>`, matching `Memory::grow`.
42+
- `Parser::new` now takes `ParserOptions`. Use `Parser::default()` for default settings. `Parser::with_options` was removed.
43+
- Pluggable memory backends and `Config::with_trap_on_oom` were removed for performance reasons. Linear memory is always `Vec`-backed. Use `ResourceLimiter` to allow, reject, or trap memory allocation and growth requests.
44+
- `WasmTupleChain` was removed. Use direct tuples up to arity 20 or untyped functions for larger signatures.
45+
- The `.twasm` format changed. Regenerate archives created by earlier TinyWasm versions.
5346

5447
## [0.10.0] - 2026-07-24
5548

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $ cargo test-wast ./wasm-testsuite/data/wasm-v1/{file}.wast
3333
$ cargo test-wasm-custom
3434

3535
# Run a specific example (run without arguments to see available examples)
36-
# The wasm test files required to run the `wasm-rust` examples are not
36+
# The wasm test files required to run the `rust` example are not
3737
# included in the main repository.
3838
# To build these, you will need to install binaryen and wabt
3939
# and run `./examples/rust/build.sh`.
@@ -48,7 +48,7 @@ Example usage:
4848

4949
```bash
5050
cargo install --locked samply
51-
samply record -- cargo run --release --example wasm-rust -- tinywasm
51+
samply record -- cargo run --release --example rust -- tinywasm
5252
```
5353

5454
## Commits

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ wat = "1.257"
3838
criterion = { version = "0.8", default-features = false, features = ["cargo_bench_support", "rayon"] }
3939

4040
[[example]]
41-
name = "wasm-rust"
41+
name = "rust"
4242
test = false
4343

4444
[[bench]]

0 commit comments

Comments
 (0)