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 type information from dynamic component funcs #8070

Merged

Conversation

alexcrichton
Copy link
Member

This commit removes the &Component argument from the component::Linker::func_new API. This is inspired by #8062 where Val holds less type information as well in addition to the realization that type-checking happens at runtime rather than instantiation time.

This argument was originally added to mirror
wasmtime::Linker::func_new which takes a type argument of the core wasm function that's being defined. Unlike core wasm, though, component functions already have to carry along their type information as part of function calls to handle resources correctly. This means that when a host function is invoked the type is already known of all the parameters and results. Additionally values are already required to be type-checked going back into wasm, so there's less of a need to perform an additional type-check up front.

The main consequence of this commit is that it's a bit more difficult for embeddings to know what the expected types of results are. No type information is provided when a host function is defined, not even function arity. This means that when the host function is invoked it may not know how many results are expected to be produced and of what type. Typically though a bindings generator is used somewhere along the way so that's expected to alleviate this issue.

Finally my hope is to enhance this "dynamic" API in the future with a bit more information so the type information is more readily accessible at runtime. For now though hosts will have to "simply know what to do".

This commit removes the `&Component` argument from the
`component::Linker::func_new` API. This is inspired by bytecodealliance#8062 where `Val`
holds less type information as well in addition to the realization that
type-checking happens at runtime rather than instantiation time.

This argument was originally added to mirror
`wasmtime::Linker::func_new` which takes a type argument of the core
wasm function that's being defined. Unlike core wasm, though, component
functions already have to carry along their type information as part of
function calls to handle resources correctly. This means that when a
host function is invoked the type is already known of all the parameters
and results. Additionally values are already required to be type-checked
going back into wasm, so there's less of a need to perform an additional
type-check up front.

The main consequence of this commit is that it's a bit more difficult
for embeddings to know what the expected types of results are. No type
information is provided when a host function is defined, not even
function arity. This means that when the host function is invoked it may
not know how many results are expected to be produced and of what type.
Typically though a bindings generator is used somewhere along the way so
that's expected to alleviate this issue.

Finally my hope is to enhance this "dynamic" API in the future with a
bit more information so the type information is more readily accessible
at runtime. For now though hosts will have to "simply know what to do".
@alexcrichton alexcrichton requested a review from dicej March 8, 2024 20:16
@alexcrichton alexcrichton requested a review from a team as a code owner March 8, 2024 20:16
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team March 8, 2024 20:16
crates/wasmtime/src/runtime/component/linker.rs Outdated Show resolved Hide resolved
Co-authored-by: Joel Dice <joel.dice@fermyon.com>
@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 Mar 8, 2024
Copy link

github-actions bot commented Mar 8, 2024

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.

@alexcrichton alexcrichton added this pull request to the merge queue Mar 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 8, 2024
@alexcrichton alexcrichton added this pull request to the merge queue Mar 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 8, 2024
@alexcrichton alexcrichton requested a review from a team as a code owner March 8, 2024 22:30
@alexcrichton alexcrichton added this pull request to the merge queue Mar 8, 2024
Merged via the queue into bytecodealliance:main with commit 6a710b9 Mar 8, 2024
19 checks passed
@alexcrichton alexcrichton deleted the simpler-component-func-wrap branch March 8, 2024 23:13
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants