Skip to content

Commit

Permalink
feat: add option to print monomorphized program (#4119)
Browse files Browse the repository at this point in the history
# 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 <jake@aztecprotocol.com>
  • Loading branch information
michaeljklein and jfecher authored Jan 22, 2024
1 parent 4738beb commit 80f7e29
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub struct CompileOptions {
/// Disables the builtin macros being used in the compiler
#[arg(long, hide = true)]
pub disable_macros: bool,

/// Outputs the monomorphized IR to stdout for debugging
#[arg(long, hide = true)]
pub show_monomorphized: bool,
}

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

let hash = fxhash::hash64(&program);
let hashes_match = cached_program.as_ref().map_or(false, |program| program.hash == hash);
if options.show_monomorphized {
println!("{program}");
}

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

0 comments on commit 80f7e29

Please sign in to comment.