-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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: Take prelude into account when resolving paths #19157
Conversation
f5a7f97
to
905ee47
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 enhances path resolution in Rust by incorporating the standard library prelude and improved handling of $crate
macro paths.
- Introduces additional test cases in a new module (m21) that exercise the resolution of unit variant enums and unit structs.
- Adjusts usage patterns in the test code to reflect QL resolution expectations regarding the Rust prelude and macro expansion.
Files not reviewed (19)
- rust/ql/integration-tests/hello-project/summary.expected: Language not supported
- rust/ql/integration-tests/hello-workspace/summary.cargo.expected: Language not supported
- rust/ql/integration-tests/hello-workspace/summary.rust-project.expected: Language not supported
- rust/ql/lib/codeql/rust/dataflow/internal/Content.qll: Language not supported
- rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll: Language not supported
- rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll: Language not supported
- rust/ql/lib/codeql/rust/elements/internal/EnumImpl.qll: Language not supported
- rust/ql/lib/codeql/rust/elements/internal/PathImpl.qll: Language not supported
- rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll: Language not supported
- rust/ql/lib/codeql/rust/internal/CachedStages.qll: Language not supported
- rust/ql/lib/codeql/rust/internal/PathResolution.qll: Language not supported
- rust/ql/lib/codeql/rust/internal/PathResolutionConsistency.qll: Language not supported
- rust/ql/lib/codeql/rust/internal/Type.qll: Language not supported
- rust/ql/lib/codeql/rust/internal/TypeInference.qll: Language not supported
- rust/ql/test/extractor-tests/canonical_path/CONSISTENCY/PathResolutionConsistency.expected: Language not supported
- rust/ql/test/extractor-tests/canonical_path_disabled/CONSISTENCY/PathResolutionConsistency.expected: Language not supported
- rust/ql/test/library-tests/path-resolution/CONSISTENCY/PathResolutionConsistency.expected: Language not supported
- rust/ql/test/library-tests/path-resolution/path-resolution.expected: Language not supported
- rust/ql/test/library-tests/path-resolution/path-resolution.ql: Language not supported
Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more
|
||
fn f() { | ||
let _ = MyEnum::A; // $ item=I104 | ||
let _ = MyStruct {}; // $ item=I106 |
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.
MyStruct is defined as a unit struct; therefore, it should be instantiated without braces. Please update the instantiation to 'let _ = MyStruct;'.
let _ = MyStruct {}; // $ item=I106 | |
let _ = MyStruct; // $ item=I106 |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
905ee47
to
02e9795
Compare
02e9795
to
f4e9382
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.
Looks great. I only have one small comment and a question.
@@ -171,17 +173,22 @@ abstract class ItemNode extends Locatable { | |||
} | |||
|
|||
/** Gets a successor named `name` of this item, if any. */ | |||
pragma[nomagic] | |||
cached |
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.
Did something change in this PR that means getASuccessor
should now be cached? Or would it already have made sense to cache it prior to this PR?
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 it already made sense prior to this PR since the type inference stage relies on the predicate.
Co-authored-by: Simon Friis Vindum <paldepind@github.com>
This PR started out with me wanting to get rid of the
VariantInLib
workaround, which was needed prior to extracting the crate graph.Removing
VariantLib
means we will be using our QL logic for resolvingoption::Option
andresult::Result
paths, instead of relying ongetExtendedCanonicalPath
provided by the extractor. However, in order to resolve those paths, we need to take the standard library prelude into account, which is exactly what this PR does.Since we don't know which edition of Rust is being used, we simply include all the editions; 2015, 2018, 2021, and 2024.
Removing
VariantLib
also revealed that we need to handle$crate
paths inside expanded macros. For now, we over-approximate resolution of$crate
paths by considering all transitive dependencies.DCA shows that, while we mostly maintain performance, we gain an additional 10% true positive call edges (up 475,373 from 430,130) and an additional 14% true positive resolved paths (up 368,369 from 324,251), all numbers computed across the entire DCA suite.