Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions compiler/noirc_evaluator/src/acir/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 15 additions & 4 deletions compiler/noirc_evaluator/src/acir/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
Expand Down Expand Up @@ -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)],
Expand All @@ -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<NumericType> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add some docs to this method, in particular why this can work for all AcirValue variants, but flatten does not, while they conceptually sound similar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments

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"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomAFrench comments such as these is why I think it would be great to get a walkthrough of how ACIR arrays are supposed to work in general. cc @asterite

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah they could use a revamp and improved documentation in general. I'll be going over the arrays soon for audit prep work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I can maybe do some docs writing next week while doing the ignition review.

AcirValue::Var(_, typ) => vec![typ.to_numeric_type()],
}
}
}
Expand Down
Loading