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

fix: Require for all foldable functions to use distinct return #4949

Merged
merged 9 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 6 additions & 9 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
brillig: &Brillig,
) -> Result<(Vec<GeneratedAcir>, Vec<BrilligBytecode>), RuntimeError> {
let mut acirs = Vec::new();
// TODO: can we parallelise this?

Check warning on line 285 in compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (parallelise)
let mut shared_context = SharedContext::default();
for function in self.functions.values() {
let context = Context::new(&mut shared_context);
Expand Down Expand Up @@ -327,13 +327,9 @@
bytecode: brillig.byte_code,
});

// TODO: check whether doing this for a single circuit's return witnesses is correct.
// We probably need it for all foldable circuits, as any circuit being folded is essentially an entry point. However, I do not know how that
// plays a part when we potentially want not inlined functions normally as part of the compiler.
// Also at the moment we specify Distinctness as part of the ABI exclusively rather than the function itself
// so this will need to be updated.
let main_func_acir = &mut acirs[0];
generate_distinct_return_witnesses(main_func_acir);
for acir in acirs.iter_mut() {
generate_distinct_return_witnesses(acir);
}

Ok((acirs, brillig))
}
Expand Down Expand Up @@ -2664,9 +2660,9 @@
#[test]
#[should_panic]
fn basic_calls_no_predicates() {
basic_call_with_outputs_assert(InlineType::NoPredicates);
call_output_as_next_call_input(InlineType::NoPredicates);
basic_nested_call(InlineType::NoPredicates);
basic_call_with_outputs_assert(InlineType::NoPredicates);
}

#[test]
Expand Down Expand Up @@ -2909,9 +2905,10 @@

let func_with_nested_call_acir = &acir_functions[1];
let func_with_nested_call_opcodes = func_with_nested_call_acir.opcodes();

assert_eq!(
func_with_nested_call_opcodes.len(),
2,
3,
"Should have an expression and a call to a nested `foo`"
);
// Should call foo f2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "fold_distinct_return"
type = "bin"
authors = [""]
compiler_version = ">=0.28.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "5"
y = "10"
10 changes: 10 additions & 0 deletions test_programs/execution_success/fold_distinct_return/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main(x: u32, y: pub u32) {
let new_field = new_field_in_array([x, y, 3]);
assert(new_field[0] == 25);
}

#[fold]
fn new_field_in_array(mut input: [u32; 3]) -> [u32; 3] {
input[0] = input[0] + 20;
input
}
1 change: 1 addition & 0 deletions tooling/debugger/ignored-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ fold_numeric_generic_poseidon
no_predicates_basic
no_predicates_numeric_generic_poseidon
regression_4709
fold_distinct_return
fold_fibonacci
Loading