-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
array_refcount
and slice_refcount
builtins for debugging (
- Loading branch information
Showing
16 changed files
with
363 additions
and
196 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
427 changes: 234 additions & 193 deletions
427
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,7 @@ | |
"quantile", | ||
"quasiquote", | ||
"rangemap", | ||
"refcount", | ||
"repr", | ||
"reqwest", | ||
"rfind", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "reference_counts" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.35.0" | ||
|
||
[dependencies] |
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 = 5 | ||
b = true |
40 changes: 40 additions & 0 deletions
40
test_programs/execution_success/reference_counts/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,40 @@ | ||
fn main() { | ||
let mut array = [0, 1, 2]; | ||
assert_refcount(array, 1); | ||
|
||
borrow(array, std::mem::array_refcount(array)); | ||
borrow_mut(&mut array, std::mem::array_refcount(array)); | ||
copy_mut(array, std::mem::array_refcount(array)); | ||
} | ||
|
||
fn borrow(array: [Field; 3], rc_before_call: u32) { | ||
assert_refcount(array, rc_before_call); | ||
println(array[0]); | ||
} | ||
|
||
fn borrow_mut(array: &mut [Field; 3], rc_before_call: u32) { | ||
assert_refcount(*array, rc_before_call + 0); // Issue! This should be rc_before_call + 1 | ||
array[0] = 5; | ||
println(array[0]); | ||
} | ||
|
||
fn copy_mut(mut array: [Field; 3], rc_before_call: u32) { | ||
assert_refcount(array, rc_before_call + 0); // Issue! This should be rc_before_call + 1 | ||
array[0] = 6; | ||
println(array[0]); | ||
} | ||
|
||
fn assert_refcount(array: [Field; 3], expected: u32) { | ||
let count = std::mem::array_refcount(array); | ||
|
||
// All refcounts are zero when running this as a constrained program | ||
if std::runtime::is_unconstrained() { | ||
if count != expected { | ||
// Brillig doesn't print the actual & expected arguments on assertion failure | ||
println(f"actual = {count}, expected = {expected}"); | ||
} | ||
assert_eq(count, expected); | ||
} else { | ||
assert_eq(count, 0); | ||
} | ||
} |
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