-
Notifications
You must be signed in to change notification settings - Fork 225
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
Refactor code generation #373
Comments
I agree that the capnpc could use a lot of refactoring. I don't think we need to bring in new dependencies, though. |
This library already requires you to set up an environment where you can shell out to Automatically running the output through |
It is difficult for the end-user to get a grip on the code generation process, partly because the to-be-interpolated code lacks visual clarity: capnproto-rust/capnpc/src/codegen.rs Lines 1497 to 1510 in 9136f83
Using a procedural macro which interpolates the variables (like for instance the one in the quote_like!{
#[inline]
pub fn which(self) -> ::core::result::Result<#concrete_type, #capnp::NotInSchema> {
match self.#field_name.get_data_field::<u16>(#doffset) {
#getter_interior
}
}
} In principle (as per the documentation) users should have the flexibility to add functionality to the codegen (for instance with custom annotations) and in many cases this would require forking and modifying the existing codegen. I would therefore argue that the codegen needs to be especially transparent and comprehensible. The usage of the quote library might initially appear as overkill (it is true that in principle no AST is required in in the output) but it can serve as a reliable intermediate data format, facilitating future development and maintainability. The Of course there might be a performance penalty and relying on another dependency would undoubtedly increase compile times. Another option would be to write a custom procedural macro, similar to |
The code generation is very bespoke, and I think there's significant scope for simplifying this, but it would be quite a lot of work, so I wanted to gauge the appetite for this before I start.
Currently the code is generated as a formatted string, using a custom code-gen framework.
I propose generating an abstract syntax tree representation instead, and then formatting it at the end.
That would allow you to use rust's standard tooling (
syn
andquote
) to generate the AST. You could then format usingprettyplease
or by shelling out torustfmt
The text was updated successfully, but these errors were encountered: