-
Notifications
You must be signed in to change notification settings - Fork 381
feat: add as_slice builtin function, add execution test #4523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d986bfc
add as_slice builtin function, add execution test
michaeljklein 462af64
wip debugging test failures, add dynamic array case to test
michaeljklein 2b749e1
wip debugging error on valid index of result of as_slice
michaeljklein 3da8474
update can_omit_element_sizes_array
vezenovm 197fd77
remove dbg calls and cleanup, add brillig implementation for AsSlice,…
michaeljklein a5f7d9e
wip debugging brillig as_slice implementation, rewrote implementation…
michaeljklein e8637a5
wip debugging brillig slice access error, fixed wrong initialization …
michaeljklein efa81db
wip debugging: cleanup for second pair of eyes
michaeljklein 84cfbc3
got brillig tests passing using version of convert_ssa_array_set, cle…
michaeljklein c29add0
remove debugging return
michaeljklein 5be64bd
Merge branch 'master' into michaeljklein/as-slice-builtin
michaeljklein fecda34
cargo clippy / fmt
michaeljklein b6feea0
fix destination length init in brillig as_slice implementation, split…
michaeljklein e940103
Merge branch 'master' into michaeljklein/as-slice-builtin
michaeljklein 269bdda
combine convert_ssa_as_slice with convert_ssa_array_set to pull in re…
michaeljklein e5da158
Merge branch 'master' into michaeljklein/as-slice-builtin
michaeljklein f66772b
move as_slice logic out of convert_ssa_array_set
michaeljklein 214229e
Merge branch 'master' into michaeljklein/as-slice-builtin
michaeljklein 10d97e6
Merge branch 'master' into michaeljklein/as-slice-builtin
michaeljklein e938872
Merge branch 'master' into michaeljklein/as-slice-builtin
michaeljklein 27ff4f0
Merge branch 'master' into michaeljklein/as-slice-builtin
michaeljklein 0f33218
remove method string from ssa generation function (panic will unwind …
michaeljklein fe6156d
Merge branch 'master' into michaeljklein/as-slice-builtin
michaeljklein c1ec91f
Update compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
michaeljklein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 = "array_to_slice" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=0.24.0" | ||
|
|
||
| [dependencies] |
This file contains hidden or 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 = "0" | ||
| y = "1" |
33 changes: 33 additions & 0 deletions
33
test_programs/execution_success/array_to_slice/src/main.nr
This file contains hidden or 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,33 @@ | ||
| // Converts an array into a slice. | ||
| fn as_slice_push<T, N>(xs: [T; N]) -> [T] { | ||
| let mut slice = []; | ||
| for elem in xs { | ||
| slice = slice.push_back(elem); | ||
| } | ||
| slice | ||
| } | ||
|
|
||
| fn main(x: Field, y: pub Field) { | ||
michaeljklein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let xs: [Field; 0] = []; | ||
| let ys: [Field; 1] = [1]; | ||
| let zs: [Field; 2] = [1, 2]; | ||
| let ws: [Field; 3] = [1; 3]; | ||
| let qs: [Field; 4] = [3, 2, 1, 0]; | ||
|
|
||
| let mut dynamic: [Field; 4] = [3, 2, 1, 0]; | ||
| let dynamic_expected: [Field; 4] = [1000, 2, 1, 0]; | ||
| dynamic[x] = 1000; | ||
|
|
||
| assert(x != y); | ||
| assert(xs.as_slice() == as_slice_push(xs)); | ||
| assert(ys.as_slice() == as_slice_push(ys)); | ||
| assert(zs.as_slice() == as_slice_push(zs)); | ||
| assert(ws.as_slice() == as_slice_push(ws)); | ||
| assert(qs.as_slice() == as_slice_push(qs)); | ||
|
|
||
| assert(dynamic.as_slice()[0] == dynamic_expected[0]); | ||
| assert(dynamic.as_slice()[1] == dynamic_expected[1]); | ||
| assert(dynamic.as_slice()[2] == dynamic_expected[2]); | ||
| assert(dynamic.as_slice()[3] == dynamic_expected[3]); | ||
| assert(dynamic.as_slice().len() == 4); | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
test_programs/execution_success/brillig_array_to_slice/Nargo.toml
This file contains hidden or 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 = "brillig_array_to_slice" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=0.25.0" | ||
|
|
||
| [dependencies] |
1 change: 1 addition & 0 deletions
1
test_programs/execution_success/brillig_array_to_slice/Prover.toml
This file contains hidden or 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" |
18 changes: 18 additions & 0 deletions
18
test_programs/execution_success/brillig_array_to_slice/src/main.nr
This file contains hidden or 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,18 @@ | ||
| unconstrained fn brillig_as_slice(x: Field) -> (u64, Field, Field) { | ||
| let mut dynamic: [Field; 1] = [1]; | ||
| dynamic[x] = 2; | ||
| assert(dynamic[0] == 2); | ||
|
|
||
| let brillig_slice = dynamic.as_slice(); | ||
| assert(brillig_slice.len() == 1); | ||
|
|
||
| (brillig_slice.len(), dynamic[0], brillig_slice[0]) | ||
| } | ||
|
|
||
| fn main(x: Field) { | ||
| let (slice_len, dynamic_0, slice_0) = brillig_as_slice(x); | ||
| assert(slice_len == 1); | ||
| assert(dynamic_0 == 2); | ||
| assert(slice_0 == 2); | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.