Skip to content

Commit

Permalink
improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vezenovm committed Feb 1, 2024
1 parent dfe904e commit a3b79c5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ impl Context {
AcirValue::Array(array.update(index, store_value))
}
None => {
// If the index is out of range for a slice we should directly create dummy data.
// This situation should only happen during flattening of slices when the same slice after an if statement
// would have different lengths depending upon the predicate.
// Otherwise, we can potentially hit an index out of bounds error.
if index >= array_size {
self.construct_dummy_slice_value(instruction, dfg)
} else {
Expand All @@ -730,9 +734,10 @@ impl Context {
self.define_result(dfg, instruction, array[index].clone());
return Ok(true);
}
// If there is a non constant predicate and the index is out of range for a slice we should still directly create dummy data
// These situations should only happen during flattening of slices when the same slice after an if statement
// would have different lengths depending upon the condition
// If there is a non constant predicate and the index is out of range for a slice, we should directly create dummy data.
// This situation should only happen during flattening of slices when the same slice after an if statement
// would have different lengths depending upon the predicate.
// Otherwise, we can potentially hit an index out of bounds error.
else if index >= array_size
&& value_type.contains_slice_element()
&& store_value.is_none()
Expand Down Expand Up @@ -784,10 +789,10 @@ impl Context {
) -> AcirValue {
let results = dfg.instruction_results(instruction);
let res_typ = dfg.type_of_value(results[0]);
self.construct_dummy_array_value(&res_typ)
self.construct_dummy_slice_value_inner(&res_typ)
}

fn construct_dummy_array_value(&mut self, ssa_type: &Type) -> AcirValue {
fn construct_dummy_slice_value_inner(&mut self, ssa_type: &Type) -> AcirValue {
match ssa_type.clone() {
Type::Numeric(numeric_type) => {
let zero = self.acir_context.add_constant(FieldElement::zero());
Expand All @@ -798,7 +803,7 @@ impl Context {
let mut values = Vector::new();
for _ in 0..len {
for typ in element_types.as_ref() {
values.push_back(self.construct_dummy_array_value(typ));
values.push_back(self.construct_dummy_slice_value_inner(typ));
}
}
AcirValue::Array(values)
Expand Down

0 comments on commit a3b79c5

Please sign in to comment.