-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement references in brillig (#1901)
* fix: fix bug in register restores * feat: implement references in brillig
- Loading branch information
1 parent
f3800c5
commit 3a078fb
Showing
10 changed files
with
158 additions
and
25 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
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_references/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,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.5.1" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_references/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 = "2" |
58 changes: 58 additions & 0 deletions
58
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_references/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,58 @@ | ||
unconstrained fn main(mut x: Field) { | ||
add1(&mut x); | ||
assert(x == 3); | ||
|
||
// https://github.com/noir-lang/noir/issues/1899 | ||
// let mut s = S { y: x }; | ||
// s.add2(); | ||
// assert(s.y == 5); | ||
|
||
// Test that normal mutable variables are still copied | ||
let mut a = 0; | ||
mutate_copy(a); | ||
assert(a == 0); | ||
|
||
// Test something 3 allocations deep | ||
let mut nested_allocations = Nested { y: &mut &mut 0 }; | ||
add1(*nested_allocations.y); | ||
assert(**nested_allocations.y == 1); | ||
|
||
// Test nested struct allocations with a mutable reference to an array. | ||
let mut c = C { | ||
foo: 0, | ||
bar: &mut C2 { | ||
array: &mut [1, 2], | ||
}, | ||
}; | ||
*c.bar.array = [3, 4]; | ||
let arr: [Field; 2] = *c.bar.array; | ||
assert(arr[0] == 3); | ||
assert(arr[1] == 4); | ||
} | ||
|
||
unconstrained fn add1(x: &mut Field) { | ||
*x += 1; | ||
} | ||
|
||
struct S { y: Field } | ||
|
||
struct Nested { y: &mut &mut Field } | ||
|
||
struct C { | ||
foo: Field, | ||
bar: &mut C2, | ||
} | ||
|
||
struct C2 { | ||
array: &mut [Field; 2] | ||
} | ||
|
||
impl S { | ||
unconstrained fn add2(&mut self) { | ||
self.y += 2; | ||
} | ||
} | ||
|
||
unconstrained fn mutate_copy(mut a: Field) { | ||
a = 7; | ||
} |
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 = "2" |
10 changes: 5 additions & 5 deletions
10
crates/nargo_cli/tests/test_data_ssa_refactor/references/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
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
Why was this changed to a parameter?
Was it only to show #1899 or was there another reason?