| d2dee5dd | 27-Mar-2026 |
Nick Fitzgerald <[email protected]> |
Handle OOM in `{Func,Memory,Table,Global}::new` and when calling an instance's exported function (#12855)
* Use `try_new` for `Box<dyn RuntimeLinearMemory>` in `DefaultMemoryCreator`
* Use `TryPrim
Handle OOM in `{Func,Memory,Table,Global}::new` and when calling an instance's exported function (#12855)
* Use `try_new` for `Box<dyn RuntimeLinearMemory>` in `DefaultMemoryCreator`
* Use `TryPrimaryMap` for `host_globals` in `Store`
* Add `Func::try_wrap` and use `try_new` for `Box<HostFunc>`
Add `Func::try_wrap` as a fallible version of `Func::wrap` that returns an error on out-of-memory instead of panicking. `Func::wrap` now delegates to `try_wrap`.
Also use `try_new::<Box<_>>` instead of `Box::new` for `HostFunc`.
* Use `bumpalo`'s `try_alloc` for `FuncRefs`
* Use `try_new` for `Arc<Module>` in "trampoline" code
* Test that we handle OOM in `{Func,Memory,Table,Global}::new` and when calling an instance's exported function
* cargo fmt
show more ...
|
| e1f50aad | 21-Aug-2025 |
Alex Crichton <[email protected]> |
Make table/memory creation async functions (#11470)
* Make core instance allocation an `async` function
This commit is a step in preparation for #11430, notably core instance allocation, or `Store
Make table/memory creation async functions (#11470)
* Make core instance allocation an `async` function
This commit is a step in preparation for #11430, notably core instance allocation, or `StoreOpaque::allocate_instance` is now an `async fn`. This function does not actually use the `async`-ness just yet so it's a noop from that point of view, but this propagates outwards to enough locations that I wanted to split this off to make future changes more digestable.
Notably some creation functions here such as making an `Instance`, `Table`, or `Memory` are refactored internally to use this new `async` function. Annotations of `assert_ready` or `one_poll` are used as appropriate as well.
For reference this commit was benchmarked with our `instantiation.rs` benchmark in the pooling allocator and shows no changes relative to the original baseline from before-`async`-PRs.
* Make table/memory creation `async` functions
This commit is a large-ish refactor which is made possible by the many previous refactorings to internals w.r.t. async-in-Wasmtime. The end goal of this change is that table and memory allocation are both `async` functions. Achieving this, however, required some refactoring to enable it to work:
* To work with `Send` neither function can close over `dyn VMStore`. This required changing their `Option<&mut dyn VMStore>` arugment to `Option<&mut StoreResourceLimiter<'_>>` * Somehow a `StoreResourceLimiter` needed to be acquired from an `InstanceAllocationRequest`. Previously the store was stored here as an unsafe raw pointer, but I've refactored this now so `InstanceAllocationRequest` directly stores `&StoreOpaque` and `Option<&mut StoreResourceLimiter>` meaning it's trivial to acquire them. This additionally means no more `unsafe` access of the store during instance allocation (yay!). * Now-redundant fields of `InstanceAllocationRequest` were removed since they can be safely inferred from `&StoreOpaque`. For example passing around `&Tunables` is now all gone. * Methods upwards from table/memory allocation to the `InstanceAllocator` trait needed to be made `async`. This includes new `#[async_trait]` methods for example. * `StoreOpaque::ensure_gc_store` is now an `async` function. This internally carries a new `unsafe` block carried over from before with the raw point passed around in `InstanceAllocationRequest`. A future PR will delete this `unsafe` block, it's just temporary.
I attempted a few times to split this PR up into separate commits but everything is relatively intertwined here so this is the smallest "atomic" unit I could manage to land these changes and refactorings.
* Shuffle `async-trait` dep
* Fix configured build
show more ...
|
| f8177c20 | 19-Aug-2025 |
Alex Crichton <[email protected]> |
Refactor `InstanceAllocator` trait impl split (#11457)
Prior to this commit Wasmtime had an `InstanceAllocatorImpl` trait with a number of required methods as well as an `InstanceAllocator` trait wi
Refactor `InstanceAllocator` trait impl split (#11457)
Prior to this commit Wasmtime had an `InstanceAllocatorImpl` trait with a number of required methods as well as an `InstanceAllocator` trait with a number of provided impls. The `InstanceAllocator` trait is implemented for everything implementing `InstanceAllocatorImpl` to force users to be unable to override the default methods. When adding `async` support internally to Wasmtime these are going to need to be `#[async_trait]`-annotated-traits which adds a cost to `async` functions as a future needs to be heap-allocated.
The goal of this commit is to make this future `async`-ification a bit more optimal. Notably the `InstanceAllocator` trait is removed and replaced with inherent methods on `impl dyn InstanceAllocatorImpl`. After that the previous `InstanceAllocatorImpl` trait was renamed to `InstanceAllocator` meaning that there's just one `InstanceAllocator` trait which has inherent methods which cannot be overridden. A consequence of this is that the inherent methods are also forced to do virtual dispatch unlike before where they would internally use monomorphization to have static dispatch. Given the complexity of instance allocation this is expected to be a negligible cost, however.
The main benefit is that `allocate_module`, `allocate_tables`, and `allocate_memories` all get to be native `async` functions without the cost of `#[async_trait]`. Only allocation of a single table/memory will require an allocation of a future which in profiling helps reduce the cost of instantiation slightly.
Note that `#[async_trait]` is not currently used, this commit is just preparation for its eventual use.
show more ...
|