Rust: Track closure types in data flow#21596
Open
hvitved wants to merge 2 commits intogithub:mainfrom
Open
Conversation
c460453 to
34024ad
Compare
34024ad to
1c02766
Compare
1c02766 to
23f0810
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Rust’s data flow implementation to incorporate closure “type” tracking (using closure expressions as unique type representatives) and adds support for the recently introduced getSourceContextParameterNodeType hook to improve precision in closure call resolution and source-call-context handling.
Changes:
- Introduces a
DataFlowTyperepresentation for closures (plus unknown/source-context-parameter types) and wires it into the Rust data flow generator, includinggetSourceContextParameterNodeType. - Refactors local must-flow steps (including explicit handling for parenthesized expressions) and integrates them into the generator’s must-flow logic.
- Extends the lambdas library test suite with
apply/apply_wrapcases and updates the expected inline-flow output accordingly.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll | Adds closure-aware data flow type support and the source-context-parameter type hook; refactors local must-flow stepping. |
| rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll | Adjusts type-inference Type import usage to avoid ambiguity and qualify RefType. |
| rust/ql/test/library-tests/dataflow/lambdas/main.rs | Adds new apply/apply_wrap closure-flow test cases and expectations. |
| rust/ql/test/library-tests/dataflow/lambdas/inline-flow.expected | Updates expected inline flow graph output for the expanded test coverage. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 1
Comment on lines
+99
to
+101
| apply_wrap(|x| sink(x), a); // $ hasValueFlow=79 $ SPURIOUS: hasValueFlow=80 | ||
| let b = source(80); | ||
| apply_wrap(|x| sink(x), b); // $ hasValueFlow=80 $ SPURIOUS: hasValueFlow=79 |
There was a problem hiding this comment.
The new $ SPURIOUS: inline expectations here don’t include a brief rationale. Adding a short -- ... explanation (like in other Rust tests) would make it clearer to future readers why these extra flows are currently accepted and what limitation they document.
Suggested change
| apply_wrap(|x| sink(x), a); // $ hasValueFlow=79 $ SPURIOUS: hasValueFlow=80 | |
| let b = source(80); | |
| apply_wrap(|x| sink(x), b); // $ hasValueFlow=80 $ SPURIOUS: hasValueFlow=79 | |
| apply_wrap(|x| sink(x), a); // $ hasValueFlow=79 $ SPURIOUS: hasValueFlow=80 -- analysis currently conflates flows across wrapped calls | |
| let b = source(80); | |
| apply_wrap(|x| sink(x), b); // $ hasValueFlow=80 $ SPURIOUS: hasValueFlow=79 -- analysis currently conflates flows across wrapped calls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With this PR we track the types of closures in data flow, which can help improve precision of closure call resolution. We also implement
getSourceContextParameterNodeType, which was introduced recently on #21592.