-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ssa refactor): Implement first-class references (#1849)
* Explore work on references * Cleanup * Implement first-class references * Fix frontend test * Remove 'Mutability' struct, it is no longer needed * Remove some extra lines * Remove another function * Revert another line * Fix test again * Fix a bug in mem2reg for nested references * Fix inconsistent .eval during ssa-gen on assign statements * Revert some code * Add check for mutating immutable self objects
- Loading branch information
Showing
27 changed files
with
611 additions
and
103 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/references/Nargo.toml
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.5.1" | ||
|
||
[dependencies] |
Empty file.
56 changes: 56 additions & 0 deletions
56
crates/nargo_cli/tests/test_data_ssa_refactor/references/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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
fn main() { | ||
let mut x = 2; | ||
add1(&mut x); | ||
assert(x == 3); | ||
|
||
let mut s = S { y: x }; | ||
s.add2(); | ||
assert(s.y == 5); | ||
|
||
// Test that normal mutable variables are still copied | ||
let mut a = 0; | ||
mutate_copy(a); | ||
assert(a == 0); | ||
|
||
// Test something 3 allocations deep | ||
let mut nested_allocations = Nested { y: &mut &mut 0 }; | ||
add1(*nested_allocations.y); | ||
assert(**nested_allocations.y == 1); | ||
|
||
// Test nested struct allocations with a mutable reference to an array. | ||
let mut c = C { | ||
foo: 0, | ||
bar: &mut C2 { | ||
array: &mut [1, 2], | ||
}, | ||
}; | ||
*c.bar.array = [3, 4]; | ||
assert(*c.bar.array == [3, 4]); | ||
} | ||
|
||
fn add1(x: &mut Field) { | ||
*x += 1; | ||
} | ||
|
||
struct S { y: Field } | ||
|
||
struct Nested { y: &mut &mut Field } | ||
|
||
struct C { | ||
foo: Field, | ||
bar: &mut C2, | ||
} | ||
|
||
struct C2 { | ||
array: &mut [Field; 2] | ||
} | ||
|
||
impl S { | ||
fn add2(&mut self) { | ||
self.y += 2; | ||
} | ||
} | ||
|
||
fn mutate_copy(mut a: Field) { | ||
a = 7; | ||
} |
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
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.