-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Implement constant folding during the mem2reg pass (#2464)
Co-authored-by: Maxim Vezenov <[email protected]>
- Loading branch information
Showing
7 changed files
with
177 additions
and
114 deletions.
There are no files selected for viewing
27 changes: 23 additions & 4 deletions
27
crates/nargo_cli/tests/execution_success/references_aliasing/src/main.nr
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
fn increment(mut r: &mut Field) { | ||
*r = *r + 1; | ||
} | ||
|
||
fn main() { | ||
let mut x = 100; | ||
let mut xref = &mut x; | ||
increment(xref); | ||
assert(*xref == 101); | ||
|
||
regression_2445(); | ||
} | ||
|
||
fn increment(mut r: &mut Field) { | ||
*r = *r + 1; | ||
} | ||
|
||
// If aliasing within arrays and constant folding within the mem2reg pass aren't | ||
// handled, we'll fail to optimize out all the references in this function. | ||
fn regression_2445() { | ||
let mut var = 0; | ||
let ref = &mut &mut var; | ||
|
||
let mut array = [ref, ref]; | ||
|
||
**array[0] = 1; | ||
**array[1] = 2; | ||
|
||
assert(var == 2); | ||
assert(**ref == 2); | ||
assert(**array[0] == 2); | ||
assert(**array[1] == 2); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.