-
Notifications
You must be signed in to change notification settings - Fork 97
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
Need a tool to extract actor or class signatures #4753
Comments
Thank you for the suggestion! Is there a motivating project / use case so we can better understand the problem you hope to solve with this tool? |
Of course: I have a CanDB partition actor X dependent on actor Y. But Y needs to call methods from X. I can't make Y dependent on X, because it would be a circular dependency (and this also would greatly increase compilation time). So I would preprocess X to have an abstract actor to include into Y. Currently I edit this abstract actor manually what is error-prone. |
If I understand correctly, we currently have a way to do this with Motoko bindings from If you want a fully custom solution, you could look into using |
This does not work in practice: The following is a simplified idea of mutual dependence: in one direction dependency on the implementation and in other one just on the interface. Consider
{
"canisters": {
"A": {
"main": "src/interdep_backend/A.mo",
"type": "motoko",
"dependencies": ["B"],
"declarations": {
"bindings": ["mo"]
}
},
"B": {
"main": "src/interdep_backend/B.mo",
"type": "motoko"
}
},
"defaults": {
"build": {
"args": "",
"packtool": ""
}
},
"output_env_file": ".env",
"version": 1
}
import B "canister:B";
actor A {};
This is impossible to compile: To compile
That is, generation of Any ideas how to fix it? |
I asked about this internally, and it seems like there isn't really a way around this given the design of dfx. The cleanest solution would be to remove the mutual dependency if possible. I'll mention this in the next Languages team meeting so we can decide on a priority for addressing this, perhaps via a header module code generation tool as you suggested. Note that it would be a while before this is available (at least several months, possibly over a year) if we end up building this due to prioritizing items on the Motoko roadmap. |
Not that I'm recommending this approach but I did actually come up with a workaround for this using hand-crafted candid for the forward declarations. |
We need to have a tool that will extract actor/class signatures to create "header" files. I will explain on an example:
would be transformed into:
The text was updated successfully, but these errors were encountered: