Refactor component host/libcalls #10959
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the spirit of making Wasmtime's internals safer this is a step forward for components to a new paradigm for how libcalls/host functions are implemented. Previously
*mut ComponentInstance
was liberally used but this meant that situations would often simultaneously have&mut ComponentInstance
and&mut StoreOpaque
accessible in the same function and there was no prevention of going from the store to the component instance, acquiring two aliasing mutable references (which would be unsound). The refactoring applied here is to redefine the entrypoints from the guest back into the host to operate on&mut dyn VMStore
(orStoreContextMut<'_, T>
) pluswasmtime::component::Instance
. This index-based approach means that there's no aliasing of component instances and stores and theInstance
type can be used to look up anything within the store that's necessary.This refactoring originated in the wasip3-prototyping repository and has been used to remove a good deal of
unsafe
code now thatInstance
is effectively safe to pass around and the store was already passed around anyway everywhere.In the future I plan to apply a similar paradigm shift for core instances as well, but that'll require some more finesse for all the bits and bobs that core wasm does.