-
Notifications
You must be signed in to change notification settings - Fork 45
feat(lean): associated types with equality constraints #1806
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
Conversation
maximebuyse
left a comment
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.
This looks good though it is a bit hard to review backend code so we should make sure there is enough testing. Can you update the snapshots so that we can see the results of the tests you added? This should also fix the CI!
78007ad to
a0e7ee2
Compare
maximebuyse
left a comment
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.
I added a few suggestions to improve the style, but otherwise this looks fine. Trying this on Core models could be the best way to test if it really does what we want!
37296a8 to
a195845
Compare
a195845 to
024f6a1
Compare
This PR implements associated types with equality constraints for the Lean backend.
This fixes one part of #1710. Some uses of associated types such as
(A as T)::Bare not supported.Implementation Details
Problem
Associated types would be most straight-forwardly modeled by Lean type classes that contain fields of type
Type. However, Rust allows us to put equality constraints on associated types, for example in function definitions. This is hard to reproduce in Lean.Solution
For every Rust trait, we generate:
classthat contains the associated types of the Rust trait. This is just an empty struct if there are no associated types.classthat takes two parameters:Self : Typeand an instance of theclasscontaining the associated types. To make type inference work, we must mark the second parameter asoutParam. The class fields are all non-type fields of the Rust trait.Every function with a trait parameter will receive two parameters in Lean:
classclasscontaining the other fields, taking the associated typeclassinstance as a parameter. If equality constraints are present, we override fields in the associated typeclassinstance instance.