-
Notifications
You must be signed in to change notification settings - Fork 386
fix(acir_gen): Do not call into AcirValue::flatten during AcirValue::flat_numeric_types #9894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<NumericType> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()], | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.