Skip to content

fix(ssa): Do not fail for static assertions in a map over empty dynamic slices#9060

Merged
vezenovm merged 19 commits intomasterfrom
mv/static-assert-empty-map
Jul 2, 2025
Merged

fix(ssa): Do not fail for static assertions in a map over empty dynamic slices#9060
vezenovm merged 19 commits intomasterfrom
mv/static-assert-empty-map

Conversation

@vezenovm
Copy link
Contributor

Description

Problem*

Resolves #7710

Summary*

This change ended up being more involved than expected:

  1. If we are in an empty loop (e.g. the upper bound is not greater than the lower bound), we skip evaluation a static assertion and do not insert it back into the SSA. For now I chose to still error out if the static assertion is inside of a dynamic loop. However, this may not be sufficient on its own, perhaps we should add a warning to not place static assertions under dynamic loops.
  2. With non-aggressive inlining we can have loop bounds from function parameters that would otherwise resolve to constants if the function was inlined. For example, the regression test added in this PR would fail with the minimum inliner aggressiveness and only the change from (1). I chose to simply always inline functions which contains calls to static assertions.
  3. We can still have nested functions calls where we pass along a constant call argument through many calls. To fully handle (2) I switched inlining to operate with a feedback loop until a fixed point. This type of logic is common in modern compilers and is something we already do in multiple SSA passes.

Additional Context

A full fix to handling constants call arguments would be #8321. However, this is quite an involved change so I decided (2) and (3) above provided a nice way to iteratively fix this bug and propagate constants for static assertions.

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.

@vezenovm vezenovm changed the title fix(ssa): Do not fail for static assertions in a map over empty arrays fix(ssa): Do not fail for static assertions in a map over empty dynamic slices Jun 30, 2025
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: 56b199e Previous: d12ebe7 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_rollup-lib 655 s 541 s 1.21
test_report_noir-lang_noir_bigcurve_ 324 s 251 s 1.29
test_report_zkpassport_noir_rsa_ 2 s 1 s 2

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

CC: @TomAFrench

@vezenovm vezenovm added the bench-show Display benchmark results on PR label Jun 30, 2025
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.

ACVM Benchmarks

Details
Benchmark suite Current: 56b199e Previous: d12ebe7 Ratio
purely_sequential_opcodes 249558 ns/iter (± 1050) 257657 ns/iter (± 2210) 0.97
perfectly_parallel_opcodes 220060 ns/iter (± 3196) 228310 ns/iter (± 3038) 0.96
perfectly_parallel_batch_inversion_opcodes 2807352 ns/iter (± 2800) 2787393 ns/iter (± 2850) 1.01

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

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.

Execution Time

Details
Benchmark suite Current: 56b199e Previous: d12ebe7 Ratio
private-kernel-inner 0.026 s 0.026 s 1
private-kernel-reset 0.161 s 0.162 s 0.99
private-kernel-tail 0.011 s 0.011 s 1
rollup-base-private 0.291 s 0.291 s 1
rollup-base-public 0.185 s 0.183 s 1.01
rollup-block-root 13.3 s 13.2 s 1.01
rollup-merge 0.002 s 0.002 s 1
rollup-root 0.004 s 0.004 s 1
semaphore-depth-10 0.026 s 0.02 s 1.30

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

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.

Compilation Time

Details
Benchmark suite Current: 56b199e Previous: d12ebe7 Ratio
private-kernel-inner 2.52 s 2.362 s 1.07
private-kernel-reset 8.204 s 7.944 s 1.03
private-kernel-tail 1.144 s 1.184 s 0.97
rollup-base-private 16.92 s 15.5 s 1.09
rollup-base-public 15.2 s 13.46 s 1.13
rollup-block-root-empty 20.58 s 19.14 s 1.08
rollup-block-root-single-tx 200 s 189 s 1.06
rollup-block-root 195 s 184 s 1.06
rollup-merge 1.31 s 1.292 s 1.01
rollup-root 1.39 s 1.442 s 0.96
semaphore-depth-10 0.796 s 0.765 s 1.04

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

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: 56b199e Previous: d12ebe7 Ratio
semaphore-depth-10 0.026 s 0.02 s 1.30

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.

Artifact Size

Details
Benchmark suite Current: 56b199e Previous: d12ebe7 Ratio
private-kernel-inner 1127.4 KB 1127.4 KB 1
private-kernel-reset 2067.9 KB 2067.9 KB 1
private-kernel-tail 585 KB 585 KB 1
rollup-base-private 4934.4 KB 4934.4 KB 1
rollup-base-public 3975.6 KB 3975.6 KB 1
rollup-block-root-empty 3871.1 KB 3868.7 KB 1.00
rollup-block-root-single-tx 32733.4 KB 32731.7 KB 1.00
rollup-block-root 32752.7 KB 32749.7 KB 1.00
rollup-merge 176.8 KB 176.8 KB 1
rollup-root 389.5 KB 389.5 KB 1
semaphore-depth-10 636.4 KB 636.4 KB 1

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

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.

Test Suite Duration

Details
Benchmark suite Current: 56b199e Previous: d12ebe7 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_aztec-nr 100 s 99 s 1.01
test_report_AztecProtocol_aztec-packages_noir-projects_noir-contracts 147 s 148 s 0.99
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 167 s 177 s 0.94
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_private-kernel-lib 218 s 219 s 1.00
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_rollup-lib 655 s 541 s 1.21
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_types 91 s 93 s 0.98
test_report_noir-lang_noir-bignum_ 379 s 376 s 1.01
test_report_noir-lang_noir_bigcurve_ 324 s 251 s 1.29
test_report_noir-lang_sha512_ 16 s 14 s 1.14
test_report_zkpassport_noir-ecdsa_ 104 s 98 s 1.06
test_report_zkpassport_noir_rsa_ 2 s 1 s 2

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

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.

Execution Memory

Details
Benchmark suite Current: 56b199e Previous: d12ebe7 Ratio
private-kernel-inner 202.71 MB 202.71 MB 1
private-kernel-reset 226.5 MB 226.5 MB 1
private-kernel-tail 178.04 MB 178.04 MB 1
rollup-base-private 508.01 MB 508.01 MB 1
rollup-base-public 441.22 MB 441.22 MB 1
rollup-block-root 1510 MB 1510 MB 1
rollup-merge 330.09 MB 330.09 MB 1
rollup-root 332.7 MB 332.7 MB 1
semaphore_depth_10 71.01 MB 71.01 MB 1

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

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.

Compilation Memory

Details
Benchmark suite Current: 56b199e Previous: d12ebe7 Ratio
private-kernel-inner 280.13 MB 280.13 MB 1
private-kernel-reset 534.01 MB 534.01 MB 1
private-kernel-tail 184.58 MB 184.58 MB 1
rollup-base-private 1400 MB 1400 MB 1
rollup-base-public 1530 MB 1530 MB 1
rollup-block-root-empty 1090 MB 1090 MB 1
rollup-block-root-single-tx 9380 MB 9380 MB 1
rollup-block-root 9390 MB 9390 MB 1
rollup-merge 333.56 MB 333.56 MB 1
rollup-root 343.59 MB 343.59 MB 1
semaphore_depth_10 106.39 MB 106.39 MB 1

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

@vezenovm vezenovm marked this pull request as ready for review June 30, 2025 18:15
@vezenovm vezenovm requested a review from a team June 30, 2025 18:15
@vezenovm vezenovm mentioned this pull request Jun 30, 2025
5 tasks
@TomAFrench
Copy link
Member

merging master to run benchmarks again

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: 2b7b601 Previous: d692001 Ratio
rollup-block-root 262 s 182 s 1.44

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

CC: @TomAFrench

@vezenovm
Copy link
Contributor Author

vezenovm commented Jul 1, 2025

merging master to run benchmarks again

Running once more without the re-inlining gate #9060 (comment) after #9069

@TomAFrench
Copy link
Member

@vezenovm Looks like there's still issues with the merge.

Copy link
Member

@TomAFrench TomAFrench 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, there's a few nits plus a bad merge.

@vezenovm vezenovm enabled auto-merge July 2, 2025 15:32
@vezenovm vezenovm added this pull request to the merge queue Jul 2, 2025
Merged via the queue into master with commit 0098c45 Jul 2, 2025
118 checks passed
@vezenovm vezenovm deleted the mv/static-assert-empty-map branch July 2, 2025 16:43
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 4, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: remove redundant associated constant lookup
(noir-lang/noir#9114)
chore: test that associated function and constant with the same name
collide (noir-lang/noir#9112)
feat: Allow TraitAsType syntax to refer to associated constants in
expressions (noir-lang/noir#9041)
chore: clippy (noir-lang/noir#9101)
chore(fuzz): Recursively generate lvalue for multi dimensional arrays
and nested tuples (noir-lang/noir#9086)
fix!: remove `hash_to_field` from stdlib
(noir-lang/noir#9098)
chore(docs): Brillig gen (noir-lang/noir#9085)
chore(fuzz): Test AST print-and-parse roundtrip
(noir-lang/noir#9083)
fix(ssa): Do not fail for static assertions in a map over empty dynamic
slices (noir-lang/noir#9060)
chore: merge `RangeCheckFailed` and `RangeCheckFailedWithMessage`
(noir-lang/noir#9093)
chore(fuzz): Capture printed output in `comptime_vs_brillig_direct`
(noir-lang/noir#9090)
chore(debug): Add trait constraint to string helper
(noir-lang/noir#9082)
chore: bump some deps (noir-lang/noir#9076)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
danielntmd pushed a commit to danielntmd/aztec-packages that referenced this pull request Jul 16, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: remove redundant associated constant lookup
(noir-lang/noir#9114)
chore: test that associated function and constant with the same name
collide (noir-lang/noir#9112)
feat: Allow TraitAsType syntax to refer to associated constants in
expressions (noir-lang/noir#9041)
chore: clippy (noir-lang/noir#9101)
chore(fuzz): Recursively generate lvalue for multi dimensional arrays
and nested tuples (noir-lang/noir#9086)
fix!: remove `hash_to_field` from stdlib
(noir-lang/noir#9098)
chore(docs): Brillig gen (noir-lang/noir#9085)
chore(fuzz): Test AST print-and-parse roundtrip
(noir-lang/noir#9083)
fix(ssa): Do not fail for static assertions in a map over empty dynamic
slices (noir-lang/noir#9060)
chore: merge `RangeCheckFailed` and `RangeCheckFailedWithMessage`
(noir-lang/noir#9093)
chore(fuzz): Capture printed output in `comptime_vs_brillig_direct`
(noir-lang/noir#9090)
chore(debug): Add trait constraint to string helper
(noir-lang/noir#9082)
chore: bump some deps (noir-lang/noir#9076)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bench-show Display benchmark results on PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

static_assert/assert_constant fail in empty loops over empty dynamic array as slice

2 participants