Skip to content

C++: Speed up forwards logic - #23022

Open
MathiasVP wants to merge 4 commits into
github:mainfrom
MathiasVP:replace-ql-models-with-mad-for-assoc-cleaned-up-step-3
Open

MathiasVP wants to merge 4 commits into
github:mainfrom
MathiasVP:replace-ql-models-with-mad-for-assoc-cleaned-up-step-3

Conversation

@MathiasVP

@MathiasVP MathiasVP commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

The forwarding logic did essentially this:

predicate typeConversion(TypeState s1, TypeState s2) { ... }

predicate fwd(TypeState s) {
  isSource(s)
  or
  exists(TypeState s0 |
    fwd(s0) and
    typeConversion(s0, s)
  )
}

predicate rev(TypeState s) {
  fwd(s) and
  (
    isSink(s)
    or
    exists(TypeState s1 |
      rev(s1) and
      typeConversion(s, s1)
    )
  )
}

but it turns out some of the typeConversion steps are rather large relations. So this PR puts appropriate bindingset annotations on the large relations to prevent a tuple explosion.

Additionally, TypeState consisted of 4 columns (Type, ValueCategory, Boolean, Phase) which were very hard to relate in any way other than through cartesian products. To fix that, this PR also delays construction of the TypeState until after the fwd phase. We can then construct the TypeState IPA based on the tuples that are included in the fwd relation.

Commit-by-commit review recommended.

Since we don't have any non-test forwards models yet I don't think there's a need to run DCA on this PR.

Instead we:
1. first do a forward pass to first compute all the reachable
type states, and then
2. define the `TypeState` type.

This commit does (1). The next commit does (2).
@MathiasVP
MathiasVP requested a review from a team as a code owner November 4, 2026 22:29
Copilot AI auto review requested due to automatic review settings November 4, 2026 22:30
@MathiasVP MathiasVP added C++ no-change-note-required This PR does not need a change note labels Nov 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the constructor-forwarding analysis optimization.

No open issues 🎉

What changed in this PR

Optimizes C++ constructor-forwarding analysis to limit intermediate tuple growth during type conversions.

Changes:

  • Adds bindingset annotations to constrain large conversion relations.
  • Computes forward reachability using separate state components, then constructs TypeState values only for reachable tuples.
  • Centralizes conversion transitions in typeStep for use by forward and reverse traversal.
File Description
cpp/​ql/​lib/​semmle/​code/​cpp/​dataflow/​ExternalFlow.qll Refactors forwarding-state traversal and constrains conversion relations to improve evaluation performance.

Review effort: Max (auto)

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

C++ no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants