Skip to content

feat(debug): Print ssa locations along with ssa#9001

Merged
jfecher merged 8 commits intomasterfrom
jf/ssa-locations
Jun 24, 2025
Merged

feat(debug): Print ssa locations along with ssa#9001
jfecher merged 8 commits intomasterfrom
jf/ssa-locations

Conversation

@jfecher
Copy link
Contributor

@jfecher jfecher commented Jun 23, 2025

Description

Problem*

Resolves #8983

Summary*

Prints the top (last) function in the callstack and the source line along with each SSA instruction to help finding where instructions originate from when printing larger files.

This requires we pass a FileManager when printing SSA now if you want the debug comments. For ease of debugging, you can still print SSA without this though and we just won't print out the source lines.

Additional Context

Before this PR (lambda_from_dynamic_if test):

After Dead Instruction Elimination - ACIR (1) (step 45):
acir(inline) impure fn main f0 {
  b0(v0: u32):
    v2 = eq v0, u32 0
    v3 = not v2
    v5 = eq v0, u32 1
    v6 = unchecked_mul v3, v5
    v7 = not v5 // src/main.nr:12
    v8 = unchecked_mul v3, v7
    v10 = make_array b"!"
    constrain u1 0 == v8, data v10, Field 0
    v13 = cast v6 as Field
    v15 = mul v13, Field 9
    enable_side_effects u1 1
    v17 = cast v2 as Field
    v18 = cast v3 as Field
    v20 = mul v17, Field 8
    v21 = mul v18, v15
    v22 = add v20, v21
    v23 = eq v22, Field 8
    v26 = make_array b"hi"
    enable_side_effects v23
    call f3(u1 1, v26)
    v28 = not v23
    v29 = eq v22, Field 9
    v30 = unchecked_mul v28, v29
    v34 = make_array b"bye"
    enable_side_effects v30
    ...

After this PR:

After Dead Instruction Elimination - ACIR (1) (step 45):
acir(inline) impure fn main f0 {
  b0(v0: u32):
    v2 = eq v0, u32 0                             	// src/main.nr:10
    v3 = not v2                                   	// src/main.nr:10
    v5 = eq v0, u32 1                             	// src/main.nr:12
    v6 = unchecked_mul v3, v5                     	// src/main.nr:12
    v7 = not v5                                   	// src/main.nr:12
    v8 = unchecked_mul v3, v7                     	// src/main.nr:12
    v10 = make_array b"!"                         	// src/main.nr:12
    constrain u1 0 == v8, data v10, Field 0       	// std/panic.nr:2
    v13 = cast v6 as Field
    v15 = mul v13, Field 9
    enable_side_effects u1 1
    v17 = cast v2 as Field
    v18 = cast v3 as Field
    v20 = mul v17, Field 8
    v21 = mul v18, v15
    v22 = add v20, v21
    v23 = eq v22, Field 8                         	// src/main.nr:17
    v26 = make_array b"hi"                        	// std/lib.nr:34
    enable_side_effects v23                       	// src/main.nr:17
    call f3(u1 1, v26)                            	// std/lib.nr:40
    v28 = not v23                                 	// src/main.nr:17
    v29 = eq v22, Field 9                         	// src/main.nr:17
    v30 = unchecked_mul v28, v29                  	// src/main.nr:17
    ...

So now the source file and line is given on the side in a comment after two tab characters. We can also clearly see how the value merger doesn't insert any locations for the instructions it inserts.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@jfecher jfecher requested a review from a team June 23, 2025 20:09
@jfecher
Copy link
Contributor Author

jfecher commented Jun 24, 2025

Adjusted the padding to have a minimum length so the locations are aligned better now

Copy link
Collaborator

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@jfecher jfecher enabled auto-merge June 24, 2025 16:17
@jfecher jfecher added this pull request to the merge queue Jun 24, 2025
Merged via the queue into master with commit 759dc57 Jun 24, 2025
119 checks passed
@jfecher jfecher deleted the jf/ssa-locations branch June 24, 2025 17:01
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 1, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: check both coordinates for point doubling
(noir-lang/noir#9039)
fix: codegen generic type arguments
(noir-lang/noir#9044)
chore: remove accidentally committed files
(noir-lang/noir#9048)
fix(fuzz): enable print in comptime_vs_brillig_direct
(noir-lang/noir#9045)
chore: move a couple of test_utils functions into a module
(noir-lang/noir#9052)
chore: bump external pinned commits
(noir-lang/noir#9046)
fix: put constraint failure after binary operations that overflow
(noir-lang/noir#9023)
fix(ssa): Remove array from cache in constant folding if it's an
argument to a `Call` (noir-lang/noir#9040)
feat: some `nargo expand` fixes related to function and method calls
(noir-lang/noir#9038)
feat(ssa_fuzzer): custom mutations
(noir-lang/noir#8988)
feat: implicit coercion of str and fmtstr into CtString
(noir-lang/noir#9032)
chore: add idempotency check to `remove_unreachable_functions`
(noir-lang/noir#9017)
chore: add logging for signature failure cases which break barretenberg
(noir-lang/noir#9030)
feat(ssa): Handle `println` in the SSA interpreter
(noir-lang/noir#9028)
chore: don't compute used globals during DIE
(noir-lang/noir#9029)
fix(ssa_fuzzer): nested conditions in loops
(noir-lang/noir#8997)
fix(fuzz): Consider `==` turning into `!=` equivalent
(noir-lang/noir#9025)
fix(fuzz): Avoid overflow in `gen_unary`
(noir-lang/noir#9024)
fix(ssa): Perform `mem2reg` before DIE
(noir-lang/noir#9018)
fix: Strange use of predicates in euclidian division
(noir-lang/noir#8934)
fix: compute the dominance frontier of the reverse cfg using the
extended cfg (noir-lang/noir#9019)
fix(fuzz): Handle overflow errors from the elaborator
(noir-lang/noir#9014)
feat: show why an assertion will always fail if it's a static string
(noir-lang/noir#9013)
chore(ssa): Add `SsaPass:and_then`
(noir-lang/noir#9016)
fix: Add a remove_unreachable_instructions SSA pass (with unreachable
terminator) (noir-lang/noir#9008)
feat: `nargo expand` for LSP
(noir-lang/noir#9012)
fix(mem2reg): Add the value in `ArraySet` to `aliased_references`
(noir-lang/noir#8976)
feat(debug): Print ssa locations along with ssa
(noir-lang/noir#9001)
chore: move `nargo expand` code to its own crate
(noir-lang/noir#9011)
chore: redo typo PR by donatik27
(noir-lang/noir#9004)
fix: recover generics when defining trait impl function
(noir-lang/noir#9009)
fix: replace public key with curve generators in inactive branches
(noir-lang/noir#8993)
fix(fuzz): Avoid overflowing binary ops in "no dynamic" mode
(noir-lang/noir#8996)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 2, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore(docs): Brillig VM docs
(noir-lang/noir#9078)
fix(expand): missing struct member visibility, and use "crate" instead
of "super" when possible (noir-lang/noir#9081)
fix: revert #9044 (noir-lang/noir#9080)
chore: error on infinite recursion
(noir-lang/noir#9063)
fix(fuzz): Assign to an index variable to sequence side effects
(noir-lang/noir#9056)
chore: bump cargo deny (noir-lang/noir#9077)
chore: Refactor `ConstrainEqFailed` to have `Option<String>` for `msg`
(noir-lang/noir#9065)
chore(debug): Toggle SSA locations when printing SSA
(noir-lang/noir#9066)
chore(acir_gen): Improve error message for radix decomposition
(noir-lang/noir#9068)
chore(ci): fix upload of benchmark results on master
(noir-lang/noir#9069)
fix: check both coordinates for point doubling
(noir-lang/noir#9039)
fix: codegen generic type arguments
(noir-lang/noir#9044)
chore: remove accidentally committed files
(noir-lang/noir#9048)
fix(fuzz): enable print in comptime_vs_brillig_direct
(noir-lang/noir#9045)
chore: move a couple of test_utils functions into a module
(noir-lang/noir#9052)
chore: bump external pinned commits
(noir-lang/noir#9046)
fix: put constraint failure after binary operations that overflow
(noir-lang/noir#9023)
fix(ssa): Remove array from cache in constant folding if it's an
argument to a `Call` (noir-lang/noir#9040)
feat: some `nargo expand` fixes related to function and method calls
(noir-lang/noir#9038)
feat(ssa_fuzzer): custom mutations
(noir-lang/noir#8988)
feat: implicit coercion of str and fmtstr into CtString
(noir-lang/noir#9032)
chore: add idempotency check to `remove_unreachable_functions`
(noir-lang/noir#9017)
chore: add logging for signature failure cases which break barretenberg
(noir-lang/noir#9030)
feat(ssa): Handle `println` in the SSA interpreter
(noir-lang/noir#9028)
chore: don't compute used globals during DIE
(noir-lang/noir#9029)
fix(ssa_fuzzer): nested conditions in loops
(noir-lang/noir#8997)
fix(fuzz): Consider `==` turning into `!=` equivalent
(noir-lang/noir#9025)
fix(fuzz): Avoid overflow in `gen_unary`
(noir-lang/noir#9024)
fix(ssa): Perform `mem2reg` before DIE
(noir-lang/noir#9018)
fix: Strange use of predicates in euclidian division
(noir-lang/noir#8934)
fix: compute the dominance frontier of the reverse cfg using the
extended cfg (noir-lang/noir#9019)
fix(fuzz): Handle overflow errors from the elaborator
(noir-lang/noir#9014)
feat: show why an assertion will always fail if it's a static string
(noir-lang/noir#9013)
chore(ssa): Add `SsaPass:and_then`
(noir-lang/noir#9016)
fix: Add a remove_unreachable_instructions SSA pass (with unreachable
terminator) (noir-lang/noir#9008)
feat: `nargo expand` for LSP
(noir-lang/noir#9012)
fix(mem2reg): Add the value in `ArraySet` to `aliased_references`
(noir-lang/noir#8976)
feat(debug): Print ssa locations along with ssa
(noir-lang/noir#9001)
chore: move `nargo expand` code to its own crate
(noir-lang/noir#9011)
chore: redo typo PR by donatik27
(noir-lang/noir#9004)
fix: recover generics when defining trait impl function
(noir-lang/noir#9009)
fix: replace public key with curve generators in inactive branches
(noir-lang/noir#8993)
fix(fuzz): Avoid overflowing binary ops in "no dynamic" mode
(noir-lang/noir#8996)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 2, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore(docs): Brillig VM docs
(noir-lang/noir#9078)
fix(expand): missing struct member visibility, and use "crate" instead
of "super" when possible (noir-lang/noir#9081)
fix: revert #9044 (noir-lang/noir#9080)
chore: error on infinite recursion
(noir-lang/noir#9063)
fix(fuzz): Assign to an index variable to sequence side effects
(noir-lang/noir#9056)
chore: bump cargo deny (noir-lang/noir#9077)
chore: Refactor `ConstrainEqFailed` to have `Option<String>` for `msg`
(noir-lang/noir#9065)
chore(debug): Toggle SSA locations when printing SSA
(noir-lang/noir#9066)
chore(acir_gen): Improve error message for radix decomposition
(noir-lang/noir#9068)
chore(ci): fix upload of benchmark results on master
(noir-lang/noir#9069)
fix: check both coordinates for point doubling
(noir-lang/noir#9039)
fix: codegen generic type arguments
(noir-lang/noir#9044)
chore: remove accidentally committed files
(noir-lang/noir#9048)
fix(fuzz): enable print in comptime_vs_brillig_direct
(noir-lang/noir#9045)
chore: move a couple of test_utils functions into a module
(noir-lang/noir#9052)
chore: bump external pinned commits
(noir-lang/noir#9046)
fix: put constraint failure after binary operations that overflow
(noir-lang/noir#9023)
fix(ssa): Remove array from cache in constant folding if it's an
argument to a `Call` (noir-lang/noir#9040)
feat: some `nargo expand` fixes related to function and method calls
(noir-lang/noir#9038)
feat(ssa_fuzzer): custom mutations
(noir-lang/noir#8988)
feat: implicit coercion of str and fmtstr into CtString
(noir-lang/noir#9032)
chore: add idempotency check to `remove_unreachable_functions`
(noir-lang/noir#9017)
chore: add logging for signature failure cases which break barretenberg
(noir-lang/noir#9030)
feat(ssa): Handle `println` in the SSA interpreter
(noir-lang/noir#9028)
chore: don't compute used globals during DIE
(noir-lang/noir#9029)
fix(ssa_fuzzer): nested conditions in loops
(noir-lang/noir#8997)
fix(fuzz): Consider `==` turning into `!=` equivalent
(noir-lang/noir#9025)
fix(fuzz): Avoid overflow in `gen_unary`
(noir-lang/noir#9024)
fix(ssa): Perform `mem2reg` before DIE
(noir-lang/noir#9018)
fix: Strange use of predicates in euclidian division
(noir-lang/noir#8934)
fix: compute the dominance frontier of the reverse cfg using the
extended cfg (noir-lang/noir#9019)
fix(fuzz): Handle overflow errors from the elaborator
(noir-lang/noir#9014)
feat: show why an assertion will always fail if it's a static string
(noir-lang/noir#9013)
chore(ssa): Add `SsaPass:and_then`
(noir-lang/noir#9016)
fix: Add a remove_unreachable_instructions SSA pass (with unreachable
terminator) (noir-lang/noir#9008)
feat: `nargo expand` for LSP
(noir-lang/noir#9012)
fix(mem2reg): Add the value in `ArraySet` to `aliased_references`
(noir-lang/noir#8976)
feat(debug): Print ssa locations along with ssa
(noir-lang/noir#9001)
chore: move `nargo expand` code to its own crate
(noir-lang/noir#9011)
chore: redo typo PR by donatik27
(noir-lang/noir#9004)
fix: recover generics when defining trait impl function
(noir-lang/noir#9009)
fix: replace public key with curve generators in inactive branches
(noir-lang/noir#8993)
fix(fuzz): Avoid overflowing binary ops in "no dynamic" mode
(noir-lang/noir#8996)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
danielntmd pushed a commit to danielntmd/aztec-packages that referenced this pull request Jul 16, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore(docs): Brillig VM docs
(noir-lang/noir#9078)
fix(expand): missing struct member visibility, and use "crate" instead
of "super" when possible (noir-lang/noir#9081)
fix: revert AztecProtocol#9044 (noir-lang/noir#9080)
chore: error on infinite recursion
(noir-lang/noir#9063)
fix(fuzz): Assign to an index variable to sequence side effects
(noir-lang/noir#9056)
chore: bump cargo deny (noir-lang/noir#9077)
chore: Refactor `ConstrainEqFailed` to have `Option<String>` for `msg`
(noir-lang/noir#9065)
chore(debug): Toggle SSA locations when printing SSA
(noir-lang/noir#9066)
chore(acir_gen): Improve error message for radix decomposition
(noir-lang/noir#9068)
chore(ci): fix upload of benchmark results on master
(noir-lang/noir#9069)
fix: check both coordinates for point doubling
(noir-lang/noir#9039)
fix: codegen generic type arguments
(noir-lang/noir#9044)
chore: remove accidentally committed files
(noir-lang/noir#9048)
fix(fuzz): enable print in comptime_vs_brillig_direct
(noir-lang/noir#9045)
chore: move a couple of test_utils functions into a module
(noir-lang/noir#9052)
chore: bump external pinned commits
(noir-lang/noir#9046)
fix: put constraint failure after binary operations that overflow
(noir-lang/noir#9023)
fix(ssa): Remove array from cache in constant folding if it's an
argument to a `Call` (noir-lang/noir#9040)
feat: some `nargo expand` fixes related to function and method calls
(noir-lang/noir#9038)
feat(ssa_fuzzer): custom mutations
(noir-lang/noir#8988)
feat: implicit coercion of str and fmtstr into CtString
(noir-lang/noir#9032)
chore: add idempotency check to `remove_unreachable_functions`
(noir-lang/noir#9017)
chore: add logging for signature failure cases which break barretenberg
(noir-lang/noir#9030)
feat(ssa): Handle `println` in the SSA interpreter
(noir-lang/noir#9028)
chore: don't compute used globals during DIE
(noir-lang/noir#9029)
fix(ssa_fuzzer): nested conditions in loops
(noir-lang/noir#8997)
fix(fuzz): Consider `==` turning into `!=` equivalent
(noir-lang/noir#9025)
fix(fuzz): Avoid overflow in `gen_unary`
(noir-lang/noir#9024)
fix(ssa): Perform `mem2reg` before DIE
(noir-lang/noir#9018)
fix: Strange use of predicates in euclidian division
(noir-lang/noir#8934)
fix: compute the dominance frontier of the reverse cfg using the
extended cfg (noir-lang/noir#9019)
fix(fuzz): Handle overflow errors from the elaborator
(noir-lang/noir#9014)
feat: show why an assertion will always fail if it's a static string
(noir-lang/noir#9013)
chore(ssa): Add `SsaPass:and_then`
(noir-lang/noir#9016)
fix: Add a remove_unreachable_instructions SSA pass (with unreachable
terminator) (noir-lang/noir#9008)
feat: `nargo expand` for LSP
(noir-lang/noir#9012)
fix(mem2reg): Add the value in `ArraySet` to `aliased_references`
(noir-lang/noir#8976)
feat(debug): Print ssa locations along with ssa
(noir-lang/noir#9001)
chore: move `nargo expand` code to its own crate
(noir-lang/noir#9011)
chore: redo typo PR by donatik27
(noir-lang/noir#9004)
fix: recover generics when defining trait impl function
(noir-lang/noir#9009)
fix: replace public key with curve generators in inactive branches
(noir-lang/noir#8993)
fix(fuzz): Avoid overflowing binary ops in "no dynamic" mode
(noir-lang/noir#8996)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
AztecBot added a commit to AztecProtocol/barretenberg that referenced this pull request Dec 3, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore(docs): Brillig VM docs
(noir-lang/noir#9078)
fix(expand): missing struct member visibility, and use "crate" instead
of "super" when possible (noir-lang/noir#9081)
fix: revert #9044 (noir-lang/noir#9080)
chore: error on infinite recursion
(noir-lang/noir#9063)
fix(fuzz): Assign to an index variable to sequence side effects
(noir-lang/noir#9056)
chore: bump cargo deny (noir-lang/noir#9077)
chore: Refactor `ConstrainEqFailed` to have `Option<String>` for `msg`
(noir-lang/noir#9065)
chore(debug): Toggle SSA locations when printing SSA
(noir-lang/noir#9066)
chore(acir_gen): Improve error message for radix decomposition
(noir-lang/noir#9068)
chore(ci): fix upload of benchmark results on master
(noir-lang/noir#9069)
fix: check both coordinates for point doubling
(noir-lang/noir#9039)
fix: codegen generic type arguments
(noir-lang/noir#9044)
chore: remove accidentally committed files
(noir-lang/noir#9048)
fix(fuzz): enable print in comptime_vs_brillig_direct
(noir-lang/noir#9045)
chore: move a couple of test_utils functions into a module
(noir-lang/noir#9052)
chore: bump external pinned commits
(noir-lang/noir#9046)
fix: put constraint failure after binary operations that overflow
(noir-lang/noir#9023)
fix(ssa): Remove array from cache in constant folding if it's an
argument to a `Call` (noir-lang/noir#9040)
feat: some `nargo expand` fixes related to function and method calls
(noir-lang/noir#9038)
feat(ssa_fuzzer): custom mutations
(noir-lang/noir#8988)
feat: implicit coercion of str and fmtstr into CtString
(noir-lang/noir#9032)
chore: add idempotency check to `remove_unreachable_functions`
(noir-lang/noir#9017)
chore: add logging for signature failure cases which break barretenberg
(noir-lang/noir#9030)
feat(ssa): Handle `println` in the SSA interpreter
(noir-lang/noir#9028)
chore: don't compute used globals during DIE
(noir-lang/noir#9029)
fix(ssa_fuzzer): nested conditions in loops
(noir-lang/noir#8997)
fix(fuzz): Consider `==` turning into `!=` equivalent
(noir-lang/noir#9025)
fix(fuzz): Avoid overflow in `gen_unary`
(noir-lang/noir#9024)
fix(ssa): Perform `mem2reg` before DIE
(noir-lang/noir#9018)
fix: Strange use of predicates in euclidian division
(noir-lang/noir#8934)
fix: compute the dominance frontier of the reverse cfg using the
extended cfg (noir-lang/noir#9019)
fix(fuzz): Handle overflow errors from the elaborator
(noir-lang/noir#9014)
feat: show why an assertion will always fail if it's a static string
(noir-lang/noir#9013)
chore(ssa): Add `SsaPass:and_then`
(noir-lang/noir#9016)
fix: Add a remove_unreachable_instructions SSA pass (with unreachable
terminator) (noir-lang/noir#9008)
feat: `nargo expand` for LSP
(noir-lang/noir#9012)
fix(mem2reg): Add the value in `ArraySet` to `aliased_references`
(noir-lang/noir#8976)
feat(debug): Print ssa locations along with ssa
(noir-lang/noir#9001)
chore: move `nargo expand` code to its own crate
(noir-lang/noir#9011)
chore: redo typo PR by donatik27
(noir-lang/noir#9004)
fix: recover generics when defining trait impl function
(noir-lang/noir#9009)
fix: replace public key with curve generators in inactive branches
(noir-lang/noir#8993)
fix(fuzz): Avoid overflowing binary ops in "no dynamic" mode
(noir-lang/noir#8996)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow printing callstack top items along instructions

2 participants