From 6549bb77f361b530e32258e4c009bd999f35c073 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 17 Sep 2025 20:01:14 +0000 Subject: [PATCH 1/3] fix ArrayValue::flat_numeric_types --- compiler/noirc_evaluator/src/acir/arrays.rs | 8 +------- compiler/noirc_evaluator/src/acir/types.rs | 9 +++++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/compiler/noirc_evaluator/src/acir/arrays.rs b/compiler/noirc_evaluator/src/acir/arrays.rs index 7b37d444036..90319355bc9 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); @@ -600,6 +593,7 @@ impl Context<'_> { }; let value_types = self.convert_value(array, dfg).flat_numeric_types(); + dbg!(value_types.clone()); // Compiler sanity check assert_eq!( value_types.len(), diff --git a/compiler/noirc_evaluator/src/acir/types.rs b/compiler/noirc_evaluator/src/acir/types.rs index 81ae44575d6..0c291f5069a 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) ) } @@ -156,11 +157,11 @@ impl AcirValue { 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()], } } } From 0468590c5f4c393bde7d7bd45486b76d8e7a5bec Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 17 Sep 2025 20:04:25 +0000 Subject: [PATCH 2/3] cleanup --- compiler/noirc_evaluator/src/acir/arrays.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/acir/arrays.rs b/compiler/noirc_evaluator/src/acir/arrays.rs index 90319355bc9..f47fbaa3465 100644 --- a/compiler/noirc_evaluator/src/acir/arrays.rs +++ b/compiler/noirc_evaluator/src/acir/arrays.rs @@ -593,7 +593,6 @@ impl Context<'_> { }; let value_types = self.convert_value(array, dfg).flat_numeric_types(); - dbg!(value_types.clone()); // Compiler sanity check assert_eq!( value_types.len(), From da360a997e699ca7f32a556a396b5e526b78217f Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Thu, 18 Sep 2025 12:27:08 +0000 Subject: [PATCH 3/3] comments --- compiler/noirc_evaluator/src/acir/types.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/noirc_evaluator/src/acir/types.rs b/compiler/noirc_evaluator/src/acir/types.rs index 0c291f5069a..7ccbf09fdef 100644 --- a/compiler/noirc_evaluator/src/acir/types.rs +++ b/compiler/noirc_evaluator/src/acir/types.rs @@ -147,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)], @@ -155,6 +162,9 @@ 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(array) => {