Skip to content

Commit

Permalink
chore: borrow instead of cloning witness vectors in IR gen (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Apr 10, 2023
1 parent 61c38d2 commit daf5c9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
8 changes: 4 additions & 4 deletions crates/noirc_evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand Down Expand Up @@ -203,13 +203,13 @@ impl Evaluator {
let mut struct_witnesses: BTreeMap<String, Vec<Witness>> = 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
}
};
Expand Down
20 changes: 7 additions & 13 deletions crates/noirc_evaluator/src/ssa/ssa_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -98,7 +98,7 @@ impl IrGenerator {
ident_def: Option<Definition>,
el_type: &noirc_abi::AbiType,
len: u64,
witness: Vec<acvm::acir::native_types::Witness>,
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);
Expand All @@ -125,30 +125,24 @@ impl IrGenerator {
struct_name: &str,
ident_def: Option<Definition>,
fields: &BTreeMap<String, noirc_abi::AbiType>,
witnesses: BTreeMap<String, Vec<acvm::acir::native_types::Witness>>,
witnesses: &BTreeMap<String, Vec<Witness>>,
) -> 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)
}
_ => {
Expand Down

0 comments on commit daf5c9d

Please sign in to comment.