-
Notifications
You must be signed in to change notification settings - Fork 249
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
feat: nargo expand
to show code after macro expansions
#7613
base: master
Are you sure you want to change the base?
Conversation
How would we do this though? The reason we only have a CLI flag currently and only output the new code is that while we're elaborating we are losing information about the source code. We throw away all type and trait definitions for example. By monomorphization we're already left with only functions. How would we output any types/traits/imports/etc back into the program? I don't think just skipping past them is an option either since metaprogramming may modify a type definition such that it differs from the source. |
Oh, I just meant that if we have a function
They are in the NodeInterner, for example
Right, we can do this before monomoprhization (or put another way: we don't monomorphize for this tool) |
nargo expand
to show code after macro expansions
Some progress: here's the output of running I listed some pending stuff in the main description for this tool to generate almost valid Noir code, but I think the most difficult thing is already done (figuring out how to recreate impls and trait impls, though I think impls are missing where clauses and they show up instead in each function). |
Description
Problem
Resolves #7552
Summary
Pending:
to_display_ast()
The idea I have for this is:
The output right now goes to the console, and just for the top-level module, and just for functions, as a way to experiment with this and get feedback from you all. Eventually a directory with all the expanded code could be created, with one file per module to match the original source code.
The downside of this approach is that comments and formatting is lost, though we could at least run the formatter at the end for formatting. Comments could be done in a follow-up where they would also be stored in the node interner, and just for this tool (maybe!).
For example, if you run it for this code:
we get this output (the function bodies use
HirExpression::to_display_ast
which isn't faithful to the original code but we could try to improve it):Additional Context
Do you think this approach is good enough? What other ways we could tackle this?
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.