Skip to content
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

feat: Add support for slices of structs and nested slices in brillig #2084

Merged
merged 27 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6884895
Start experiment to merge array and slice types
jfecher Jul 20, 2023
79440f2
Finish merger of slices and arrays
jfecher Jul 21, 2023
22f2ed3
Implement missing try_bind function
jfecher Jul 21, 2023
fca324d
Merge branch 'master' into jf/merge-array-and-slice-types
jfecher Jul 27, 2023
c550dbb
Add missed case for NotConstant
jfecher Jul 27, 2023
d06b69c
Fix some tests
jfecher Jul 27, 2023
a9089fc
Merge branch 'master' into jf/merge-array-and-slice-types
jfecher Jul 27, 2023
eb33561
Fix poseidon test
jfecher Jul 27, 2023
3e366d8
Fix evaluation of slice length
jfecher Jul 27, 2023
fe00354
Fix tests
jfecher Jul 27, 2023
704d9b8
fix: Initialize Value::Array of type Slice
sirasistant Jul 28, 2023
5c10ddb
test: improved brillig test after bug fix
sirasistant Jul 28, 2023
37aefbc
fix: Slice initialization (#2080)
sirasistant Jul 28, 2023
94cb291
feat: nested slices
sirasistant Jul 28, 2023
4b49b56
fix: insert and remove indexes
sirasistant Jul 28, 2023
fc915c3
Merge branch 'jf/merge-array-and-slice-types' into arv/nested_slices
sirasistant Jul 28, 2023
3a3f242
Merge branch 'master' into jf/merge-array-and-slice-types
jfecher Jul 28, 2023
742a55d
fix: add missing deallocation
sirasistant Jul 28, 2023
9f0bc88
Merge branch 'jf/merge-array-and-slice-types' into arv/nested_slices
sirasistant Jul 28, 2023
da0ae19
Merge branch 'master' into arv/nested_slices
sirasistant Jul 28, 2023
c9b37b7
Merge branch 'master' into arv/nested_slices
sirasistant Aug 7, 2023
be7674c
test: added more cases to nested slice test
sirasistant Aug 7, 2023
00b5438
refactor: simplify array length instructions
sirasistant Aug 7, 2023
0cbe9ce
test: fix stale import
sirasistant Aug 7, 2023
a731cba
Merge branch 'master' into arv/nested_slices
sirasistant Aug 7, 2023
2bdda12
refactor: reuse element_size and regen json
sirasistant Aug 7, 2023
d1c9f27
Update crates/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
sirasistant Aug 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "brillig_nested_slices"
type = "bin"
authors = [""]
compiler_version = "0.6.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = "5"
b = "10"
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use dep::std::slice;
use dep::std;

// Tests nested slice passing to/from functions
unconstrained fn push_back_to_slice<T>(slice: [T], item: T) -> [T] {
slice.push_back(item)
}

struct NestedSliceStruct {
id: Field,
arr: [Field]
}

unconstrained fn create_foo(id: Field, value: Field) -> NestedSliceStruct {
let mut arr = [id];
arr = arr.push_back(value);
NestedSliceStruct { id, arr }
}

unconstrained fn main(a: Field, b: Field) {
let mut slice = [create_foo(a, b), create_foo(b, a)];
assert(slice.len() == 2);

assert(slice[0].id == a);
assert(slice[0].arr[0] == a);
assert(slice[1].id == b);
assert(slice[1].arr[1] == a);

slice = push_back_to_slice(slice, create_foo(0, 42));
assert(slice.len() == 3);

assert(slice[0].id == a);
assert(slice[0].arr[0] == a);
assert(slice[1].id == b);
assert(slice[1].arr[1] == a);

assert(slice[2].id == 0);
assert(slice[2].arr[0] == 0);
assert(slice[2].arr[1] == 42);

slice = slice.push_front(create_foo(1, 43));
slice = slice.push_back(create_foo(2, 44));

assert(slice.len() == 5);

let pop_front_result = slice.pop_front();
slice = pop_front_result.1;
assert(pop_front_result.0.id == 1);

let pop_back_result = slice.pop_back();
slice = pop_back_result.0;
assert(pop_back_result.1.id == 2);

assert(slice.len() == 3);

let mut remove_result = slice.remove(0);
slice = remove_result.0;
let mut removed_item = remove_result.1;
assert(removed_item.arr[0] == a);

remove_result = slice.remove(1);
slice = remove_result.0;
removed_item = remove_result.1;
assert(removed_item.arr[0] == 0);

let last_item = slice[0];

assert(last_item.id == b);
slice = slice.insert(1, removed_item);

assert(slice.len() == 2);
assert(slice[0].id == b);
assert(slice[1].id == 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"},{"name":"y","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2]},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/8WcTWwdVxXH53lemvhNkxRSmhA7jtOUhqZx8xybfiRpepsGN/1I46RJE5w4TYrjfOB8tBIrNkjsYYOQ2MAKCYklEhskFqxg0w1igYTEEokFC1ixQMAd5v/e7x1fv1bqPa9XiubMnDP3/z/nnnPPHdtKWRRFq/j/KP/3b6xYP6QPzbX72cZsK99cXU+eY04849jSBHq8iTv5jyfW4RHIIROnR/LHrLsJXLc18qa8GEdifNomPi1zHyBvQgw35+UyN14Mrs0ncdkMLlvycqlzbBxY4iWcCvoSNuN5edT1vcX4r3vy+7Rcxz5nrg64L8Q5Op/gfyfBozNC/4mvZ+3PmUtlODhxmasS2J3RxGEuzvlo5jkVO3EXZ+GU0D/dXLc2dlsTPm/Py6/eux4r+kOY2xH7bY1Mu8fAbRt80VX6GePTF/CefNqR16fZOMfj4CrMHfDpi41Mu8fBTfox+CT9vPHpS3hPPu3M69OROMcucBXmTvj0RCPvAg+P/XMX/BUm+5v0x02cvoz3xC93Psc5J/LOWZ81dheDY9hZYwL+7cnsX8SdwvwBGMTdmxd3lrit5p8w9LyEfKboj72QlQPiHPNiMmFHebd5p4J+0tnnPeARcC+smMsnYTOZ4L0dvKXXvhJzawJzyZdJB18mikFfJgxn9vjdflzqHm+xO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7fBs8Au6FFWvpN/B1FfapXvXNhN0q5pKevUr6j81ZRnHh3u3Rf1fAz+7bJfR/GMFZ5nYivjzLKB9odxv8pedZRvo/OfOPc67lnXOWdah9SPkgrJgrqssCthwBsuaLfO9ljkHEvY/5AzC24/kDhzjdh+8tYOh5CflvCNCDvtjrP+Icc24tYUf5jnmngn7N2ed74BFwL6xYE3/BWWDN2Mtfrk3mnJhN4a6ZmKV8uWO42TWONh8k+HvnVsD9A+A+zItb19KHmD8AgzX2kYO/H8LfFjD0vIT8b9TSR32xt8bi3EG8aEf5nnmngv6Bs88PwSPgXlixlv4BX+/D3tZR9PVbCbv7mEt69irpx5qHOgsoLty7PfrvGvjZfbuEfjP4xf+DzvabbAuj4LSK9H8m+V/w7MsncVIAAA==","proving_key":null,"verification_key":null}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ unconstrained fn main(x: Field, y: Field) {
// Tests slice passing to/from functions
unconstrained fn push_front_to_slice<T>(slice: [T], item: T) -> [T] {
slice.push_front(item)
}
}
Loading