- 
                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
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 BaseTypesmodule by changing from private to public visibility | 
| rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll | Major refactor of AssocFunctionTypeto use shared library constraint satisfaction logic | 
| rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll | Updated calls to assocFunctionTypeAtto match new return value instead of out parameter | 
| rust/ql/lib/codeql/rust/internal/TypeInference.qll | Updated calls to appliesToto match new parameter ordering | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| 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.
|  | ||
| /** 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.
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.
Could you investigate the changes in semantics? Perhaps it is all good, but we should verify.
| * `pos` at path `path` | ||
| */ | ||
| pragma[nomagic] | ||
| Type assocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition pos, TypePath 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.
I think getAssocFunctionTypeAt would be a better name.
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.
This remains to be addressed.
| } | ||
|  | ||
| bindingset[condition, constraint, tp] | ||
| private Type traitConstraintTypeAt( | 
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.
getTraitConstraintTypeAt.
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 still think this is a better name.
        
          
                rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll
              
                Outdated
          
            Show resolved
            Hide resolved
        
      3ceb033    to
    15bdb53      
    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.
LGTM, but I would still prefer to have the two predicates renamed.
| } | ||
|  | ||
| bindingset[condition, constraint, tp] | ||
| private Type traitConstraintTypeAt( | 
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 still think this is a better name.
| * `pos` at path `path` | ||
| */ | ||
| pragma[nomagic] | ||
| Type assocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition pos, TypePath 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.
This remains to be addressed.
15bdb53    to
    d50d6c7      
    Compare
  
    d50d6c7    to
    c648aa6      
    Compare
  
    
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.