fix(ssa): Use number of SSA instructions for the Brillig unrolling bytecode size limit #7242
+12
−38
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*
Pulls a change out of #7236 that was causing panics with less aggressive inliner settings. Comment for reference: #7236 (comment).
I labelled this PR a fix rather than a chore as it does prevent possible panics.
Summary*
After performing an unroll in the Brillig runtime we have a setting that lets us set an upper bound on the bytecode size increase percentage. However, we have certain intrinsics (e.g. DerivePedersenGenerators) that we expect to entirely compile-time and fully resolved by Brillig gen.
Another possible fix would be to set any method which calls
derive_generators
(such aspedersen_hash_with_separator
) as#[inline_always]
. However, we still do not have a guarantee that theseparator
has been resolved to a constant. Let's say we knowderive_generators
is called bypedersen_hash_with_separator
. Even ifpedersen_hash_with_separator
is always inlined into its parent we cannot guarantee that the input for the separator comes from the parent's function parameter. This issue will exist with any other intrinsics we expect to be fully resolved by compile-time.By using the number of SSA instructions we can also avoid the extra compilation to Brillig as well as having to expose extra Brillig gen logic to the SSA passes. This gives us a better separation of concerns.
Additional Context
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.