-
Notifications
You must be signed in to change notification settings - Fork 248
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
feat!: Allow impls on primitive types #847
Conversation
Nice! Will look at this when I get back |
Since this breaks a lot of noir code, we should push a release once this is merged so that we break less newer people's code. Alternatively, maybe we could slowly deprécate those functions which are now methods? |
I think some discussion on which functions should or should not be methods may also be helpful. Having |
Ah, also worth noting: this PR fixes #618 since for each loops now use |
I think for hash functions it feels more natural to have them as functions instead of methods, because unlike .len() there will be other implementations for a hash function that one may want to use, so theres nothing special about the current hash functions that we have in the stdlib, its just that they are the ones we had in our primary backend. |
Nice, should we kee the issue open and make it more general, since this would fix it for |
Alright, I'll change these methods back to functions then. Should reduce breakage in user code as a result. What are your thoughts on the
I think it is fine to close it. It was an issue because the for-each syntax desugared internally using |
I think
The snippet above feels natural to me as there is one implementation of this method for the Field type. Hashes feel separate from this and it would be awkward to have something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, I like the change.
+1 to Maxim's comment -- Field looks good already. Need to go back over the specific methods that were changed to methods on Field as there might be some that we only want to be on Field, which may break IntOrField variant. Just something that came OTOH so may not be a problem. An example would be if we had a method named |
Note that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM -- one nit regarding the if true, apart from that happy to merge
Did we decide whether we are going to merge this before a release or after? CI on the preprocess PR is almost finished |
Was going to merge your one first as the last non-breaking change and push a release. Then this PR along with the other breaking change from Tom would go into the next release which we can cut tomorrow or early next week. |
Related issue(s)
Resolves #736
Description
Allows impls on primitive types and changes several library functions into methods. This PR does not verify these primitive impls are in the stdlib only as I could not find a good method to do so.
Note that this PR is currently expected to break almost all noir code in its changing of library functions into methods.
Test additions / changes
Updates many tests to the new method syntax
Checklist
cargo fmt
with default settings.Additional context
What rule should we go by for which library functions should be methods and which (if any) should be free functions? So far, I've started by only making functions that take an argument of the same type into methods. This excludes nullary functions like
std::field::modulus_num_bits
for example.