-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Shared: Make some generalizations in type inference library #20358
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR introduces generalizations in the type inference library to make it more flexible and abstract. It separates the constraint type from being limited to TypeMention
s and introduces a new state-aware matching module.
- Abstract the
IsInstantiationOfInput
signature to work with different constraint types instead of onlyTypeMention
s - Introduce
MatchingWithState
which extends the existingMatching
module to track state during type matching - Preserve backward compatibility by implementing the existing
Matching
module in terms ofMatchingWithState
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
shared/typeinference/codeql/typeinference/internal/TypeInference.qll | Core refactoring to generalize constraint types and add state-aware matching functionality |
rust/ql/lib/codeql/rust/internal/TypeInference.qll | Updates to use new generalized signature parameters in Rust-specific type inference implementation |
final private class FinalTypeMention = TypeMention; | ||
|
||
/** An adapter for type mentions to implement `HasTypeTreeSig`. */ | ||
final class TypeMentionTypeTree extends FinalTypeMention { | ||
Type getTypeAt(TypePath path) { result = this.resolveTypeAt(path) } | ||
} |
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.
[nitpick] This adapter class is defined early but only used later in the code. Consider moving this definition closer to where it's first used (around line 731) to improve code organization and readability.
Copilot uses AI. Check for mistakes.
private module Inp implements MatchingWithStateInputSig { | ||
private import codeql.util.Unit | ||
import Input | ||
|
||
predicate adjustAccessType = Input::adjustAccessType/6; | ||
|
||
class State = Unit; | ||
|
||
final private class AccessFinal = Input::Access; | ||
|
||
class Access extends AccessFinal { | ||
Type getInferredType(State state, AccessPosition apos, TypePath path) { | ||
exists(state) and | ||
result = super.getInferredType(apos, path) | ||
} | ||
|
||
Declaration getTarget(State state) { | ||
exists(state) and | ||
result = super.getTarget() | ||
} | ||
} | ||
} |
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.
The exists(state)
conditions in lines 1660 and 1665 are redundant since state
is bound by the method signature. These conditions don't provide any meaningful constraint and should be removed for clarity.
Copilot uses AI. Check for mistakes.
I'm trying to understand why a client of the |
Indeed, I tried that in my use case, but that resulted in non-monotonic recursion. |
I don't understand why putting it in Another suggestion, what about renaming |
Extracted from #20282:
IsInstantiationOfInput
, instead of limiting it toTypeMention
s.MatchingWithState
, which is likeMatching
, but allows for state to be tracked. This will eventually allow for us to get rid ofadjustAccessType
.DCA is uneventful.