Skip to content

Commit 80f7e29

Browse files
michaeljkleinjfecher
andauthored
feat: add option to print monomorphized program (#4119)
# Description Debugging optimizations often requires inspecting the monomorphized program. This adds an option to enable this. ## Problem\* #4067 ## Summary\* Example usage: ```bash ❯ (cd test_programs/compile_success_contract/simple_contract && cargo run compile --show-monomorphized) Compiling nargo_cli v0.23.0 (/Users/michaelklein/Coding/rust/noir/tooling/nargo_cli) Finished dev [optimized + debuginfo] target(s) in 1.79s Running `/Users/michaelklein/Coding/rust/noir/target/debug/nargo compile --show-monomorphized` Monomorphized AST for program with hash: 18020856208726922572 fn triple$f0(x$l0: Field) -> Field { (x$l0 * 3) } Monomorphized AST for program with hash: 9305131916264092540 fn skibbidy$f0(x$l0: Field) -> Field { (x$l0 * 5) } Monomorphized AST for program with hash: 17799031513160233728 fn double$f0(x$l0: Field) -> Field { (x$l0 * 2) } Monomorphized AST for program with hash: 16417890415031598568 fn quadruple$f0(x$l0: Field) -> Field { (x$l0 * 4) } ``` ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. (hidden option) - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: jfecher <[email protected]>
1 parent 4738beb commit 80f7e29

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

  • compiler/noirc_driver/src

compiler/noirc_driver/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub struct CompileOptions {
7575
/// Disables the builtin macros being used in the compiler
7676
#[arg(long, hide = true)]
7777
pub disable_macros: bool,
78+
79+
/// Outputs the monomorphized IR to stdout for debugging
80+
#[arg(long, hide = true)]
81+
pub show_monomorphized: bool,
7882
}
7983

8084
/// Helper type used to signify where only warnings are expected in file diagnostics
@@ -391,6 +395,9 @@ pub fn compile_no_check(
391395

392396
let hash = fxhash::hash64(&program);
393397
let hashes_match = cached_program.as_ref().map_or(false, |program| program.hash == hash);
398+
if options.show_monomorphized {
399+
println!("{program}");
400+
}
394401

395402
// If user has specified that they want to see intermediate steps printed then we should
396403
// force compilation even if the program hasn't changed.

0 commit comments

Comments
 (0)