Skip to content
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

Switching to proc macros for code generation? #70

Open
projectgus opened this issue May 7, 2024 · 3 comments
Open

Switching to proc macros for code generation? #70

projectgus opened this issue May 7, 2024 · 3 comments

Comments

@projectgus
Copy link
Contributor

projectgus commented May 7, 2024

I suspect you folks have thought about this, so I'm curious what your take is on using a proc macro mechanism such as quote to generate the output code instead of writeln!?

If you think such a thing could potentially work, would you be amenable to merging a PR that switched over (without changing the generated code semantics), if someone was to put one together(*)?

(*) EDIT: With the obvious caveat that it would have to not add heinous amounts of complexity!

@killercup
Copy link
Member

What advantages do you see for this?

I remember the main reason I didn't go with anything more complex like quote initially was that this was supposed to be a quick one-off codegen thing. I've used quote and friends before a bunch for proc macros but I didn't see the value of doing it here. This is a separate build step, we don't even parse the input file ourselves so we don't benefit from tracking spans or anything like that.

@projectgus
Copy link
Contributor Author

That's a very reasonable question.

Mostly around readability of the generation code in lib.rs. Reading back the code generation stages it can be a little hard to find which piece of code generates a particular line of output, because it all kind of "flattens" into sequences of writenln!s. What I ended up doing was to open a generated messages.rs side by side and find a particular line that way.

That said, I've never used quote before so I've almost certainly got blind spots around the extra complexity of switching to it.

If keeping it this way fits with the approach & values you intend for the project then I don't think there's any reason to change, really. :)

@rdelfin
Copy link

rdelfin commented May 26, 2024

Another upside of using proc macros is you can provide the macros as a library and let people implement their own custom structs if they can't (or don't want to) use the code generation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants