Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Initialize copy array from previous values in array_set #2106

Merged
merged 5 commits into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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