rvolosatovs opened PR #7688 from rvolosatovs:feat/dynamic-resources to bytecodealliance:main:
Closes https://github.com/bytecodealliance/wasmtime/issues/7676
Follow-up on #7680This feature requires changes in the resource table to allow specifying the
ResourceTypeassociated with the resource stored (since assumption that it's always equal toResourceType::host::<T>()is no longer valid
rvolosatovs updated PR #7688.
rvolosatovs edited PR #7688:
Closes https://github.com/bytecodealliance/wasmtime/issues/7676
Follow-up on #7680This feature requires changes in the resource table to allow specifying the
ResourceTypeassociated with the resource stored (since assumption that it's always equal toResourceType::host::<T>()is no longer valid)
alexcrichton commented on PR #7688:
I think I might have missed something in this by accident perhaps. I don't think that this is the direction things should go in, for example
Resource<T>is designed to have a statically known type asResourceType::host::<T>()as opposed to a runtime-defined type. Having a runtime-defined type sort of defeats the purpose of the type parameter which at that point require a redesign of the resource-related APIs.The title of this PR though, allowing host creation of guest resources, is not something Wasmtime can enable. Just as guests can't create host-defined resources without asking the host to do so the other way around is the same. The host can't conjure a guest resource out of thin air, it must originate in the guest.
Given that I fear I might have missed some motivation/use case when talking about this, could you perhaps clarify?
rvolosatovs commented on PR #7688:
Given that I fear I might have missed some motivation/use case when talking about this, could you perhaps clarify?
Here's a more concrete example of the use case:
Assume the following WIT:
interface types { use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; resource future-string { subscribe: func() -> pollable; get: func() -> option<string>; } } interface example { use types.{future-string}; foo: func(future-string); } world opaque-world { export example }And a component exporting the
exampleinterface.The intention is to call
example.fooon the component without having the WIT at compilation time, i.e. parsing the WIT from the Wasm itself at runtime (which works already) and then invokingexample.foowithin the component.
The only blocker for this now is the fact that the host cannot constructfuture-stringat runtime if it does not have thefuture-stringWIT definition available at compilation time (and associated bindings)The host, however, can already push a
Resourceto the table and link the associated methods on the linker, the only bit left is being able to turn theResourceconstructed at runtime into aResourceAnyto be able to invoke the function viacallorcall_async
rvolosatovs edited a comment on PR #7688:
Given that I fear I might have missed some motivation/use case when talking about this, could you perhaps clarify?
Here's a more concrete example of the use case:
Assume the following WIT:
interface types { use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; resource future-string { subscribe: func() -> pollable; get: func() -> option<string>; } } interface example { use types.{future-string}; foo: func(opaque: future-string); } world opaque-world { export example; }And a component exporting the
exampleinterface.The intention is to call
example.fooon the component without having the WIT at compilation time, i.e. parsing the WIT from the Wasm itself at runtime (which works already) and then invokingexample.foowithin the component.
The only blocker for this now is the fact that the host cannot constructfuture-stringat runtime if it does not have thefuture-stringWIT definition available at compilation time (and associated bindings)The host, however, can already push a
Resourceto the table and link the associated methods on the linker, the only bit left is being able to turn theResourceconstructed at runtime into aResourceAnyto be able to invoke the function viacallorcall_async
rvolosatovs commented on PR #7688:
Another way to look at this would be the following:
- If one could pass a
wasmtime::component::Val::U32, which stores theResource::repvalue as a function parameter directly where a resource is expected, that would cover the use case.Perhaps a an even more generic view on this could be allowing arbitrary
impl Lowervalues to be passed as arguments tocall/call_async(or yet another alternative)This all really boils down to being able to pass the resource index to a component in cases where the resource type is not known at compilation time
rvolosatovs edited a comment on PR #7688:
Another way to look at this would be the following:
- If one could pass a
wasmtime::component::Val::U32, which stores theResource::repvalue as a function parameter directly where a resource is expected, that would cover the use case.Perhaps an even more generic view on this could be allowing arbitrary
impl Lowervalues to be passed as arguments tocall/call_async(or yet another alternative)This all really boils down to being able to pass the resource index to a component in cases where the resource type is not known at compilation time
github-actions[bot] commented on PR #7688:
Subscribe to Label Action
cc @peterhuene
<details>
This issue or pull request has been labeled: "wasi", "wasmtime:api"Thus the following users have been cc'd because of the following labels:
- peterhuene: wasmtime:api
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
rvolosatovs updated PR #7688.
Last updated: Dec 13 2025 at 19:03 UTC