You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exporting functions returning resources prevents implementing the guest #330
A world exporting a static function that returns a resource does not behave like a constructor, despite documentation. It's not clear how to construct a resource in the guest except via constructor calls.
WIT with exported resource and constructor, vs exported function that returns resource
In the former, a GuestRunner trait is declared which enables constructing a GuestRunner on the client, and it's clear how to implement this on the guest.
Can guests own Services and provide them to the host?
Can hosts own Services and provide them to the guest?
This implementation is ambiguous, and it's not clear - except perhaps by naming convention for the latter two - how this should be bound. Should:
Guests own services, and on the guest create-service creates resources and registers them into a guest-owned dictionary, get-service provides lookup, and on the server, install-service should be bound so that it takes a handle on the host?
Hosts own services, install-service expects a resource implementation, and create-service is some sort of side-effecting operation on the guest which returns a handle to the modified resource by name?
A world exporting a static function that returns a resource does not behave like a constructor, despite documentation. It's not clear how to construct a resource in the guest except via constructor calls.
Ah, I think you're hitting a current-but-temporary limitation of the WIT tooling. (At the component-model level, constructor-vs-static-function is purely a naming different; they have the same types and semantics.)
the use in aici (which I expect is what you're writing) is going to implicitly add an import of controller to aici, which means that a component targeting aici is not defining and implementing runner, which is why there's not a trait for implementing the resource.
Ultimately, this gets to the root problem addressed by #308 and thus I think would be fixed by #308. With #308, you could write:
Hmm, that doesn't work yet either - the codegen is:
pubmod exports {pubmod aici {pubmod abi {pubmod runner {pubtypeController = super::super::super::super::aici::abi::ctrl::Controller;pubtraitGuest{fnrun(args:_rt::Vec::<u8>,) -> Controller;}}}}}
But there is no guest trait to implement for runner, so this function is impossible to implement. There's no way to obtain a Controller handle in the guest, even if that were the intention.
Hm there's a couple versions of WITs in play in this issue, so I'd want to make sure I pick the right one. @AaronFriel can you summarize where you're currently at, e.g. which WIT document generates bindings that you're not expecting?
Ah yes that's because the aici world is exporting the run interface, but run transitively refers to the controller interface. That controller interface is neither imported nor exported, so it ends up being implicitly imported. As it's an imported interface you only get functionality in the interface itself, so there's no way to construct the resource.
If, however, export controller is added to world aici then you should have the ability to construct a custom runner resource.
Good question! The implicit use-resolution rules that Alex described (and I forgot) look for an exported version of a used interface before falling back to adding an import, thus the explicit export controller; is found by the use controller, thereby preventing an implicit import from being generated. And yes, #308 should indeed clarify all this and also avoid the need for the explicit export controller;; use export controller.{runner} would do the right thing.
That's great - thanks for answering my questions! I'm implementing microsoft/aici#70 to simplify the bindings between the host and guest and this has been very helpful.
Activity
AaronFriel commentedon Mar 25, 2024
Related to this and #285, I think it's not obvious what
-> foofor some resource foo should be.It could be a reference to a pre-existing component, i.e.:
Can guests own
Servicesand provide them to the host?Can hosts own
Servicesand provide them to the guest?This implementation is ambiguous, and it's not clear - except perhaps by naming convention for the latter two - how this should be bound. Should:
Guests own services, and on the guest
create-servicecreates resources and registers them into a guest-owned dictionary,get-serviceprovides lookup, and on the server,install-serviceshould be bound so that it takes a handle on the host?Hosts own services,
install-serviceexpects a resource implementation, andcreate-serviceis some sort of side-effecting operation on the guest which returns a handle to the modified resource by name?lukewagner commentedon Mar 25, 2024
Ah, I think you're hitting a current-but-temporary limitation of the WIT tooling. (At the component-model level, constructor-vs-static-function is purely a naming different; they have the same types and semantics.)
In particular, in your static function example:
the
useinaici(which I expect is what you're writing) is going to implicitly add an import ofcontrollertoaici, which means that a component targetingaiciis not defining and implementingrunner, which is why there's not a trait for implementing the resource.Ultimately, this gets to the root problem addressed by #308 and thus I think would be fixed by #308. With #308, you could write:
so that now an
aicicomponent is defining-and-exportingrunner.FWIW, I believe a short-term workaround is:
AaronFriel commentedon Mar 26, 2024
Hmm, that doesn't work yet either - the codegen is:
But there is no guest trait to implement for
runner, so this function is impossible to implement. There's no way to obtain aControllerhandle in the guest, even if that were the intention.lukewagner commentedon Mar 26, 2024
Ah, that's surprising; maybe I'm forgetting something or maybe it's a bug? @alexcrichton do you know?
alexcrichton commentedon Mar 26, 2024
Hm there's a couple versions of WITs in play in this issue, so I'd want to make sure I pick the right one. @AaronFriel can you summarize where you're currently at, e.g. which WIT document generates bindings that you're not expecting?
AaronFriel commentedon Mar 26, 2024
Ah, it was the workaround proposed above:
alexcrichton commentedon Mar 26, 2024
Ah yes that's because the
aiciworld is exporting theruninterface, butruntransitively refers to thecontrollerinterface. Thatcontrollerinterface is neither imported nor exported, so it ends up being implicitly imported. As it's an imported interface you only get functionality in the interface itself, so there's no way to construct the resource.If, however,
export controlleris added toworld aicithen you should have the ability to construct a customrunnerresource.lukewagner commentedon Mar 26, 2024
Ah right, sorry, my mistake above. So then I think the workaround is:
AaronFriel commentedon Mar 26, 2024
I see - does
export controllerchange the return type of the binding forrun?Or is this clarified by #308 where the notional direction of
runneris clear?lukewagner commentedon Mar 26, 2024
Good question! The implicit
use-resolution rules that Alex described (and I forgot) look for an exported version of aused interface before falling back to adding an import, thus the explicitexport controller;is found by theuse controller, thereby preventing an implicit import from being generated. And yes, #308 should indeed clarify all this and also avoid the need for the explicitexport controller;;use export controller.{runner}would do the right thing.AaronFriel commentedon Mar 26, 2024
That's great - thanks for answering my questions! I'm implementing microsoft/aici#70 to simplify the bindings between the host and guest and this has been very helpful.
lukewagner commentedon Mar 26, 2024
Great! Closing, but feel free to reopen if there are further questions.