-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Remove restriction that blanket(-like) impls must have a constraint #21168
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?
Rust: Remove restriction that blanket(-like) impls must have a constraint #21168
Conversation
326464f to
f7df602
Compare
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 removes the restriction that blanket implementations must have constraints, enabling resolution of calls like impl<T> From<T> for T. The change improves call target resolution by allowing blanket implementations when no compatible non-blanket targets exist, preventing ambiguous call targets through a specialization-aware disambiguation strategy.
Changes:
- Modified type inference logic to handle blanket implementations without constraints
- Added new predicate to check if arguments are NOT instantiations of function parameters
- Extended blanket implementation constraint checking to handle unconstrained type parameters
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/test/library-tests/type-inference/main.rs | Updated test comment to expect call target resolution for blanket impl |
| rust/ql/test/library-tests/dataflow/local/main.rs | Updated comments to reflect new flow summaries for reflexive From and Into implementations |
| rust/ql/test/library-tests/dataflow/local/inline-flow.expected | Added new flow summaries for Into trait and updated MaD references to reflect new model numbering |
| rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll | Added disambiguation logic to prefer non-blanket implementations and check for type parameter constraints |
| rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll | Renamed module and added predicate to detect non-matching type instantiations |
| rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll | Extended sibling detection to handle multiple blanket implementations |
| rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll | Extended constraint satisfaction to handle blanket impls without non-trivial constraints |
| rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll | Added flow summary for reflexive From implementation that preserves values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll
Outdated
Show resolved
Hide resolved
rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll
Show resolved
Hide resolved
f7df602 to
fd309d6
Compare
paldepind
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.
Very nice improvements to the number of resolved calls!
rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll
Outdated
Show resolved
Hide resolved
rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll
Outdated
Show resolved
Hide resolved
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll
Outdated
Show resolved
Hide resolved
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll
Outdated
Show resolved
Hide resolved
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.
LGTM!
(there are some CI failures but they look unrelated?)
ee85c9e to
f76d85c
Compare
Before this PR, blanket implementations without constraints, such as
impl<T> From<T> for T, were ignored, because they would give rise to too many calls with multiple call targets.This PR changes that, and avoids multiple targets by only allowing blanket targets when no compatible non-blanket targets exist (we already had this check in place for method calls).
DCA looks good:
Percentage of calls with call targetincreases by 1.5 % point and performance is more or less unchanged.