Skip to content

Commit

Permalink
fix: avoid creating unnecessary memory blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jan 17, 2025
1 parent 82cb900 commit 9be3fb8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions compiler/noirc_evaluator/src/acir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3709,4 +3709,38 @@ mod test {
}
}
}

#[test]
fn does_not_generate_memory_blocks_without_dynamic_accesses() {
let src = "
acir(inline) fn main f0 {
b0(v0: [Field; 2]):
v2, v3 = call as_slice(v0) -> (u32, [Field])
call f1(u32 2, v3)
v7 = array_get v0, index u32 0 -> Field
constrain v7 == Field 0
return
}
brillig(inline) fn foo f1 {
b0(v0: u32, v1: [Field]):
return
}
";
let ssa = Ssa::from_str(src).unwrap();
let brillig = ssa.to_brillig(false);

let (acir_functions, _brillig_functions, _, _) = ssa
.into_acir(&brillig, ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

assert_eq!(acir_functions.len(), 1);

// Check that no memory opcodes were emitted.
let main = &acir_functions[0];
assert!(!main
.opcodes()
.iter()
.any(|opcode| matches!(opcode, Opcode::MemoryInit { .. } | Opcode::MemoryOp { .. })));
}
}

0 comments on commit 9be3fb8

Please sign in to comment.