You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that the compiler supports inlining Brillig functions based off of an aggressiveness setting, we can potentially have non-inlined functions in our final SSA. Previously, when we used to inline all functions a global would simply be a local constant that was constructed in the top block of a function. With multiple functions being able to re-use the same global, we may now be duplicating initialization of the those constants across functions.
e.g. let's take the modified regression_4709 test:
global EXPONENTIATE: [[Field; 2]; 2] = [
[1, 1],
[0, 0],
];
fn main(x: Field, y: pub Field) {
let mut acc: Field = 0;
for i in 0..2 {
for j in 0..2 {
acc += EXPONENTIATE[i][j];
}
}
assert(!acc.lt(x));
assert(x != y);
dummy_again(x, y);
}
fn dummy_again(x: Field, y: pub Field) {
let mut acc: Field = 0;
for i in 0..2 {
for j in 0..2 {
acc += EXPONENTIATE[i][j];
}
}
assert(!acc.lt(x));
assert(x != y);
}
If compiled with a really low inliner aggressiveness, while compiling to Brillig we will get the following SSA for main:
Problem
Now that the compiler supports inlining Brillig functions based off of an aggressiveness setting, we can potentially have non-inlined functions in our final SSA. Previously, when we used to inline all functions a global would simply be a local constant that was constructed in the top block of a function. With multiple functions being able to re-use the same global, we may now be duplicating initialization of the those constants across functions.
e.g. let's take the modified
regression_4709
test:If compiled with a really low inliner aggressiveness, while compiling to Brillig we will get the following SSA for
main
:We will see the exact same SSA for
dummy_again
. This means everytimedummy_again
is called we are going to reinitialize theEXPONENTIATE
global array.Happy Case
We should add global variables to SSA. These must be compile time values and must be immutable.
An example of what it could like in SSA pseudocode:
Some of the handling of constants in Brillig will also have to be updated to share global constants across functions.
LLVM has global variables as well (https://llvm.org/docs/LangRef.html#global-variables), from which the inspiration for the
@
marker came.Workaround
None
Workaround Description
If you want non-inlined functions there is not really a workaround as the workaround is to inline all functions.
Additional Context
No response
Project Impact
None
Blocker Context
No response
Would you like to submit a PR for this Issue?
Yes
Support Needs
No response
The text was updated successfully, but these errors were encountered: