-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation of slices in brillig (#1932)
* feat: get push/pop working * feat: get all slice operations working * chore: remove printing of initial ssa * chore: remove print * refactor: use memory op * feat: implement array_set for slices * Update crates/nargo_cli/tests/test_data_ssa_refactor/brillig_slices/src/main.nr * test: added unit testing for slice ops
- Loading branch information
1 parent
cfb1765
commit ea47936
Showing
9 changed files
with
1,456 additions
and
237 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_slices/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.6.0" | ||
|
||
[dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_slices/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 = "5" | ||
y = "10" |
72 changes: 72 additions & 0 deletions
72
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_slices/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,72 @@ | ||
use dep::std::slice; | ||
use dep::std; | ||
|
||
unconstrained fn main(x: Field, y: Field) { | ||
// Mark it as mut so the compiler doesn't simplify the following operations | ||
// But don't reuse the mut slice variable until this is fixed https://github.com/noir-lang/noir/issues/1931 | ||
let slice: [Field] = [y, x]; | ||
assert(slice.len() == 2); | ||
|
||
let mut pushed_back_slice = slice.push_back(7); | ||
assert(pushed_back_slice.len() == 3); | ||
assert(pushed_back_slice[0] == y); | ||
assert(pushed_back_slice[1] == x); | ||
assert(pushed_back_slice[2] == 7); | ||
|
||
// Array set on slice target | ||
pushed_back_slice[0] = x; | ||
pushed_back_slice[1] = y; | ||
pushed_back_slice[2] = 1; | ||
|
||
assert(pushed_back_slice[0] == x); | ||
assert(pushed_back_slice[1] == y); | ||
assert(pushed_back_slice[2] == 1); | ||
|
||
assert(slice.len() == 2); | ||
|
||
let pushed_front_slice = pushed_back_slice.push_front(2); | ||
assert(pushed_front_slice.len() == 4); | ||
assert(pushed_front_slice[0] == 2); | ||
assert(pushed_front_slice[1] == x); | ||
assert(pushed_front_slice[2] == y); | ||
assert(pushed_front_slice[3] == 1); | ||
|
||
let (item, popped_front_slice) = pushed_front_slice.pop_front(); | ||
assert(item == 2); | ||
|
||
assert(popped_front_slice.len() == 3); | ||
assert(popped_front_slice[0] == x); | ||
assert(popped_front_slice[1] == y); | ||
assert(popped_front_slice[2] == 1); | ||
|
||
let (popped_back_slice, another_item) = popped_front_slice.pop_back(); | ||
assert(another_item == 1); | ||
|
||
assert(popped_back_slice.len() == 2); | ||
assert(popped_back_slice[0] == x); | ||
assert(popped_back_slice[1] == y); | ||
|
||
let inserted_slice = popped_back_slice.insert(1, 2); | ||
assert(inserted_slice.len() == 3); | ||
assert(inserted_slice[0] == x); | ||
assert(inserted_slice[1] == 2); | ||
assert(inserted_slice[2] == y); | ||
|
||
let (removed_slice, should_be_2) = inserted_slice.remove(1); | ||
assert(should_be_2 == 2); | ||
|
||
assert(removed_slice.len() == 2); | ||
assert(removed_slice[0] == x); | ||
assert(removed_slice[1] == y); | ||
|
||
let (slice_with_only_x, should_be_y) = removed_slice.remove(1); | ||
assert(should_be_y == y); | ||
|
||
assert(slice_with_only_x.len() == 1); | ||
assert(removed_slice[0] == x); | ||
|
||
let (empty_slice, should_be_x) = slice_with_only_x.remove(0); | ||
assert(should_be_x == x); | ||
assert(empty_slice.len() == 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
554 changes: 408 additions & 146 deletions
554
crates/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
Oops, something went wrong.