-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: better take at type hierarchy in SSA
- Loading branch information
1 parent
211e251
commit c539c2d
Showing
10 changed files
with
381 additions
and
130 deletions.
There are no files selected for viewing
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
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_slices_casting/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.6.0" | ||
|
||
[dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_slices_casting/Prover.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,2 @@ | ||
x = "5" | ||
y = "10" |
54 changes: 54 additions & 0 deletions
54
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_slices_casting/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,54 @@ | ||
use dep::std::slice; | ||
use dep::std; | ||
|
||
unconstrained fn main(x: Field, y: Field) { | ||
let mut array = [x, y]; | ||
|
||
// Dynamic dispatch typing | ||
let mut test_slice = wrapper(push_accepts_array_returns_slice, array); | ||
assert(test_slice[2] == 1); | ||
|
||
test_slice = wrapper(push_accepts_slice_returns_slice, array); | ||
assert(test_slice[2] == 1); | ||
|
||
|
||
//Get the slice from a function to correct the type until https://github.com/noir-lang/noir/issues/1931 is fixed | ||
let mut slice = get_me_a_slice(x, y); | ||
|
||
|
||
// No cast | ||
let another_array = push_accepts_array_returns_array(array); | ||
assert(another_array[2] == 1); | ||
|
||
slice = push_accepts_array_returns_slice(array); | ||
assert(slice[2] == 1); | ||
|
||
// Cast return value | ||
slice = push_accepts_array_returns_array(array); | ||
assert(slice[2] == 1); | ||
|
||
// Cast param | ||
slice = push_accepts_slice_returns_slice(array); | ||
assert(slice[2] == 1); | ||
} | ||
|
||
unconstrained fn get_me_a_slice(x: Field, y: Field) -> [Field] { | ||
[x, y] | ||
} | ||
|
||
unconstrained fn push_accepts_array_returns_slice<N>(array: [Field; N]) -> [Field] { | ||
let slice: [Field] = array; | ||
slice.push_back(1) | ||
} | ||
|
||
unconstrained fn push_accepts_array_returns_array(array: [Field; 2]) -> [Field; 3] { | ||
[array[0], array[1], 1] | ||
} | ||
|
||
unconstrained fn push_accepts_slice_returns_slice(slice: [Field]) -> [Field] { | ||
slice.push_back(1) | ||
} | ||
|
||
unconstrained fn wrapper(function: fn ([Field]) -> [Field], param: [Field; 2]) -> [Field] { | ||
function(param) | ||
} |
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.