Skip to content

chore: add acir-gen unit tests per ssa instruction#8084

Closed
guipublic wants to merge 17 commits intomasterfrom
gd/acir-gen_tests
Closed

chore: add acir-gen unit tests per ssa instruction#8084
guipublic wants to merge 17 commits intomasterfrom
gd/acir-gen_tests

Conversation

@guipublic
Copy link
Contributor

Description

Problem*

Increase test coverage for acir-gen

Summary*

Add a framework for acir-gen unit tests.
It generates SSA for a single instruction, converts it using acir-gen and execute it.
Then we compare the result with a SSA evaluation using constant folding.
All 'simple' instructions are covered, in particular all the binary instructions.
More tests with different types or missing instructions such as array operations and calls could be added in future.

Additional Context

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.

@guipublic guipublic requested a review from a team April 15, 2025 11:28
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 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: f3b2941 Previous: b591847 Ratio
rollup-merge 0.004 s 0.003 s 1.33

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

CC: @TomAFrench

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: f3b2941 Previous: b591847 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 51 s 41 s 1.24

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

CC: @TomAFrench

Copy link
Contributor

@vezenovm vezenovm left a comment

Choose a reason for hiding this comment

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

I was thinking of ACIR gen unit tests that were more similar to our SSA units tests. Something along the lines of we accept an SSA src text and check that it matches the supplied ACIR text. We would probably need to complete this issue #7902 and make an ACIR parser similar to the SSA parser to do that

.expect("Should compile manually written SSA into ACIR");
assert_eq!(acir_functions.len(), 1);
let main = &acir_functions[0];
let mut acvm = ACVM::new(
Copy link
Contributor

@vezenovm vezenovm Apr 16, 2025

Choose a reason for hiding this comment

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

Executing in the acir-gen unit tests feels a little strange to me. It feels more like an integration test versus a test of the output of our ACIR gen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For me it is a unit test because it test a single operator.

@TomAFrench
Copy link
Member

@vezenovm If we're testing SSA -> ACIR then we don't need to fully complete #7902 in order to do this (obviously the test becomes more binding in that case) but we can probably get enough out with the current output.

@vezenovm
Copy link
Contributor

If we're testing SSA -> ACIR then we don't need to fully complete #7902 in order to do this (obviously the test becomes more binding in that case) but we can probably get enough out with the current output.

Sounds good, agreed. In addition to your note, we already do test in this way for the existing ACIR gen unit tests. Either way I still think the ACIR gen unit tests should be more in the vein mentioned in my original comment. e.g. does_not_generate_memory_blocks_without_dynamic_accesses (post SSA parser) and brillig_stdlib_calls_with_multiple_acir_calls (pre SSA parser) are a good example of the kind of tests I would expect.

I mentioned completing #7902 and an ACIR parser as it may be worth it to still complete that task before adding more unit tests as it would not only make the unit tests more binding but quicker to write. If we have tests we can add now though without completing #7902 though I won't block those.

Copy link
Contributor

@vezenovm vezenovm 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! I am more comfortable with these tests being under acir now that they use the SSA interpreter vs. constant folding. I think ideally these would be moved into their own interpreter module or something, but as this PR has been up for a while I am good with the PR as is. The tests can reorganized in follow-ups. Just some last nits with regards to comments.

"truncate 8 32",
];
let inputs = [FieldElement::from(2_usize), FieldElement::from(1_usize)];
test_operators(&operators, "u32", &inputs);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess in follow-ups we can test the remaining numeric types then.

// Bitwise operations are not allowed on field elements
// SSA interpreter will emit an error but not ACVM
// "and",
// "xor",
Copy link
Contributor

Choose a reason for hiding this comment

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

We can follow-up with expected error tests that would have corresponding issues.

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 'Compilation Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 740428d Previous: ba05d72 Ratio
private-kernel-reset 10.306 s 8.076 s 1.28

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

CC: @TomAFrench

@github-actions
Copy link
Contributor

Changes to Brillig bytecode sizes

Generated at commit: 043b39c10c024fa22d679c93926411edcfc622cd, compared to commit: fe87db3078bef4fa726c66565e016926c3ce9cbb

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
brillig_nested_arrays_inliner_min +30 ❌ +21.28%
brillig_nested_arrays_inliner_zero +30 ❌ +21.28%

Full diff report 👇
Program Brillig opcodes (+/-) %
brillig_nested_arrays_inliner_min 171 (+30) +21.28%
brillig_nested_arrays_inliner_zero 171 (+30) +21.28%
unrolling_regression_8333_inliner_max 88 (+6) +7.32%
unrolling_regression_8333_inliner_min 88 (+6) +7.32%
unrolling_regression_8333_inliner_zero 88 (+6) +7.32%
fold_complex_outputs_inliner_max 361 (+12) +3.44%
nested_array_in_slice_inliner_max 880 (+19) +2.21%
nested_arrays_from_brillig_inliner_min 151 (+3) +2.03%

@github-actions
Copy link
Contributor

Changes to number of Brillig opcodes executed

Generated at commit: 043b39c10c024fa22d679c93926411edcfc622cd, compared to commit: fe87db3078bef4fa726c66565e016926c3ce9cbb

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
brillig_nested_arrays_inliner_min +30 ❌ +22.22%
brillig_nested_arrays_inliner_zero +30 ❌ +22.22%

Full diff report 👇
Program Brillig opcodes (+/-) %
brillig_nested_arrays_inliner_min 165 (+30) +22.22%
brillig_nested_arrays_inliner_zero 165 (+30) +22.22%
fold_complex_outputs_inliner_max 452 (+12) +2.73%
nested_array_in_slice_inliner_max 1,072 (+19) +1.80%
nested_arrays_from_brillig_inliner_min 192 (+3) +1.59%
unrolling_regression_8333_inliner_max 724 (+6) +0.84%
unrolling_regression_8333_inliner_min 724 (+6) +0.84%
unrolling_regression_8333_inliner_zero 724 (+6) +0.84%

@guipublic
Copy link
Contributor Author

Closing as duplicate.
The PR was duplicated in #9185

@guipublic guipublic closed this Jul 21, 2025
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.

4 participants