Skip to content

Commit

Permalink
chore: Initialize copy array from previous values in array_set (#2106)
Browse files Browse the repository at this point in the history
* Initialize copy array from previous values in array_set

* chore: use `try_vecmap` in place of for-loop

* Update crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs

* Update crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs

---------

Co-authored-by: Tom French <[email protected]>
Co-authored-by: jfecher <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2023
1 parent a07b8a4 commit ed67b10
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions crates/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,17 @@ impl Context {
let result_array_id = result_id.to_usize() as u32;
let result_block_id = BlockId(result_array_id);

// Initialize the new array with zero values
self.initialize_array(result_block_id, len, None)?;

// Copy the values from the old array into the newly created zeroed array
for i in 0..len {
// Initialize the new array with the values from the old array
let init_values = try_vecmap(0..len, |i| {
let index = AcirValue::Var(
self.acir_context.add_constant(FieldElement::from(i as u128)),
AcirType::NumericType(NumericType::NativeField),
);
let var = index.into_var()?;
let read = self.acir_context.read_from_memory(block_id, &var)?;
self.acir_context.write_to_memory(result_block_id, &var, &read)?;
}
Ok(AcirValue::Var(read, AcirType::NumericType(NumericType::NativeField)))
})?;
self.initialize_array(result_block_id, len, Some(&init_values))?;

// Write the new value into the new array at the specified index
let index_var = self.convert_value(index, dfg).into_var()?;
Expand Down

0 comments on commit ed67b10

Please sign in to comment.