-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Model union, never, and pointer types #20516
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
Rust: Model union, never, and pointer types #20516
Conversation
633926e to
2a814dd
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 adds support for modeling union, never (!), and pointer types in Rust's type system. The changes enhance the type inference system to better handle these Rust type constructs, resulting in improved call resolution capabilities.
Key changes:
- Added new type representations for union, never, and pointer types to the type system
- Extended type mention resolution to handle these new type constructs
- Updated type inference logic to support pointer type parameters
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/internal/Type.qll | Adds UnionType, NeverType, and PtrType classes with their type parameters |
| rust/ql/lib/codeql/rust/internal/TypeMention.qll | Adds type mention classes for never and pointer type representations |
| rust/ql/lib/codeql/rust/internal/TypeInference.qll | Extends type inference to handle pointer type parameters |
| rust/ql/lib/codeql/rust/elements/internal/UnionImpl.qll | Adds getStructField method to Union class for field access |
| rust/ql/test/library-tests/type-inference/type-inference.expected | Test expectations updated to reflect improved never type inference |
| rust/ql/test/query-tests/security/CWE-770/CONSISTENCY/PathResolutionConsistency.expected | Test expectations for improved call resolution with pointer casts |
| rust/ql/test/query-tests/security/CWE-696/CONSISTENCY/PathResolutionConsistency.expected | Test expectations for improved call resolution with pointer operations |
| rust/ql/test/extractor-tests/macro-expansion/CONSISTENCY/TypeInferenceConsistency.expected | Removes previous type inference inconsistency for union types |
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.
One tiny comment, otherwise looks really good!
Co-authored-by: Simon Friis Vindum <paldepind@github.com>
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.
Nice! With this I think we have support for all forms of types in Rust (maybe with the exception of function pointer types) which is really great!
Extracted from #20282.
DCA looks good: increase in resolvable calls by
0.353 %points.