diff --git a/compiler/noirc_evaluator/src/acir/arrays.rs b/compiler/noirc_evaluator/src/acir/arrays.rs index 7b37d444036..f47fbaa3465 100644 --- a/compiler/noirc_evaluator/src/acir/arrays.rs +++ b/compiler/noirc_evaluator/src/acir/arrays.rs @@ -226,13 +226,6 @@ impl Context<'_> { } if let Some(store_value) = store_value { - // We should avoid storing a DynamicArray directly inside an Array. Instead we must allow - // the regular `array_set_value` to take place which reads the item from the block the - // dynamic array refers to, and writes items one by one. Otherwise subsequent operations - // with non-constant indexes will fail. - if matches!(store_value, AcirValue::DynamicArray(_)) { - return Ok(false); - } let side_effects_always_enabled = self.acir_context.is_constant_one(&self.current_side_effects_enabled_var); diff --git a/compiler/noirc_evaluator/src/acir/types.rs b/compiler/noirc_evaluator/src/acir/types.rs index 81ae44575d6..7ccbf09fdef 100644 --- a/compiler/noirc_evaluator/src/acir/types.rs +++ b/compiler/noirc_evaluator/src/acir/types.rs @@ -110,9 +110,10 @@ impl Debug for AcirDynamicArray { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!( f, - "id: {}, len: {}, element_type_sizes: {:?}", + "id: {}, len: {}, value_types: {:?}, element_type_sizes: {:?}", self.block_id.0, self.len, + self.value_types, self.element_type_sizes.map(|block_id| block_id.0) ) } @@ -146,6 +147,13 @@ impl AcirValue { } } + /// Fetch a flat list of ([AcirVar], [AcirType]). + /// + /// # Panics + /// If [AcirValue::DynamicArray] is supplied or an inner element of an [AcirValue::Array]. + /// This is because an [AcirValue::DynamicArray] is simply a pointer to an array + /// and fetching its internal [AcirValue::Var] would require laying down opcodes to read its content. + /// This method should only be used where dynamic arrays are not a possible type. pub(super) fn flatten(self) -> Vec<(AcirVar, AcirType)> { match self { AcirValue::Var(var, typ) => vec![(var, typ)], @@ -154,13 +162,16 @@ impl AcirValue { } } + /// Fetch a flat list of the [NumericType] contained within an array + /// An [AcirValue::DynamicArray] should already have a field representing + /// its types and should be supported here unlike [AcirValue::flatten] pub(super) fn flat_numeric_types(self) -> Vec { match self { - AcirValue::Array(_) => { - self.flatten().into_iter().map(|(_, typ)| typ.to_numeric_type()).collect() + AcirValue::Array(array) => { + array.into_iter().flat_map(|elem| elem.flat_numeric_types()).collect() } AcirValue::DynamicArray(AcirDynamicArray { value_types, .. }) => value_types, - _ => unreachable!("An AcirValue::Var cannot be used as an array value"), + AcirValue::Var(_, typ) => vec![typ.to_numeric_type()], } } }