Skip to content

Commit

Permalink
feat: Sync from aztec-packages (#6634)
Browse files Browse the repository at this point in the history
Co-authored-by: TomAFrench <tom@tomfren.ch>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 28, 2024
1 parent dace078 commit aa143a7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b8bace9a00c3a8eb93f42682e8cbfa351fc5238c
1bfc15e08873a1f0f3743e259f418b70426b3f25
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 12 additions & 24 deletions compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl<'brillig> Context<'brillig> {
block = dominator;
}
}
}
};

let new_results =
// First try to inline a call to a brillig function with all constant arguments.
Expand Down Expand Up @@ -498,7 +498,6 @@ impl<'brillig> Context<'brillig> {
block: BasicBlockId,
) -> Option<CacheResult> {
let results_for_instruction = self.cached_instruction_results.get(instruction)?;

let predicate = self.use_constraint_info && instruction.requires_acir_gen_predicate(dfg);
let predicate = predicate.then_some(side_effects_enabled_var);

Expand Down Expand Up @@ -1004,32 +1003,22 @@ mod test {
// Regression for #4600
#[test]
fn array_get_regression() {
// fn main f0 {
// b0(v0: u1, v1: u64):
// enable_side_effects_if v0
// v2 = make_array [Field 0, Field 1]
// v3 = array_get v2, index v1
// v4 = not v0
// enable_side_effects_if v4
// v5 = array_get v2, index v1
// }
//
// We want to make sure after constant folding both array_gets remain since they are
// under different enable_side_effects_if contexts and thus one may be disabled while
// the other is not. If one is removed, it is possible e.g. v4 is replaced with v2 which
// is disabled (only gets from index 0) and thus returns the wrong result.
let src = "
acir(inline) fn main f0 {
b0(v0: u1, v1: u64):
enable_side_effects v0
v4 = make_array [Field 0, Field 1] : [Field; 2]
v5 = array_get v4, index v1 -> Field
v6 = not v0
enable_side_effects v6
v7 = array_get v4, index v1 -> Field
return
}
";
acir(inline) fn main f0 {
b0(v0: u1, v1: u64):
enable_side_effects v0
v4 = make_array [Field 0, Field 1] : [Field; 2]
v5 = array_get v4, index v1 -> Field
v6 = not v0
enable_side_effects v6
v7 = array_get v4, index v1 -> Field
return
}
";
let ssa = Ssa::from_str(src).unwrap();

// Expected output is unchanged
Expand Down Expand Up @@ -1096,7 +1085,6 @@ mod test {
// v5 = call keccakf1600(v1)
// v6 = call keccakf1600(v2)
// }
//
// Here we're checking a situation where two identical arrays are being initialized twice and being assigned separate `ValueId`s.
// This would result in otherwise identical instructions not being deduplicated.
let main_id = Id::test_new(0);
Expand Down
6 changes: 1 addition & 5 deletions compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ impl<'f> Context<'f> {
// If this is not a separate variable, clippy gets confused and says the to_vec is
// unnecessary, when removing it actually causes an aliasing/mutability error.
let instructions = self.inserter.function.dfg[block].instructions().to_vec();

for instruction in instructions.iter() {
if self.is_no_predicate(no_predicates, instruction) {
// disable side effect for no_predicate functions
Expand Down Expand Up @@ -637,10 +636,6 @@ impl<'f> Context<'f> {

/// If we are currently in a branch, we need to modify constrain instructions
/// to multiply them by the branch's condition (see optimization #1 in the module comment).
///
/// `previous_allocate_result` should only be set to the result of an allocate instruction
/// if that instruction was the instruction immediately previous to this one - if there are
/// any instructions in between it should be None.
fn handle_instruction_side_effects(
&mut self,
instruction: Instruction,
Expand Down Expand Up @@ -1282,6 +1277,7 @@ mod test {
fn should_not_merge_incorrectly_to_false() {
// Regression test for #1792
// Tests that it does not simplify a true constraint an always-false constraint

let src = "
acir(inline) fn main f0 {
b0(v0: [u8; 2]):
Expand Down

0 comments on commit aa143a7

Please sign in to comment.