From 9be3fb81e71acb8c5f64d9a67dc9ec027feebf9a Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 17 Jan 2025 20:55:09 +0000 Subject: [PATCH] fix: avoid creating unnecessary memory blocks --- compiler/noirc_evaluator/src/acir/mod.rs | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/compiler/noirc_evaluator/src/acir/mod.rs b/compiler/noirc_evaluator/src/acir/mod.rs index b573b7136f..26e205ff8b 100644 --- a/compiler/noirc_evaluator/src/acir/mod.rs +++ b/compiler/noirc_evaluator/src/acir/mod.rs @@ -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 { .. }))); + } }