Skip to content

Migrate Rust to shared control-flow graph - #22864

Draft
hvitved wants to merge 17 commits into
github:mainfrom
hvitved:hvitved-rust-shared-cfg
Draft

hvitved wants to merge 17 commits into
github:mainfrom
hvitved:hvitved-rust-shared-cfg

Conversation

@hvitved

@hvitved hvitved commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Rust still used its bespoke completion-tree and CFG-splitting implementation, which duplicated infrastructure now shared by other language frontends. This migrates Rust to the common codeql.controlflow.ControlFlowGraph framework so it can share the same CFG construction, consistency checks, and maintenance path.

Approach

  • Build the Rust CFG through the shared Make0/Make1/Make2 pipeline while preserving Rust-specific semantics for patterns, match, let-else, loops, value-carrying break, and ?.
  • Remove the legacy completion and splitting implementation and adapt the public CFG, basic-block, printing, and diagnostics APIs.
  • Update SSA and data-flow consumers to use the shared CFG's unique injects(...) relation for semantic AST associations.
  • Rework unreachable-code reporting for the shared CFG's reachable-only node model, including correct handling of returning macros and compile-time const/static declarations.

The generated CFG and basic-block baselines change substantially because the shared framework exposes canonical before, in, after, and conditional-after nodes.

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Oct 21, 2026
@hvitved
hvitved force-pushed the hvitved-rust-shared-cfg branch 5 times, most recently from 8cc8c5e to e171f3d Compare November 4, 2026 08:33
@hvitved
hvitved force-pushed the hvitved-rust-shared-cfg branch from e171f3d to c000f33 Compare November 4, 2026 13:01
*/

private import internal.MacroExprImpl
import codeql.rust.elements.AnyAttr
*/

private import internal.StructExprImpl
import codeql.rust.elements.AnyAttr

private import codeql.rust.elements.internal.generated.Synth
private import codeql.rust.elements.internal.generated.Raw
import codeql.rust.elements.AnyAttr

private import codeql.rust.elements.internal.generated.Synth
private import codeql.rust.elements.internal.generated.Raw
import codeql.rust.elements.AnyAttr
@hvitved
hvitved force-pushed the hvitved-rust-shared-cfg branch from c000f33 to 2cc249b Compare November 5, 2026 09:29
@hvitved
hvitved force-pushed the hvitved-rust-shared-cfg branch 2 times, most recently from 3a6c039 to 5cba2b8 Compare November 6, 2026 12:36
@hvitved
hvitved force-pushed the hvitved-rust-shared-cfg branch from 8dec1b0 to 7bc53c7 Compare November 12, 2026 19:17
hvitved and others added 4 commits November 16, 2026 14:54
Replace Rust's legacy completion and splitting CFG with the shared control-flow framework, and update downstream CFG consumers and tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Regenerate affected CFG expectations for the shared value-propagation behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Avoid propagating a tail expression directly to an async block expression across callable boundaries. The shared block handling already propagates block-tail values within the correct callable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hvitved
hvitved force-pushed the hvitved-rust-shared-cfg branch from 7bc53c7 to a8adc5c Compare November 16, 2026 13:55
hvitved and others added 9 commits November 16, 2026 15:07
Model nonempty match expressions and arms through the shared switch abstraction, retaining custom handling only for divergent empty matches.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Treat switch case bodies as value-propagating children so language adapters do not need their own hook.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The shared callable parameter flow and generic post-order traversal already model parameter patterns and self parameters.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Model Rust for expressions through the shared foreach abstraction and treat their compiler-enforced patterns as irrefutable.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
hvitved and others added 3 commits November 16, 2026 21:50
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Actions Analysis of GitHub Actions label Nov 17, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Actions Analysis of GitHub Actions C# Go Java Python Ruby Rust Pull requests that update Rust code Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants