-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Refactor using shared constraint satisfaction #20682
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
eb1e8b1 to
04b0ed6
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 refactors the AssocFunctionType implementation in Rust type inference to reuse constraint satisfaction functionality from the shared library. The main change simplifies the handling of specialized function types for traits and impl blocks by leveraging existing BaseTypes utilities instead of custom recursive logic.
Key Changes:
- Refactored
AssocFunctionTypefrom a union type with inheritance logic to a simpler single constructor with a helper predicate - Replaced custom type parameter resolution with shared library's
BaseTypes::conditionSatisfiesConstraintTypeAt - Updated all call sites to match the new signature ordering
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| shared/typeinference/codeql/typeinference/internal/TypeInference.qll | Exposed BaseTypes module by changing from private to public visibility |
| rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll | Major refactor of AssocFunctionType to use shared library constraint satisfaction logic |
| rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll | Updated calls to assocFunctionTypeAt to match new return value instead of out parameter |
| rust/ql/lib/codeql/rust/internal/TypeInference.qll | Updated calls to appliesTo to match new parameter ordering |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll
Outdated
Show resolved
Hide resolved
| pragma[nomagic] | ||
| private predicate hasSelfTypeParameterAt(TypePath path) { | ||
| this.getTypeParameterAt(path) = TSelfTypeParameter(_) | ||
| predicate appliesTo(Function f, ImplOrTraitItemNode i, FunctionPosition pos) { |
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.
I changed the parameter order here to match assocFunctionTypeAt.
Co-authored-by: Copilot <[email protected]>
|
|
||
| /** Provides logic related to base types. */ | ||
| private module BaseTypes { | ||
| module BaseTypes { |
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.
Making BaseTypes public was the simples way to get the needed predicates. We could also more surgically export the needed functions, but I'm not sure if that's worth the trouble.
Some of the code for
AssocFunctionTypereminded me a bit of what we have for constraint satisfaction in the shared library. This PR is a small refactor to reuse that functionality.