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

Expose get_module_export from Caller #9525

Merged
merged 1 commit into from
Nov 2, 2024

Conversation

richardpringle
Copy link
Contributor

Not necessarily trying to get this merged, just using it as an example for my comment here

@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Oct 30, 2024
@alexcrichton
Copy link
Member

What I might recommend for your use case is to store a TypedFunc<P, R> within the T of your Store<T>. That'd probably start as Option<TypedFunc<...>> and be None on store construction. After instantiation you'd load the function, set it in the store, and then all your host functions have access to that allocation function.

Alternatively if you want the absolute fastest route what I think you'd do is:

That front-loads as much as possible at the cost of safety, so I'd recommend using .get_typed_func if possible after the initial instantiation of the module.

@alexcrichton
Copy link
Member

(although if you'd like adding the API like in this PR I also think is reasonable!)

@richardpringle richardpringle marked this pull request as ready for review October 31, 2024 20:35
@richardpringle richardpringle requested a review from a team as a code owner October 31, 2024 20:35
@richardpringle richardpringle requested review from alexcrichton and removed request for a team October 31, 2024 20:35
/// Returns `None` if there was no export with a matching entity index.
/// # Panics
///
/// Panics if `store` does not own this instance.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Docs are effectively a copy/paste of Instance::get_module_export. Happy to take recommendations or if you want to make a suggestion, I will definitely accept it. I think see [Instance::get_module_export] for details would probably also be fine so long as it's clear that the caller has access to the instance (wasn't clear to me without looking at the code).

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks good to me! Mind adding a small smoke test too?

@richardpringle
Copy link
Contributor Author

Looks good to me! Mind adding a small smoke test too?

@alexcrichton not sure if this is what you meant by a smoke test, but it works as one, haha 😅 .

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks!

@alexcrichton alexcrichton added this pull request to the merge queue Nov 2, 2024
Merged via the queue into bytecodealliance:main with commit f305ef5 Nov 2, 2024
40 checks passed
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