Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the need to have a Store for an InstancePre #5683

Conversation

alexcrichton
Copy link
Member

This commit relaxes a requirement of the InstancePre API, notably its construction via Linker::instantiate_pre. Previously this function required a Store<T> to be present to be able to perform type-checking on the contents of the linker, and now this requirement has been removed.

Items stored within a linker are either a HostFunc, which has type information inside of it, or an Extern, which doesn't have type information inside of it. Due to the usage of Extern this is why a Store was required during the InstancePre construction process, it's used to extract the type of an Extern. This commit implements a solution where the type information of an Extern is stored alongside the Extern itself, meaning that the InstancePre construction process no longer requires a Store<T>.

One caveat of this implementation is that some items, such as tables and memories, technically have a "dynamic type" where during type checking their current size is consulted to match against the minimum size required of an import. This no longer works when using Linker::instantiate_pre as the current size used is the one when it was inserted into the linker rather than the one available at instantiation time. It's hoped, however, that this is a relatively esoteric use case that doesn't impact many real-world users.

Additionally note that this is an API-breaking change. Not only is the Store argument removed from Linker::instantiate_pre, but some other methods such as Linker::define grew a Store argument as the type needs to be extracted when an item is inserted into a linker.

Closes #5675

This commit relaxes a requirement of the `InstancePre` API, notably its
construction via `Linker::instantiate_pre`. Previously this function
required a `Store<T>` to be present to be able to perform type-checking
on the contents of the linker, and now this requirement has been
removed.

Items stored within a linker are either a `HostFunc`, which has type
information inside of it, or an `Extern`, which doesn't have type
information inside of it. Due to the usage of `Extern` this is why a
`Store` was required during the `InstancePre` construction process, it's
used to extract the type of an `Extern`. This commit implements a
solution where the type information of an `Extern` is stored alongside
the `Extern` itself, meaning that the `InstancePre` construction process
no longer requires a `Store<T>`.

One caveat of this implementation is that some items, such as tables and
memories, technically have a "dynamic type" where during type checking
their current size is consulted to match against the minimum size
required of an import. This no longer works when using
`Linker::instantiate_pre` as the current size used is the one when it
was inserted into the linker rather than the one available at
instantiation time. It's hoped, however, that this is a relatively
esoteric use case that doesn't impact many real-world users.

Additionally note that this is an API-breaking change. Not only is the
`Store` argument removed from `Linker::instantiate_pre`, but some other
methods such as `Linker::define` grew a `Store` argument as the type
needs to be extracted when an item is inserted into a linker.

Closes bytecodealliance#5675
@alexcrichton alexcrichton requested a review from pchickey February 1, 2023 16:31
@github-actions github-actions bot added fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself labels Feb 1, 2023
@github-actions
Copy link

github-actions bot commented Feb 1, 2023

Subscribe to Label Action

cc @fitzgen, @peterhuene

This issue or pull request has been labeled: "fuzzing", "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing
  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Feb 1, 2023
@github-actions
Copy link

github-actions bot commented Feb 1, 2023

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:c-api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@alexcrichton alexcrichton reopened this Feb 1, 2023
Co-authored-by: Andrew Brown <andrew.brown@intel.com>
Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Requiring a store to Linker::define any externs makes sense, and I don't expect it will break any users.

@alexcrichton alexcrichton merged commit 63d80fc into bytecodealliance:main Feb 2, 2023
@alexcrichton alexcrichton deleted the remove-store-from-instance-pre branch February 2, 2023 17:54
jbourassa added a commit to bytecodealliance/wasmtime-rb that referenced this pull request Feb 24, 2023
This includes a breaking change, following bytecodealliance/wasmtime#5683.
`Wasmtime::Linker#define` now takes a store as a first argument.
jbourassa added a commit to bytecodealliance/wasmtime-rb that referenced this pull request Feb 24, 2023
This includes a breaking change, following bytecodealliance/wasmtime#5683.
`Wasmtime::Linker#define` now takes a store as a first argument.
lann added a commit to lann/wasmtime that referenced this pull request Mar 17, 2023
alexcrichton pushed a commit that referenced this pull request Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linker::instantiate_pre could avoid mutating a Store
3 participants