Skip to content

Ssa: Refactor caching - #23011

Open
aschackmull wants to merge 3 commits into
github:mainfrom
aschackmull:ssa/caching
Open

aschackmull wants to merge 3 commits into
github:mainfrom
aschackmull:ssa/caching

Conversation

@aschackmull

@aschackmull aschackmull commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

This PR refactors SSA caching in two steps (2 separate commits). The SSA library consists of three main modules: Make, MakeSsa, and DataFlowIntegration. First, the main SSA computation of Make is cached directly in a newly constructed explicitly named cached stage. This means that all the languages that aren't using MakeSsa no longer need to do this caching. Second, the caching in all three modules is tied together via a cached-stage-reverse-reference predicate from the nested modules passed into Make. This means that the cached getARead no longer needs to be threaded through on the language-specific side.

The ssaCachedStageRevRef predicates were initially meant to be named without the 1,2 suffixes, but they were accidentally imported in common scopes in several places in Java and C#, which broke compilation, so that would have required a much bigger refactoring. Since they're just meant as internal names, the distinguishing suffixes was the simplest solution.

@aschackmull

Copy link
Copy Markdown
Contributor Author

Dca is uneventful.

@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Nov 5, 2026
@aschackmull
aschackmull marked this pull request as ready for review November 5, 2026 09:05
@aschackmull
aschackmull requested review from a team as code owners November 5, 2026 09:05
Copilot AI auto review requested due to automatic review settings November 5, 2026 09:05

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.

🟡 Changes recommended

Removing the cached overrides leaves getARead uncached, so query-specific barrier guards may recompute the reaching-definition/read/CFG join instead of reusing cached results.

2 open issues
What changed in this PR

Refactors static single assignment (SSA) caching into the shared library, reducing cache management in language-specific data-flow implementations.

Changes:

  • Adds an explicitly named cached stage for core SSA computation.
  • Links Make, MakeSsa, and DataFlowIntegration through reverse-reference hooks.
  • Removes redundant language-specific caching and moves read lookup into the shared integration module.
File Description
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​LocalSsa.qll Connects local SSA to the integration cache hook.
shared/​ssa/​codeql/​ssa/​Ssa.qll Centralizes SSA caching, adds hooks, and internalizes read lookup.
shared/​dataflow/​codeql/​dataflow/​VariableCapture.qll Connects capture SSA to the integration cache hook.
rust/​ql/​lib/​codeql/​rust/​dataflow/​Ssa.qll Calls shared phi-input and prior-definition predicates directly.
rust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​SsaImpl.qll Adds cache wiring and removes redundant wrappers.
ruby/​ql/​lib/​codeql/​ruby/​dataflow/​SSA.qll Calls shared prior-definition and phi-input predicates directly.
ruby/​ql/​lib/​codeql/​ruby/​dataflow/​internal/​SsaImpl.qll Adds cache wiring and removes redundant wrappers.
javascript/​ql/​lib/​semmle/​javascript/​dataflow/​internal/​sharedlib/​Ssa.qll Names the integration module and removes its read override.
java/​ql/​lib/​semmle/​code/​java/​dataflow/​internal/​SsaImpl.qll Connects both cache hooks and removes the read override.
java/​ql/​lib/​semmle/​code/​java/​dataflow/​internal/​BaseSSA.qll Connects base SSA to the MakeSsa cache hook.
go/​ql/​lib/​semmle/​go/​dataflow/​SsaImpl.qll Removes redundant caching annotations and related notes.
csharp/​ql/​lib/​semmle/​code/​csharp/​dataflow/​internal/​SsaImpl.qll Connects both cache hooks and removes the read override.
csharp/​ql/​lib/​semmle/​code/​csharp/​dataflow/​internal/​BaseSSA.qll Connects base SSA to the MakeSsa cache hook.
cpp/​ql/​lib/​semmle/​code/​cpp/​ir/​dataflow/​internal/​SsaImpl.qll Replaces the local cache module with shared caching.
cpp/​ql/​lib/​semmle/​code/​cpp/​ir/​dataflow/​internal/​DataFlowPrivate.qll Connects iterator SSA to the integration cache hook.

Review effort: Max (auto)

Comment thread shared/ssa/codeql/ssa/Ssa.qll Resolved
Comment on lines +68 to +70
* If `MakeSsa` and/or `DataFlowIntegration` is used, then this predicate
* should be instantiated with (the union of) their respective
* `ssaCachedStageRevRef` predicates.
}

/** Reverse references to the cached predicates in this module. */
predicate ssaCachedStageRevRef2() {

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.

Should this call ssaCachedStageRevRef1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it should just be a list of the cached predicates in this module, so they can be referenced from SsaCachedStage::revRef().

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# C++ DataFlow Library Go Java JS no-change-note-required This PR does not need a change note Ruby Rust Pull requests that update Rust code Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants