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

fix(acir_gen): Nested dynamic array initialization #5810

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 13 additions & 2 deletions compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,9 @@ impl<F: AcirField> AcirContext<F> {
}
Some(optional_value) => {
let mut values = Vec::new();
if let AcirValue::DynamicArray(_) = optional_value {
unreachable!("Dynamic array should already be initialized");
}
self.initialize_array_inner(&mut values, optional_value)?;
values
}
Expand Down Expand Up @@ -1962,8 +1965,16 @@ impl<F: AcirField> AcirContext<F> {
self.initialize_array_inner(witnesses, value)?;
}
}
AcirValue::DynamicArray(_) => {
unreachable!("Dynamic array should already be initialized");
AcirValue::DynamicArray(AcirDynamicArray { block_id, len, .. }) => {
let dynamic_array_values = try_vecmap(0..len, |i| {
let index_var = self.add_constant(i);

let read = self.read_from_memory(block_id, &index_var)?;
Ok::<AcirValue, InternalError>(AcirValue::Var(read, AcirType::field()))
})?;
for value in dynamic_array_values {
self.initialize_array_inner(witnesses, value)?;
}
}
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "nested_dyn_array_regression_5782"
type = "bin"
authors = [""]
compiler_version = ">=0.33.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
array = [5, 10]
i = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main(mut array: [Field; 2], i: u32) {
assert_eq(array[i - 1], 5);
assert_eq(array[i], 10);

array[i] = 2;

let array2 = [array, array];

assert_eq(array2[0][0], 5);
assert_eq(array2[0][i], 2);
assert_eq(array2[i][0], 5);
assert_eq(array2[i][i], 2);
}
Loading