Skip to content

fix(acir_gen): Do not call into AcirValue::flatten during AcirValue::flat_numeric_types#9894

Merged
vezenovm merged 3 commits intoaf/9860-acir-gen-flat-dyn-arrfrom
mv/fix-flat-numeric-types
Sep 18, 2025
Merged

fix(acir_gen): Do not call into AcirValue::flatten during AcirValue::flat_numeric_types#9894
vezenovm merged 3 commits intoaf/9860-acir-gen-flat-dyn-arrfrom
mv/fix-flat-numeric-types

Conversation

@vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Sep 17, 2025

Description

Problem*

Alternative to #9887

In #9860 we look to be panicking due to attempting flatten an AcirValue::Array containing an AcirValue::DynamicArray. This panic is ultimately triggered by a call to flat_numeric_types. We should be able to safely write an array value that contains dynamic arrays (in fact this call to flat_numeric_types occurs after array_set_value).

Summary*

I switched to iterating through each array element in flat_numeric_types rather than calling AcirValue::flatten directly.

Additional Context

These issues could be avoid with #6231 as well as arrays will not be able to contain one another.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@github-actions
Copy link
Contributor

Changes to circuit sizes

Generated at commit: ef77cbb8a26263a71cbef0416744a9baceb3bd53, compared to commit: 152fedcf9fa9bbfc7b3af8a00135a42903ee46b3

🧾 Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
conditional_1 +6 ❌ +0.23% +16 ❌ +0.20%
regression_9860 -4 ✅ -4.44% -17 ✅ -0.56%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
conditional_1 2,636 (+6) +0.23% 7,999 (+16) +0.20%
regression_9860 86 (-4) -4.44% 3,045 (-17) -0.56%

@vezenovm vezenovm requested a review from aakoshh September 17, 2025 20:14
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: da360a9 Previous: a2ec2e5 Ratio
test_report_zkpassport_noir-ecdsa_ 2 s 1 s 2

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

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
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
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
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.

@@ -156,11 +157,11 @@ impl AcirValue {

pub(super) fn flat_numeric_types(self) -> Vec<NumericType> {
Copy link
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
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

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@vezenovm
Copy link
Contributor Author

Merging into the parent @aakoshh

@vezenovm vezenovm merged commit cce4c10 into af/9860-acir-gen-flat-dyn-arr Sep 18, 2025
32 checks passed
@vezenovm vezenovm deleted the mv/fix-flat-numeric-types branch September 18, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants