-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): Explicit numeric generics and type kinds (#5155)
# Description ## Problem\* Resolves #4633, but only in the elaborator as we will be moving to this new infrastructure for the frontend soon and resolving edge cases across both the old resolver and the elaborator was becoming a time sink. ## Summary\* We now have an `UnresolvedGeneric` type rather than simply representing generics using idents. ```rust pub enum UnresolvedGeneric { Variable(Ident), Numeric { ident: Ident, typ: UnresolvedType }, } ``` We also have a new `ResolvedGeneric` struct when storing generics during resolution and elaboration. We were previously storing a tuple of three elements, but now that I need to distinguish when we have a numeric generic it was simpler to make this a struct. Some example usage: ```rust // Used as a field of a struct struct Foo<let N: u64> { inner: [u64; N], } fn baz<let N: u64>() -> Foo<N> { Foo { inner: [1; N] } } // Used in an impl impl<let N: u64> Foo<N> { fn bar(self) -> u64 { N * self.inner[0] } } ``` More examples can be found in `numeric_generics` and documentation will come in a follow-up. We make sure to error out when an explicit numeric generic is used as a type. For example, this code: ```rust struct Trash<let N: u64> { a: Field, b: N, } fn id_two<let I: Field>(x: I) -> I { x } ``` <img width="749" alt="Screenshot 2024-06-04 at 5 42 53 PM" src="https://github.com/noir-lang/noir/assets/43554004/a515a508-7ea4-4a23-bfd3-6f7bbae28e55"> ## Additional Context We do not ban the old strategy for implicit numeric generics just yet as a lot of code uses it. Currently this warning is issued: <img width="965" alt="Screenshot 2024-06-04 at 11 34 19 AM" src="https://github.com/noir-lang/noir/assets/43554004/60c79337-98b2-4e70-a11d-947f6611fc41"> ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [X] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: jfecher <jake@aztecprotocol.com>
- Loading branch information
Showing
43 changed files
with
1,501 additions
and
264 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
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.