-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nargo): Handle call stacks for multiple Acir calls (#4711)
# Description ## Problem\* Resolves leftover work from #4428 We would error out on calls in non-inlined Acir calls, however, we would only use the debug info from the main function. ## Summary\* There is now a new `ResolvedOpcodeLocation` that wraps an acir function index from the `Program` as well as its opcode location. We then build a call stack during execution that is resolved upon execution failure. Both `ExecutionError` variants now contain a call stack of `ResolvedOpcodeLocation`. For the `fold_basic_nested_call` if I make `assert(x == y)` fail I will get the following now: <img width="811" alt="Screenshot 2024-04-03 at 4 53 17 PM" src="https://github.com/noir-lang/noir/assets/43554004/9c50bec5-4f85-4fe1-93ed-0527f9511f2c"> On master we would get an error in `main` at the first call to `func_with_nested_foo_call`. For the new `test_programs/execution_failure/fold_nested_brillig_assert_fail` test we have this output: <img width="859" alt="Screenshot 2024-04-11 at 9 50 34 AM" src="https://github.com/noir-lang/noir/assets/43554004/58ef8d8f-f67c-477d-9af1-cc1ccd89be5e"> I then also added support for call stacks with dynamic indices in `test_programs/execution_failure/fold_dyn_index_fail`: <img width="774" alt="Screenshot 2024-04-11 at 9 51 16 AM" src="https://github.com/noir-lang/noir/assets/43554004/1066a05a-78db-4c84-83fd-77c17d83cc81"> ## Additional Context ## Documentation\* Check one: - [] No documentation needed. - [ ] Documentation included in this PR. - [X] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: Tom French <[email protected]>
- Loading branch information
1 parent
b46d0e3
commit 5b23171
Showing
27 changed files
with
345 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test_programs/execution_failure/fold_dyn_index_fail/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "fold_dyn_index_fail" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.26.0" | ||
|
||
[dependencies] |
2 changes: 2 additions & 0 deletions
2
test_programs/execution_failure/fold_dyn_index_fail/Prover.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x = [104, 101, 108, 108, 111] | ||
z = "4" |
10 changes: 10 additions & 0 deletions
10
test_programs/execution_failure/fold_dyn_index_fail/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fn main(mut x: [u32; 5], z: Field) { | ||
x[z] = 4; | ||
dynamic_index_check(x, z + 10); | ||
} | ||
|
||
#[fold] | ||
fn dynamic_index_check(x: [u32; 5], idx: Field) { | ||
// Dynamic index is greater than length of the array | ||
assert(x[idx] != 0); | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/execution_failure/fold_nested_brillig_assert_fail/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "fold_nested_brillig_assert_fail" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.26.0" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
test_programs/execution_failure/fold_nested_brillig_assert_fail/Prover.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = "0" |
26 changes: 26 additions & 0 deletions
26
test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Tests a very simple program. | ||
// | ||
// The features being tested is using assert on brillig that is triggered through nested ACIR calls. | ||
// We want to make sure we get a call stack from the original call in main to the failed assert. | ||
fn main(x: Field) { | ||
assert(1 == fold_conditional_wrapper(x as bool)); | ||
} | ||
|
||
#[fold] | ||
fn fold_conditional_wrapper(x: bool) -> Field { | ||
fold_conditional(x) | ||
} | ||
|
||
#[fold] | ||
fn fold_conditional(x: bool) -> Field { | ||
conditional_wrapper(x) | ||
} | ||
|
||
unconstrained fn conditional_wrapper(x: bool) -> Field { | ||
conditional(x) | ||
} | ||
|
||
unconstrained fn conditional(x: bool) -> Field { | ||
assert(x); | ||
1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.