-
Notifications
You must be signed in to change notification settings - Fork 82
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
Exporting functions returning resources prevents implementing the guest #330
Comments
Related to this and #285, I think it's not obvious what It could be a reference to a pre-existing component, i.e.: interface service-factory {
resource service;
install-service: func(name: string, service: Service);
get-service: func(name: string) -> Service;
create-service: func(name: string) -> Service;
}
world service-factory {
export service-factory;
} Can guests own Can hosts own This implementation is ambiguous, and it's not clear - except perhaps by naming convention for the latter two - how this should be bound. Should:
|
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: world aici {
use controller.{runner};
export run: func(args: list<u8>) -> runner;
}
interface controller {
resource runner { ... }
} the Ultimately, this gets to the root problem addressed by #308 and thus I think would be fixed by #308. With #308, you could write: world aici {
use export controller.{runner};
export run: func(args: list<u8>) -> runner;
}
interface controller {
resource runner { ... }
} so that now an FWIW, I believe a short-term workaround is: world aici {
export run;
}
interface run {
use controller.{runner};
run: func(args: list<u8>) -> runner;
}
interface controller {
resource runner { ... }
} |
Hmm, that doesn't work yet either - the codegen is: pub mod exports {
pub mod aici {
pub mod abi {
pub mod runner {
pub type Controller = super::super::super::super::aici::abi::ctrl::Controller;
pub trait Guest {
fn run(args:_rt::Vec::<u8>,) -> Controller;
}
}
}
}
} But there is no guest trait to implement for |
Ah, that's surprising; maybe I'm forgetting something or maybe it's a bug? @alexcrichton do you know? |
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, it was the workaround proposed above: world aici {
export run;
}
interface run {
use controller.{runner};
run: func(args: list<u8>) -> runner;
}
interface controller {
resource runner { ... }
} |
Ah yes that's because the If, however, |
Ah right, sorry, my mistake above. So then I think the workaround is: interface run {
export controller;
use controller.{runner};
run: func(args: list<u8>) -> runner;
} |
I see - does Or is this clarified by #308 where the notional direction of |
Good question! The implicit |
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. |
Great! Closing, but feel free to reopen if there are further questions. |
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
Versus
In the former, a
GuestRunner
trait is declared which enables constructing aGuestRunner
on the client, and it's clear how to implement this on the guest.Comparison of generated Rust from `wit_bindgen`
In the latter, we instead see:
Where
Runner
is an opaque resource handle.In the latter, there is no way to implement Guest safely because there is no way to obtain a valid Runner handle.
I would expect that when a resource occurs in a return position, the bindings to implement the resource is also generated.
The text was updated successfully, but these errors were encountered: