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
ResourceType
associated 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
ResourceType
associated 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
example
interface.The intention is to call
example.foo
on 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.foo
within the component.
The only blocker for this now is the fact that the host cannot constructfuture-string
at runtime if it does not have thefuture-string
WIT definition available at compilation time (and associated bindings)The host, however, can already push a
Resource
to the table and link the associated methods on the linker, the only bit left is being able to turn theResource
constructed at runtime into aResourceAny
to be able to invoke the function viacall
orcall_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
example
interface.The intention is to call
example.foo
on 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.foo
within the component.
The only blocker for this now is the fact that the host cannot constructfuture-string
at runtime if it does not have thefuture-string
WIT definition available at compilation time (and associated bindings)The host, however, can already push a
Resource
to the table and link the associated methods on the linker, the only bit left is being able to turn theResource
constructed at runtime into aResourceAny
to be able to invoke the function viacall
orcall_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::rep
value 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 Lower
values 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::rep
value 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 Lower
values 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: Nov 22 2024 at 17:03 UTC