-
Notifications
You must be signed in to change notification settings - Fork 230
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
add turbofish-like syntax #4710
Closed
2 tasks done
Labels
enhancement
New feature or request
Comments
6 tasks
5 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
May 21, 2024
# Description ## Problem\* Resolves <!-- Link to GitHub Issue --> Working towards #4514 and fully resolving #4710 ## Summary\* We need to accurately monomorphize functions with turbofish operators where no function parameters or the return type using the specified generic. Without this change the following would pass: ``` fn main(x: Field, y: pub Field) { let mut hasher = PoseidonHasher::default(); hasher.write(x); hasher.write(y); let poseidon_expected_hash = hasher.finish(); assert(hash_simple_array::<PoseidonHasher>([x, y]) == poseidon_expected_hash); let mut hasher = Poseidon2Hasher::default(); hasher.write(x); hasher.write(y); let poseidon2_expected_hash = hasher.finish(); assert(hash_simple_array::<Poseidon2Hasher>([x, y]) == poseidon_expected_hash); assert(hash_simple_array::<Poseidon2Hasher>([x, y]) != poseidon2_expected_hash); } fn hash_simple_array<H>(input: [Field; 2]) -> Field where H: Hasher + Default { let mut hasher: H = H::default(); hasher.write(input[0]); hasher.write(input[1]); hasher.finish() } ``` Essentially any future invocations of `hash_simple_array` would use the `PoseidonHasher`. We now correctly monomorphize the functions to use the correct type. ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [ ] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: Jake Fecher <[email protected]> Co-authored-by: Jake Fecher <[email protected]> Co-authored-by: Tom French <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussed in https://github.com/orgs/noir-lang/discussions/3413
Originally posted by f01dab1e August 28, 2023
Problem
In Rust, the "turbofish" syntax (
::<>
) allows users to explicitly specify generic type parameters in function calls. This feature has proven to be useful for disambiguating type inference in certain scenarios.Happy Case
Alternatives Considered
No response
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
Issues which can be worked around / fixed with turbofish
The text was updated successfully, but these errors were encountered: