From e3673f8b14527453d4a2342c4ce4aced3759d7a4 Mon Sep 17 00:00:00 2001 From: Tom French Date: Sat, 8 Apr 2023 12:28:11 +0100 Subject: [PATCH] chore: borrow instead of cloning witness vectors in IR gen --- crates/noirc_evaluator/src/lib.rs | 8 ++++---- crates/noirc_evaluator/src/ssa/ssa_gen.rs | 20 +++++++------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/crates/noirc_evaluator/src/lib.rs b/crates/noirc_evaluator/src/lib.rs index 3880a32fd99..9656c3cdb9f 100644 --- a/crates/noirc_evaluator/src/lib.rs +++ b/crates/noirc_evaluator/src/lib.rs @@ -175,7 +175,7 @@ impl Evaluator { AbiType::Array { length, typ } => { let witnesses = self.generate_array_witnesses(length, typ)?; - ir_gen.abi_array(name, Some(def), typ.as_ref(), *length, witnesses.clone()); + ir_gen.abi_array(name, Some(def), typ.as_ref(), *length, &witnesses); witnesses } AbiType::Integer { sign: _, width } => { @@ -203,13 +203,13 @@ impl Evaluator { let mut struct_witnesses: BTreeMap> = BTreeMap::new(); self.generate_struct_witnesses(&mut struct_witnesses, &new_fields)?; - ir_gen.abi_struct(name, Some(def), fields, struct_witnesses.clone()); - struct_witnesses.values().flatten().cloned().collect() + ir_gen.abi_struct(name, Some(def), fields, &struct_witnesses); + struct_witnesses.values().flatten().copied().collect() } AbiType::String { length } => { let typ = AbiType::Integer { sign: noirc_abi::Sign::Unsigned, width: 8 }; let witnesses = self.generate_array_witnesses(length, &typ)?; - ir_gen.abi_array(name, Some(def), &typ, *length, witnesses.clone()); + ir_gen.abi_array(name, Some(def), &typ, *length, &witnesses); witnesses } }; diff --git a/crates/noirc_evaluator/src/ssa/ssa_gen.rs b/crates/noirc_evaluator/src/ssa/ssa_gen.rs index e819d83f55d..8205dc8e10c 100644 --- a/crates/noirc_evaluator/src/ssa/ssa_gen.rs +++ b/crates/noirc_evaluator/src/ssa/ssa_gen.rs @@ -10,7 +10,7 @@ use crate::{ {block, builtin, node, ssa_form}, }, }; -use acvm::FieldElement; +use acvm::{acir::native_types::Witness, FieldElement}; use iter_extended::vecmap; use noirc_errors::Location; use noirc_frontend::{ @@ -98,7 +98,7 @@ impl IrGenerator { ident_def: Option, el_type: &noirc_abi::AbiType, len: u64, - witness: Vec, + witness: &[Witness], ) -> NodeId { let element_type = self.get_object_type_from_abi(el_type); let (v_id, array_idx) = self.new_array(name, element_type, len as u32, ident_def); @@ -125,30 +125,24 @@ impl IrGenerator { struct_name: &str, ident_def: Option, fields: &BTreeMap, - witnesses: BTreeMap>, + witnesses: &BTreeMap>, ) -> Value { let values = vecmap(fields, |(name, field_typ)| { let new_name = format!("{struct_name}.{name}"); match field_typ { noirc_abi::AbiType::Array { length, typ } => { - let v_id = - self.abi_array(&new_name, None, typ, *length, witnesses[&new_name].clone()); + let v_id = self.abi_array(&new_name, None, typ, *length, &witnesses[&new_name]); Value::Node(v_id) } noirc_abi::AbiType::Struct { fields, .. } => { let new_name = format!("{struct_name}.{name}"); - self.abi_struct(&new_name, None, fields, witnesses.clone()) + self.abi_struct(&new_name, None, fields, witnesses) } noirc_abi::AbiType::String { length } => { let typ = noirc_abi::AbiType::Integer { sign: noirc_abi::Sign::Unsigned, width: 8 }; - let v_id = self.abi_array( - &new_name, - None, - &typ, - *length, - witnesses[&new_name].clone(), - ); + let v_id = + self.abi_array(&new_name, None, &typ, *length, &witnesses[&new_name]); Value::Node(v_id) } _ => {