fix(defunctionalization): ACIR variant in Brillig#9728
Merged
vezenovm merged 7 commits intogd/issue_9390from Sep 4, 2025
Merged
fix(defunctionalization): ACIR variant in Brillig#9728vezenovm merged 7 commits intogd/issue_9390from
vezenovm merged 7 commits intogd/issue_9390from
Conversation
Contributor
There was a problem hiding this comment.
⚠️ 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: 1917488 | Previous: 8d5ae13 | Ratio |
|---|---|---|---|
test_report_noir-lang_sha512_ |
21 s |
12 s |
1.75 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem*
Resolves errors in #9412.
As per the #9484 description we duplicate both constrained and unconstrained versions of closures. Later when the function is called we extract the correct version to call based off of the caller runtime. However, this means we may still have closure variants with differing runtimes for which defunctionalization will attempt to call.
Summary*
#9412 attempted to work around variants with differing runtimes by adding an extra always failing constrain that are attemping to call a function with a different runtime.
For example this is what was done in #9412 (where f3 is an ACIR function):
However, this breaks when we get to inlining as we will attempt to inline f3.
We can achieve the same effect by simply not skipping all functions with a differing runtime. All conditionals and the final dispatch constrain will only reference the function IDs for the variants with matching runtimes. Thus, if the frontend generates bad code and attempts to call the ACIR variant, it will be caught by the
constrainin the final dispatch. You can see the tests in this PR for a more in depth example. Theapplyfunction above will now be the following:I decided to perform the filtering during
create_apply_functionsso that we can add an extra check for whether we ended up with no variants after filtering against ACIR runtimes. This means we have a frontend bug for closure runtime duplication.Additional Context
Another option would be to keep what was done in #9412 but mark ACIR -> Brillig calls as never being allowed to be inlined. However, this ACIR being called from Brillig would then be a well-formed SSA and it would have to be protected by constrain instruction as done for the
applymethod.Documentation*
Check one:
PR Checklist*
cargo fmton default settings.