peterhuene commented on Issue #5:
@alexcrichton how awful would it be for
Config
to expose a method taking anArc<dyn wasmtime_runtime::InstanceAllocator>
? A complete non-starter?This asymmetry between the
InstanceAllocator
traits inwasmtime
andwasmtime-runtime
necessitate a back pointer fromwasmtime_runtime::Instance
to the allocator that created it so that the instance can call into the allocator upon deallocation of theInstanceHandle
. I would really like to see the back pointer removed.Having
Config
directly take the runtime trait would both simplify the code (i.e. no duplicated types in thewasmtime
crate) and eliminate the problem becauseStore
could use the runtime trait directly to deallocate the instance.This also means that if we open up the construction of
Instance
andInstanceHandle
in the runtime so that instance allocators can be implemented in external crates, the Wasmtime API can use those implementations without introducing a wrapping type in thewasmtime
crate.
alexcrichton commented on Issue #5:
Heh I always start with the idea that anything is possible!
More to the point though a move like that would basically just be about the costs. It would cost us in terms of stability that we would have to document that usage of the method is not covered under our semver stability promises. That's probably feasible to do since we don't expect every user to have to implement this? Especially if we can bundle "common" allocation strategies in the
wasmtime
crate which are covered under the semver rules.Other than that the only other alternative I can think of is to sync up on the code you've got and see if anyone else is struck with inspiration of how to not have the dependency
fitzgen commented on Issue #5:
It wouldn't solve the duplication issue, but would solve the API stability issues: we could create a
wasmtime-traits
crate that defines just theInstanceAllocator
trait and necessary types (e.g.InstanceRequest
) and say it has the same stability that thewasmtime
crate does (even re-export it fromwasmtime
).
peterhuene commented on Issue #5:
What if we kept the sole
InstanceAllocator
trait inwasmtime_runtime
where it would inherently be unstable (and thus implementors would know that their implementations are subject to breaks inwasmtime_runtime
) but we would then considerConfig::with_instance_allocator
to itself be stable despite takingArc<dyn wasmtime_runtime::InstanceAllocator>
as an argument? Thewasmtime
crate and any implementors ofInstanceAllocator
must agree on the definition anyway, right?The "out of the box" instance allocator implementations could be exported via the
wasmtime
crate and thus considered stable as their only public API surface are their constructors.We generally don't expect users to implement the trait themselves as it requires a lot of internal runtime understanding to do so, but we do want an easy mechanism for users to swap out the allocator implementations easily using the public Wasmtime API.
peterhuene edited a comment on Issue #5:
What if we kept the sole
InstanceAllocator
trait inwasmtime_runtime
where it would inherently be unstable (and thus implementors would know that their implementations are subject to breaks inwasmtime_runtime
) but we would then considerConfig::with_instance_allocator
to itself be stable despite takingArc<dyn wasmtime_runtime::InstanceAllocator>
as an argument? Thewasmtime
crate and any implementors ofInstanceAllocator
must agree on the definition anyway, right?The "out of the box" instance allocator implementations could be exported via the
wasmtime
crate and thus considered stable as their only public API surface are their constructors.We generally don't expect users to implement the trait themselves as it requires a lot of internal runtime understanding to do so, but we do want an easy mechanism for users to swap out the allocator implementations using the public Wasmtime API.
fitzgen commented on Issue #5:
If we don't expect anyone else to implement this trait, then we might as well make it an
enum
at thewasmtime
API level, and not expose its guts, types, and implementation details. This would let us write the instance pool in its own (internal) crate, preserve API stability, and avoid duplicating types.
fitzgen edited a comment on Issue #5:
If we don't expect anyone else to implement this trait, then we might as well make it an
enum InstanceAllocationStategy { Default, Pool }
at thewasmtime
API level, and not expose its guts, types, and implementation details. This would let us write the instance pool in its own (internal) crate, preserve API stability, and avoid duplicating types.
peterhuene commented on Issue #5:
I can get behind that. We could always extend any such enumeration for
Custom
if a trait is needed in the future.
peterhuene commented on Issue #5:
I've updated the RFC with an enum approach that hides the implementation details from the
wasmtime
crate.
Last updated: Dec 23 2024 at 12:05 UTC