feat(lean): associated types with equality constraints#1806
Merged
Conversation
maximebuyse
requested changes
Dec 10, 2025
Contributor
maximebuyse
left a comment
There was a problem hiding this comment.
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
approved these changes
Dec 11, 2025
Contributor
maximebuyse
left a comment
There was a problem hiding this comment.
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 file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.