-
Notifications
You must be signed in to change notification settings - Fork 388
fix(frontend): Correctly monomorphize turbofish functions #5049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
04ea5d0
Add turbofish operator; add stack overflow crash
3a95229
Fix parsing error
jfecher 427cb95
Add test
jfecher 3ab58b8
Add compiler error for incorrect generic count
jfecher 8fc453a
Edit example to have a more problematic case
jfecher 4050fe5
Merge branch 'master' into jf/turbofish
TomAFrench b9673b2
resolved merge conflicts
vezenovm b289b87
fixup remaining fmt stuff
vezenovm 6127baf
cleanup
vezenovm 9ebb3b5
cargo fmt
vezenovm c652541
working initial turbofish tests
vezenovm 9660360
cargo fmt
vezenovm 4cee817
nargo fmt
vezenovm e89cde2
clippy
vezenovm a2da705
fmt
vezenovm da23029
nargo fmt
vezenovm da26bc3
fix nargo fmt for turbofish on method calls
vezenovm 77dfc19
clippy
vezenovm 0e5a579
initial work to get calling trait methods working, decided this would…
vezenovm c17e834
working turbofish with implicit generics now
vezenovm 8f2be2e
separate out function and implicit generic counts
vezenovm 405683e
merge conflicts w/ jf/turbofish and working trait methods with mutabl…
vezenovm 5ad8fb4
cleanup
vezenovm e7000d7
Merge branch 'master' into jf/turbofish
vezenovm 3cbba0b
merge conflicts w/ parent jf/turbofish
vezenovm cc135e7
cargo fmt
vezenovm a0090c1
cleanup
vezenovm 954aba7
nargo fmt
vezenovm 1e22003
add todo comments
vezenovm 44a4aee
specify type annotation for hasher
vezenovm 8d5c072
rename
vezenovm c6f3057
brought back removed comment
vezenovm 384e26a
chore: add test for specifying types on function with turbofish
TomAFrench 98c5d89
chore: add test for using turbofish with generic methods
TomAFrench 32d1714
chore: add turbofish to cspell
TomAFrench dde6d5a
correctly monomorphize turbofish functions
vezenovm e26ed36
missed save
vezenovm 9ab7351
nargo fmt tests
vezenovm b73d263
fix noirc_frontend tests
vezenovm a886946
chore: update formatter test outputs
TomAFrench 4125804
Revert "chore: update formatter test outputs"
TomAFrench bc7abf8
Update compiler/noirc_frontend/src/hir_def/expr.rs
vezenovm 8b1bbc4
have atom_or_right_unary accept a type parser
vezenovm cd1f59e
Merge remote-tracking branch 'origin/jf/turbofish' into jf/turbofish
vezenovm bd075fa
clippy and fmt
vezenovm b2100ad
Update compiler/noirc_frontend/src/hir/type_check/expr.rs
vezenovm 0d7fb67
Update test_programs/execution_success/trait_method_mut_self/src/main.nr
vezenovm c045540
Update test_programs/execution_success/trait_method_mut_self/src/main.nr
vezenovm c6aed8c
fetch implicit generic count from node interner
vezenovm 9bf4ac2
remove unused method implicit generics map
vezenovm 22e3cda
add new line to expected formatter tests
vezenovm af2c858
fixup after code review
vezenovm aa8e49e
fmy and clippy
vezenovm af3cc88
Merge branch 'jf/turbofish' into mv/trait-method-reference
vezenovm e6850e9
update comment
vezenovm e14738b
merge parent
vezenovm bf07ee8
move where implciit_generic_count is computed
vezenovm a9cb6c4
switch to single loop in instantiate_with
vezenovm daf151b
rename to turbofish_generics
vezenovm 0d887de
Merge branch 'master' into jf/turbofish
vezenovm 8d93a66
Merge branch 'jf/turbofish' into mv/trait-method-reference
vezenovm a44782b
Merge branch 'master' into jf/turbofish
vezenovm d174e13
Merge branch 'jf/turbofish' into mv/trait-method-reference
vezenovm 29bb0ae
Merge branch 'mv/trait-method-reference' into mv/turbofish-monomorphi…
vezenovm 12084ae
merge w/ master
vezenovm fa91128
remove extra function_generic_count
vezenovm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
test_programs/execution_success/turbofish_call_func_diff_types/Nargo.toml
This file contains hidden or 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,7 @@ | ||
| [package] | ||
| name = "turbofish_call_func_diff_types" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=0.29.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
test_programs/execution_success/turbofish_call_func_diff_types/Prover.toml
This file contains hidden or 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" |
36 changes: 36 additions & 0 deletions
36
test_programs/execution_success/turbofish_call_func_diff_types/src/main.nr
This file contains hidden or 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,36 @@ | ||
| use dep::std::hash::Hasher; | ||
| use dep::std::hash::poseidon2::Poseidon2Hasher; | ||
| use dep::std::hash::poseidon::PoseidonHasher; | ||
|
|
||
| fn main(x: Field, y: pub Field) { | ||
| let mut hasher = PoseidonHasher::default(); | ||
| hasher.write(x); | ||
| hasher.write(y); | ||
| let poseidon_expected_hash = hasher.finish(); | ||
| // Check that we get the same result when using the hasher in a | ||
| // method that purely uses trait methods without a supplied implementation. | ||
| assert(hash_simple_array::<PoseidonHasher>([x, y]) == poseidon_expected_hash); | ||
|
|
||
| // Now let's do the same logic but with a different `Hasher` supplied to the turbofish operator | ||
| // We want to make sure that we have correctly monomorphized a function with a trait generic | ||
| // where the generic is not used on any function parameters or the return value. | ||
| let mut hasher = Poseidon2Hasher::default(); | ||
| hasher.write(x); | ||
| hasher.write(y); | ||
| let poseidon2_expected_hash = hasher.finish(); | ||
| assert(hash_simple_array::<Poseidon2Hasher>([x, y]) == poseidon2_expected_hash); | ||
| } | ||
|
|
||
| fn hash_simple_array<H>(input: [Field; 2]) -> Field where H: Hasher + Default { | ||
| // Check that we can call a trait method instead of a trait implementation | ||
| // TODO(https://github.com/noir-lang/noir/issues/5063): Need to remove the need for this type annotation | ||
| // Curently, without the annotation we will get `Expression type is ambiguous` when trying to use the `hasher` | ||
| let mut hasher: H = H::default(); | ||
| // Regression that the object is converted to a mutable reference type `&mut _`. | ||
| // Otherwise will see `Expected type &mut _, found type H`. | ||
| // Then we need to make sure to also auto dereference later in the type checking process | ||
| // when searching for a matching impl or else we will get `No matching impl found for `&mut H: Hasher` | ||
| hasher.write(input[0]); | ||
| hasher.write(input[1]); | ||
| hasher.finish() | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.