-
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: Allow slices to brillig entry points (#4713)
# Description ## Problem\* Allows passing slices to brillig entry points, since ACIR knows the initial length of the slice and is fixed at compile time. ## Summary\* ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[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.
- Loading branch information
1 parent
68f9eeb
commit 62423d5
Showing
6 changed files
with
139 additions
and
37 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
6 changes: 6 additions & 0 deletions
6
test_programs/execution_success/brillig_slice_input/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,6 @@ | ||
[package] | ||
name = "brillig_slice_input" | ||
type = "bin" | ||
authors = [""] | ||
|
||
[dependencies] |
40 changes: 40 additions & 0 deletions
40
test_programs/execution_success/brillig_slice_input/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 @@ | ||
struct Point { | ||
x: Field, | ||
y: Field, | ||
} | ||
|
||
unconstrained fn sum_slice(slice: [[Point; 2]]) -> Field { | ||
let mut sum = 0; | ||
for i in 0..slice.len() { | ||
for j in 0..slice[i].len() { | ||
sum += slice[i][j].x + slice[i][j].y; | ||
} | ||
} | ||
sum | ||
} | ||
|
||
fn main() { | ||
let mut slice = &[]; | ||
slice = slice.push_back([ | ||
Point { | ||
x: 13, | ||
y: 14, | ||
}, | ||
Point { | ||
x: 20, | ||
y: 8, | ||
} | ||
]); | ||
slice = slice.push_back([ | ||
Point { | ||
x: 15, | ||
y: 5, | ||
}, | ||
Point { | ||
x: 12, | ||
y: 13, | ||
} | ||
]); | ||
let brillig_sum = sum_slice(slice); | ||
assert_eq(brillig_sum, 100); | ||
} |