-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Add SatisfiesConstraintInput
module in shared type inference
#19829
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
Merged
+130
−182
Conversation
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
CI failure is unrelated. |
aad400c
to
266d5c6
Compare
SatisfiesConstraintInput
in shared type inferenceSatisfiesConstraintInput
module in shared type inference
hvitved
requested changes
Jun 23, 2025
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.
Very nice refactor.
shared/typeinference/codeql/typeinference/internal/TypeInference.qll
Outdated
Show resolved
Hide resolved
shared/typeinference/codeql/typeinference/internal/TypeInference.qll
Outdated
Show resolved
Hide resolved
shared/typeinference/codeql/typeinference/internal/TypeInference.qll
Outdated
Show resolved
Hide resolved
shared/typeinference/codeql/typeinference/internal/TypeInference.qll
Outdated
Show resolved
Hide resolved
shared/typeinference/codeql/typeinference/internal/TypeInference.qll
Outdated
Show resolved
Hide resolved
266d5c6
to
60c27f8
Compare
hvitved
approved these changes
Jun 23, 2025
I have started a new DCA run. |
Thanks for the comments and thanks for starting DCA :) |
Latest DCA shows that the performance issue was fixed; merging. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
no-change-note-required
This PR does not need a change note
Rust
Pull requests that update Rust code
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 refactors the shared type inference library, it untangles the logic for figuring out whether a type tree implements a trait, such that we can expose that logic from the shared library. This is done by a new module called
SatisfiesConstraintInput
. This module can be used to figure out if and how the type of an AST nodes (or more generally anyHasTypeTree
) implements a given trait.I believe we can use this module for quite a few things in Rust:
for
loops likefor i of e { ... }
where the type ofi
depends on howe
implements theIntoIterator
trait.receiver
implementsTrait1
.Deref
trait we need to figure out whether the potentially deref'ed value implementsDeref
.Fn
,FnOnce
, etc.foo.await
we must know iffoo
implementsFuture
.To show that this works, the last item is carried out in this PR (results in a simplification compared to the current implementation that uses the
Matching
module).for
loops should also be pretty easy, but I didn't want to create conflicts with #19754.Below is an explanation of how this module can be used in the case of the iterator in a
for
loop:First we create a class that satisfies the
HasTypeTree
signature and which includes nodes that occur as the iterator in afor
loop:Then we create a modules that satisfies the
SatisfiesConstraint
signature. The signature only contains a predicate that for every type tree gives the traits that we're interested in that type tree satisfying:Now we can instantiate the module and get the type of
e
as an implementation of theIntoIterator
trait:This should make it possible to type
for
loops over any iterator type, which we could do following #19754.