Skip to content
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

Improve trait resolution #1031

Merged
merged 8 commits into from
Oct 24, 2024
Merged

Conversation

Nadrieril
Copy link
Collaborator

This continues my work in cleaning up trait resolution. Of particular importance is the clarification of "required" vs "implied" predicates: required predicates must be proven to mention an item (e.g. one must prove T: Sized to mention Option<T>) whereas implied predicates are implied by the item being present in a signature (e.g. T: Copy implies T: Clone).

So far we consider all predicates on a trait declaration to be implied, but that's not what rustc does. For example:

trait Foo<T: Clone>: ToString {}

Here (according to rustc) T: Clone is required to mention Foo, and Self: ToString is implied by Self: Foo. I don't know if considering T: Clone as implied (like we implicitly did today) could cause problems but at least now what's happening is clear.

@W95Psp
Copy link
Collaborator

W95Psp commented Oct 24, 2024

Thanks! So if I understand correctly, while this notion of implied VS required predicates was sort of existing implicitly in hax, this PR makes them very explicit and clear, particularly with the traits::utils::implied_predicates and traits::utils::required_predicates?
That sounds pretty nice, and that makes the API of traits more clear!

The rest looks good to me, let's merge!

@W95Psp W95Psp enabled auto-merge October 24, 2024 06:27
@Nadrieril
Copy link
Collaborator Author

Yep, this was implicit previously, for example we don't store impl exprs when we refer to a trait, but if we decided to represent required predicates for traits we'd have to do that.

@W95Psp W95Psp added this pull request to the merge queue Oct 24, 2024
Merged via the queue into cryspen:main with commit 96b4203 Oct 24, 2024
13 checks passed
@Nadrieril Nadrieril deleted the separate-trait-solver branch October 24, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants