-
Notifications
You must be signed in to change notification settings - Fork 199
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
Epic: Implement Traits #2568
Milestone
Comments
Closed
12 tasks
8 tasks
This was referenced Oct 17, 2023
Closed
Adding #2629 for when this Epic is nearing completion |
5 tasks
This was referenced Sep 15, 2023
3 tasks
This was referenced Oct 3, 2023
5 tasks
This was referenced Oct 31, 2023
5 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
Dec 13, 2023
# Description ## Problem\* Resolves #3773 Part of #2568 ## Summary\* This PR implements the ability to be able to call trait methods such as `Default::default()` where previously we required `StructName::default()`. The specific impl is selected via type inference. Previously, this resulted in a compiler panic. ## Additional Context When a trait method's type isn't constrained enough or is otherwise still ambiguous after type inference, the compiler currently just selects the first trait implementation that matches. E.g. `let _ = Default::default();`. This is a separate issue, so I'll create a new issue for this. ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [x] **[Exceptional Case]** Documentation to be submitted in a separate PR. - I think traits are finally stable enough to start writing documentation for. I'm going to submit another PR to remove some of the experimental warnings the compiler has for traits, and with it add documentation for traits as well. This wouldn't stabilize all trait features (e.g. associated types are still unimplemented), but users will now be able to use basic traits with functions without warnings. Any unimplemented trait items (associated types again) will not be included in the documentation. # 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: kevaundray <kevtheappdev@gmail.com>
github-merge-queue bot
pushed a commit
that referenced
this issue
Jan 3, 2024
# Description ## Problem\* Working towards #2568 ## Summary\* This PR implements operator overloading through traits. This works for all operators in noir, including bitwise operators. The comparison operators `<`, `<=`, `>`, and `>=`, are notable in that their corresponding function `cmp` returns an `Ordering` object rather than a boolean as the operators themselves do. ## Additional Context There is a bug when using static trait function syntax `Default::default` or operator overloading when the trait has generic methods. I'm considering this a separate bug, although for the moment it prevents us from being able to use e.g. the `Eq` trait for arrays. There is a boolean in `type_check/expr.rs` that determines if we use a trait impl or primitive implementation of each operator and because of this bug I've kept the primitive implementations for string and array equality. ## Documentation\* Check one: - [ ] No documentation needed. - [x] Documentation included in this PR. - [ ] **[Exceptional Case]** 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: Tom French <tom@tomfren.ch> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Added a "Bugs" section to the original Issue with latest ones @jfecher gathered. |
I've made issues for all the remaining items. They are:
Of these, only #4538 is a major item. The rest are mostly small syntactic shorthands which would be nice to have. #4539 is to some degree necessary, but only once we have #4538. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a tracking issue for the implementation of traits.
Noir Traits Roadmap
Note: Traits are a huge feature, and this list is by no means final. Expect more steps to be added along the way.
Parser
Parser (optional)
Def collector
Name resolution/Type checking
Self::
feat(traits): Improve support for traits static method resolution #2958self.
. Test: chore(traits): added exhaustive test for trait function calls #2918T::
(generic type) feat(traits): Improve support for traits static method resolution #2958v.
(method invocation) (TODO: tests?)<TypeName as TraitName>::
TraitName::
(works only when the method has a Self parameter. Type inference is used to determine which implementation to use.)Monomorphization
Support generic traits
Implement builtin traits
Support combining of traits
Testing
Bugs
The text was updated successfully, but these errors were encountered: