Skip to content

(feat): Creating forward analysis for the dataflow framework#9584

Open
eytan-starkware wants to merge 1 commit intoeytan_graphite/_refactor_updating_analysis_framework_to_be_easier_to_usefrom
eytan_graphite/_feat_creating_forward_analysis_for_the_dataflow_framework
Open

(feat): Creating forward analysis for the dataflow framework#9584
eytan-starkware wants to merge 1 commit intoeytan_graphite/_refactor_updating_analysis_framework_to_be_easier_to_usefrom
eytan_graphite/_feat_creating_forward_analysis_for_the_dataflow_framework

Conversation

@eytan-starkware
Copy link
Contributor

@eytan-starkware eytan-starkware commented Feb 1, 2026

Summary

Added a forward dataflow analysis framework to complement the existing backward analysis. This implementation traverses the control flow graph in topological order (from entry towards exits), processing statements in forward order within each block.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The codebase already had a backward dataflow analysis framework, but lacked a forward analysis counterpart. Forward analysis is essential for many compiler optimizations and static analyses that need to follow program execution flow from entry to exit points. This implementation enables writing analyzers that track information as it flows through the program in execution order.


What is the behavior or documentation after?

The PR adds:

  • A ForwardDataflowAnalysis class that traverses the CFG in topological order
  • Support for block/statement traversal, variable remapping, state distribution to match arms, and state joining
  • Comprehensive test cases demonstrating both block-level and statement-level analyses
  • Removed #[expect(dead_code)] attributes from the core analysis components that are now used

The implementation also includes two example analyzers in the test module:

  1. A block counter that demonstrates block-level analysis
  2. A reachability analyzer that tracks which blocks are reachable

Additional context

This implementation completes the dataflow analysis framework by providing both forward and backward analysis capabilities, which are fundamental building blocks for various compiler optimizations and static analyses.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

eytan-starkware commented Feb 1, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@eytan-starkware eytan-starkware marked this pull request as ready for review February 1, 2026 11:16
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c3949ebef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 100 to 114
/// Add incoming info and mark target ready if all predecessors have contributed.
fn add_and_maybe_ready(
&mut self,
target: BlockId,
info: TAnalyzer::Info,
ready: &mut Vec<BlockId>,
) {
self.incoming[target.0] = Some(info);
self.predecessor_counts[target.0] -= 1;

Choose a reason for hiding this comment

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

P1 Badge Merge incoming states at join points

At join points with multiple predecessors, this code overwrites any previously stored incoming state (self.incoming[target.0] = Some(info)) and never calls DataflowAnalyzer::merge, so only the last processed edge contributes to the block entry state. In a branching CFG where two paths converge, the earlier path’s info is silently dropped, producing incorrect analysis results even for acyclic graphs that otherwise fit the “topological order” assumption. The trait contract and module docs explicitly describe merging at convergence points, so this should merge with any existing incoming state (using the appropriate entry StatementLocation) instead of overwriting it.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_updating_analysis_framework_to_be_easier_to_use branch from 024ddbf to 2ad86bb Compare February 1, 2026 12:48
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_feat_creating_forward_analysis_for_the_dataflow_framework branch from 1c3949e to b09d4aa Compare February 1, 2026 12:48
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_feat_creating_forward_analysis_for_the_dataflow_framework branch from b09d4aa to b2daf3d Compare February 1, 2026 12:49
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_updating_analysis_framework_to_be_easier_to_use branch from 2ad86bb to 32bfb79 Compare February 1, 2026 12:49
Copy link
Contributor Author

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@eytan-starkware made 1 comment.
Reviewable status: 0 of 7 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware).

Comment on lines 100 to 114
/// Add incoming info and mark target ready if all predecessors have contributed.
fn add_and_maybe_ready(
&mut self,
target: BlockId,
info: TAnalyzer::Info,
ready: &mut Vec<BlockId>,
) {
self.incoming[target.0] = Some(info);
self.predecessor_counts[target.0] -= 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@orizi reviewed all commit messages and made 1 comment.
Reviewable status: 0 of 7 files reviewed, 2 unresolved discussions (waiting on @eytan-starkware and @TomerStarkware).


Cargo.toml line 149 at r2 (raw file):

sha2 = "0.10.9"
sha3 = "0.10.8"
smallvec = "1.15.1"

optimize later.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants