Skip to content

wasmtime component: get InstancePre from Instance #10621

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

Merged
merged 3 commits into from
Apr 21, 2025

Conversation

pchickey
Copy link
Contributor

@pchickey pchickey commented Apr 21, 2025

  • wasmtime::component::InstancePre gets a new field to hold an arc to the imported resources table resource_types: Arc<PrimaryMap<ResourceIndex, ResourceType>>. This information is available at the two spots where an InstancePre is constructed (one of which is new, below), so theres no additional computation required here, just a clone of the arc.
  • InstancePre gets a new method instance_type(&self) -> InstanceType<'_>. The InstanceType is used for typechecking. The whole purpose of this PR is so that typechecking can occur from either an Instance or InstancePre, and without taking a borrow into a Store, for the sake of wasmtime-wit-bindgen: Typecheck exports at {Foo}Indices construction #10610.
  • wasmtime::component::Instance gets a new method instance_pre<T>(&self, store: &impl AsContext<Data = T>) -> InstancePre<T>. All of the information required to construct the InstancePre is already found in the Store at the Instances's index.

…source types

types::Component can be used to create an InstanceType (also added as a
hidden method). The construction of InstancePre in the Linker calculates
this information already, and the types::Compoonent is just storing Arcs
to this information.
which retrieves an InstancePre corresponding to an Instance.

All of the information needed to compute the InstancePre is already
present in the Store under the Instances's index.

This method is pub but doc(hidden) because it is just for typechecking
(to be used in the bindings generator), so like other accessors of
InstanceType or typecheck methods, it is not exposed in the public API.
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Apr 21, 2025
… type table

construct InstanceType right from the contents of InstancePre instead of
using the intermediate ComponentType. The net is that InstancePre is
just one word larger & one arc clone more expensive than before.
@pchickey pchickey changed the title get InstancePre from Instance wasmtime component: get InstancePre from Instance Apr 21, 2025
@pchickey pchickey marked this pull request as ready for review April 21, 2025 21:16
@pchickey pchickey requested a review from a team as a code owner April 21, 2025 21:16
@pchickey pchickey requested review from dicej and alexcrichton and removed request for a team and dicej April 21, 2025 21:16
@pchickey pchickey added this pull request to the merge queue Apr 21, 2025
Merged via the queue into main with commit 1a9e623 Apr 21, 2025
43 checks passed
@pchickey pchickey deleted the pch/instance_pre_from_instance branch April 21, 2025 21:38
@pchickey pchickey restored the pch/instance_pre_from_instance branch April 21, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants