Skip to content

Commit

Permalink
remove first_elem param
Browse files Browse the repository at this point in the history
  • Loading branch information
vezenovm committed Sep 21, 2023
1 parent 05f35c6 commit f2dd702
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,8 @@ impl Context {

let mut dummy_predicate_index = predicate_index;
// We must setup the dummy value to match the type of the value we wish to store
let mut is_first_elem = true;
let dummy = self.array_get_value(
&store_type,
block_id,
&mut dummy_predicate_index,
&mut is_first_elem,
)?;
let dummy =
self.array_get_value(&store_type, block_id, &mut dummy_predicate_index)?;

Some(self.convert_array_set_store_value(&store_value, &dummy)?)
}
Expand Down Expand Up @@ -788,8 +783,7 @@ impl Context {
let results = dfg.instruction_results(instruction);
let res_typ = dfg.type_of_value(results[0]);

let mut first_elem = true;
let value = self.array_get_value(&res_typ, block_id, &mut var_index, &mut first_elem)?;
let value = self.array_get_value(&res_typ, block_id, &mut var_index)?;

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

Expand All @@ -801,26 +795,24 @@ impl Context {
ssa_type: &Type,
block_id: BlockId,
var_index: &mut AcirVar,
first_elem: &mut bool,
) -> Result<AcirValue, RuntimeError> {
let one = self.acir_context.add_constant(FieldElement::one());
match ssa_type.clone() {
Type::Numeric(numeric_type) => {
if !*first_elem {
*var_index = self.acir_context.add_var(*var_index, one)?;
}
*first_elem = false;

// Read the value from the array at the specified index
let read = self.acir_context.read_from_memory(block_id, var_index)?;

// Incremement the var_index in case of a nested array
*var_index = self.acir_context.add_var(*var_index, one)?;

let typ = AcirType::NumericType(numeric_type);
Ok(AcirValue::Var(read, typ))
}
Type::Array(element_types, len) => {
let mut values = Vector::new();
for _ in 0..len {
for typ in element_types.as_ref() {
values
.push_back(self.array_get_value(typ, block_id, var_index, first_elem)?);
values.push_back(self.array_get_value(typ, block_id, var_index)?);
}
}
Ok(AcirValue::Array(values))
Expand Down Expand Up @@ -922,8 +914,7 @@ impl Context {
)?;
}

let mut is_first_elem = true;
self.array_set_value(store_value, result_block_id, &mut var_index, &mut is_first_elem)?;
self.array_set_value(store_value, result_block_id, &mut var_index)?;

let result_value =
AcirValue::DynamicArray(AcirDynamicArray { block_id: result_block_id, len: array_len });
Expand All @@ -936,25 +927,22 @@ impl Context {
value: AcirValue,
block_id: BlockId,
var_index: &mut AcirVar,
first_elem: &mut bool,
) -> Result<(), RuntimeError> {
let one = self.acir_context.add_constant(FieldElement::one());
match value {
AcirValue::Var(store_var, _) => {
if !*first_elem {
*var_index = self.acir_context.add_var(*var_index, one)?;
}
*first_elem = false;
// Write the new value into the new array at the specified index
self.acir_context.write_to_memory(block_id, var_index, &store_var)?;
// Incremement the var_index in case of a nested array
*var_index = self.acir_context.add_var(*var_index, one)?;
}
AcirValue::Array(values) => {
for value in values {
self.array_set_value(value, block_id, var_index, first_elem)?;
self.array_set_value(value, block_id, var_index)?;
}
}
AcirValue::DynamicArray(_) => {
panic!("ahhh got dyn array for set")
unimplemented!("ICE: setting a dynamic array not supported");
}
}
Ok(())
Expand Down

0 comments on commit f2dd702

Please sign in to comment.