feat: nargo expand to show code after macro expansions#7613
feat: nargo expand to show code after macro expansions#7613
nargo expand to show code after macro expansions#7613Conversation
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) |
|
This is now ready for review. In most cases it produces code that can be compiled again, and executes like the original program, but in some cases it produces code that can't be compiled. That said, the code is always understandable, which is likely the use case for expanding macro code. We can fix the remaining bugs in subsequent PRs as this PR is already quite large. |
Co-authored-by: Michael J Klein <michaeljklein@users.noreply.github.com>
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE feat: add `--debug-compile-stdin` to read `main.nr` from `STDIN` for testing (noir-lang/noir#8253) feat: better error message on unicode whitespace that isn't ascii whitespace (noir-lang/noir#8295) chore: update `quicksort` from iterative `noir_sort` version (noir-lang/noir#7348) fix: use correct meta attribute names in contract custom attributes (noir-lang/noir#8273) feat: `nargo expand` to show code after macro expansions (noir-lang/noir#7613) feat: allow specifying fuzz-related dirs when invoking `nargo test` (noir-lang/noir#8293) chore: redo typo PR by ciaranightingale (noir-lang/noir#8292) chore: Extend the bug list with issues found by the AST fuzzer (noir-lang/noir#8285) fix: don't disallow writing to memory after passing it to brillig (noir-lang/noir#8276) chore: test against zkpassport rsa lib (noir-lang/noir#8278) feat: omit element size array for more array types (noir-lang/noir#8257) chore: refactor array handling in ACIRgen (noir-lang/noir#8256) chore: document cast (noir-lang/noir#8268) END_COMMIT_OVERRIDE --------- Co-authored-by: AztecBot <tech@aztecprotocol.com> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Description
Problem
Resolves #7552
Summary
By pure coincidence,
nargo expandworks almost the same way ascargo expand:cargo expand)cargo expand)In a follow-up PR we could try to somehow put back comments (we can know where they are and insert them as we traverse the HIR).
For example, if you run it for this code:
we get this output:
Additional Context
Documentation
Check one:
PR Checklist
cargo fmton default settings.