Skip to content

Rust: Track closure types in data flow#21596

Open
hvitved wants to merge 2 commits intogithub:mainfrom
hvitved:rust/data-flow-closure-type
Open

Rust: Track closure types in data flow#21596
hvitved wants to merge 2 commits intogithub:mainfrom
hvitved:rust/data-flow-closure-type

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Mar 27, 2026

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.

@github-actions github-actions bot added C# Rust Pull requests that update Rust code DataFlow Library labels Mar 27, 2026
@hvitved hvitved force-pushed the rust/data-flow-closure-type branch 2 times, most recently from c460453 to 34024ad Compare April 7, 2026 14:36
@hvitved hvitved force-pushed the rust/data-flow-closure-type branch from 34024ad to 1c02766 Compare April 8, 2026 08:30
@hvitved hvitved force-pushed the rust/data-flow-closure-type branch from 1c02766 to 23f0810 Compare April 9, 2026 13:26
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Apr 10, 2026
@hvitved hvitved marked this pull request as ready for review April 10, 2026 12:05
@hvitved hvitved requested a review from a team as a code owner April 10, 2026 12:05
Copilot AI review requested due to automatic review settings April 10, 2026 12:05
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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 DataFlowType representation for closures (plus unknown/source-context-parameter types) and wires it into the Rust data flow generator, including getSourceContextParameterNodeType.
  • 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_wrap cases 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
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants