-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Use type inference to insert implicit borrows and derefs #19419
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: Use type inference to insert implicit borrows and derefs #19419
Conversation
4158477
to
f584d22
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 logic for implicit borrows and dereferences by basing them on type inference instead of heuristics.
- Removed outdated expected summaries in tests and updated expected outputs accordingly.
- Modified the TypeInference module to use inferType(n) for determining receiver types and added new predicates for detecting implicit deref and borrow.
- Adjusted dataflow predicates to call the new TypeInference predicates.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
rust/ql/test/utils-tests/modelgenerator/CaptureSummaryModels.expected | Removed outdated expected summary lines to match the new model generation output. |
rust/ql/test/query-tests/security/CWE-089/SqlInjection.expected | Updated expected SQL injection summaries by removing duplicate/obsolete entries. |
rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected | Removed redundant "receiver" lines reflecting changes in implicit borrow/deref handling. |
rust/ql/lib/codeql/rust/internal/TypeInference.qll | Revised receiver type detection to use inferType(n) and added predicates for implicit borrow/dereference. |
rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll | Updated dataflow predicates to use the new TypeInference predicates for implicit dereference and borrow. |
@@ -690,7 +690,7 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) { | |||
| | |||
if apos.isSelf() | |||
then | |||
exists(Type receiverType | receiverType = CallExprBaseMatchingInput::inferReceiverType(n) | |
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 don't remember why it was done like this originally, but if it doesn't impact performance, this is fine, and we can now remove the two inferReceiverType
predicates.
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.
Yes, I forgot that. Done now :)
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.
Great to have a principled solution for this.
Removes the current heuristic for implicit borrows and derefs and determines these based on type inference instead.