-
Notifications
You must be signed in to change notification settings - Fork 757
Description
This is a rather loose proposal but I'd like to start this discussion as it might provide a more straightforward way to handle issues like #564 and #1743. I've seen that most of the code generation is done relying on quote!
which is a very straightforward and simple way to emit rust code.
However, tacking any issue that requires reordering or modifying the generated code would require several workarounds due to the unstructured nature of proc_macro2::TokenStream
.
I was wondering if it would be feasible and useful use syn::parse_quote!
and other tools provided by the syn
crate for code generation in order to keep all the generated code in a more structured way before emitting it so bindgen
can manipulate it in later stages in an easier way.
cc @amanjeev
Edit: I forgot to mention that one advantage of being able to handle all the items generated by bindgen
as syn
types is that we could implement "passes" in a modular way so we can easily enable/disable them. So for example, we could deduplicate extern "C" { ... }
blocks in one pass and independently write another pass to reorganize items. In general, it would help a lot when having to handle generated code in my opinion.
Another important point is that we should be able to do this transition incrementally as we can always produce TokenStream
s from the syn
data structures by using the ToToken
trait.
However, we think it's pretty important to know if this change would be worth it from the maintainers point of view or if a less intrusive way to solve the issues mentioned above would be better.