-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(brillig_gen): Return slices from foreign calls (#1909)
* working two foreign calls returning slices * cargo fmt and clippy * regression test for memory overwrite * switch sequence tests to loops * delete commented out code * Update crates/nargo/src/ops/execute.rs Co-authored-by: jfecher <jake@aztecprotocol.com> * Update crates/nargo/src/ops/execute.rs Co-authored-by: jfecher <jake@aztecprotocol.com> * Update crates/nargo/src/ops/execute.rs Co-authored-by: jfecher <jake@aztecprotocol.com> * fixup from suggested changes and cargo clippy * link issues --------- Co-authored-by: jfecher <jake@aztecprotocol.com>
- Loading branch information
Showing
6 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
28 changes: 28 additions & 0 deletions
28
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_oracle/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 |
---|---|---|
@@ -1,23 +1,51 @@ | ||
use dep::std::slice; | ||
|
||
// Tests oracle usage in brillig/unconstrained functions | ||
fn main(x: Field) { | ||
// call through a brillig wrapper | ||
oracle_print_array_wrapper([x, x]); | ||
|
||
// TODO(#1615) Nargo currently only supports resolving one foreign call | ||
// oracle_print_wrapper(x); | ||
|
||
get_number_sequence_wrapper(20); | ||
} | ||
|
||
// TODO(#1911) | ||
#[oracle(oracle_print_impl)] | ||
unconstrained fn oracle_print(_x : Field) -> Field {} | ||
|
||
unconstrained fn oracle_print_wrapper(x: Field) { | ||
oracle_print(x); | ||
} | ||
|
||
// TODO(#1911) | ||
#[oracle(oracle_print_array_impl)] | ||
unconstrained fn oracle_print_array(_arr : [Field; 2]) -> Field {} | ||
|
||
unconstrained fn oracle_print_array_wrapper(arr: [Field; 2]) { | ||
oracle_print_array(arr); | ||
} | ||
|
||
// TODO(#1911): This function does not need to be an oracle but acts | ||
// as a useful test while we finalize code generation for slices in Brillig | ||
#[oracle(get_number_sequence)] | ||
unconstrained fn get_number_sequence(_size: Field) -> [Field] {} | ||
|
||
// TODO(#1911) | ||
#[oracle(get_reverse_number_sequence)] | ||
unconstrained fn get_reverse_number_sequence(_size: Field) -> [Field] {} | ||
|
||
unconstrained fn get_number_sequence_wrapper(size: Field) { | ||
let slice = get_number_sequence(size); | ||
for i in 0..19 as u32 { | ||
assert(slice[i] == i as Field); | ||
} | ||
|
||
let reversed_slice = get_reverse_number_sequence(size); | ||
// Regression test that we have not overwritten memory | ||
for i in 0..19 as u32 { | ||
assert(slice[i] == reversed_slice[19 - i]); | ||
} | ||
} | ||
|
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