Conversation
46306f4 to
af84fbc
Compare
clementblaudeau
approved these changes
Aug 14, 2025
Contributor
clementblaudeau
left a comment
There was a problem hiding this comment.
This PR addresses a real issue of verbosity when writing backends. It will make the code more concise and provide better error messages when parts of the ast are unsupported.
3d8ec14 to
0ae2e7a
Compare
0ae2e7a to
643423e
Compare
jschneider-bensch
approved these changes
Aug 14, 2025
Contributor
Author
|
Thanks @clementblaudeau and @jschneider-bensch for your reviews! :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a improves the printing and backend infrastructure.
The
PrettyAsttraitThe main change of this PR in the introduction of the
PrettyAsttrait, that reduces boilerplate.Instead of implementing
pretty::Prettyfor every type of the AST, one must only implementPrettyAst, which has default methods.The default methods print debugging information that makes it easy to iterate when writting a printer.
Helper macros
The
prettylibrary we are using for pretty printing uses an explicit allocator: whenever we must render a node, the allocator needs to be specified expclitely.As it is visible in the existing lean printer, this is very verbose.
This PR introduces
pretty_ast::install_pretty_helpers!, a macro that hides this allocator away. This macro basically creates partial applications of the allocator method using a local variable.Instead of doing:
You can do:
We also introduce the macro
prepend_associated_functions_with!(something)that prependssomethingto each body of associated function.Combining the trait
PrettyAst, the macroprepend_associated_functions_withand the macros given byinstall_pretty_helpers, we get implicit allocator across entire printers.See
backends::rustfor an example.Rust Printer
This PR introduces a dummy placeholder Rust printer.