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: set index and value to 0 for array_get with predicate #4971

Merged
merged 14 commits into from
May 7, 2024
9 changes: 8 additions & 1 deletion compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
brillig: &Brillig,
) -> Result<(Vec<GeneratedAcir>, Vec<BrilligBytecode>), RuntimeError> {
let mut acirs = Vec::new();
// TODO: can we parallelise this?

Check warning on line 285 in compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (parallelise)
let mut shared_context = SharedContext::default();
for function in self.functions.values() {
let context = Context::new(&mut shared_context);
Expand Down Expand Up @@ -1200,7 +1200,14 @@
!res_typ.contains_slice_element(),
"ICE: Nested slice result found during ACIR generation"
);
let value = self.array_get_value(&res_typ, block_id, &mut var_index)?;
let mut value = self.array_get_value(&res_typ, block_id, &mut var_index)?;
if let AcirValue::Var(value_var, typ) = value {
guipublic marked this conversation as resolved.
Show resolved Hide resolved
// Set the value to 0 if current_side_effects is 0, to ensure it fits in any value type
value = AcirValue::Var(
self.acir_context.mul_var(value_var, self.current_side_effects_enabled_var)?,
typ,
);
}

self.define_result(dfg, instruction, value.clone());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regression_struct_array_conditional"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
y = 1
z = 1

[[x]]
value = "0x23de33be058ce5504e1ade738db8bdacfe268fa9dbde777092bf1d38519bdf59"
counter = "10"
dummy = "0"

[[x]]
value = "3"
counter = "2"
dummy = "0"

[[x]]
value = "2"
counter = "0"
dummy = "0"

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct foo {
value: Field,
counter: u8,
dummy: u8,
}
fn main(x: [foo; 3], y: u32, z: u32) -> pub u8 {
if z == 0 {
assert(y as u8 < x[y].counter);
}
x[0].counter
}
Loading