(feat): def site analysis based on forward dataflow#9870
Conversation
PR SummaryLow Risk Overview Introduces file-based tests and fixtures for linear code, match arms, goto remappings, multi-output statements, and a regression test that ensures the analysis panics if any variable remains Reviewed by Cursor Bugbot for commit e0a55cc. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 21bf47f. Configure here.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21bf47fb36
ℹ️ 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".
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 1 file and all commit messages, and made 2 comments.
Reviewable status: 1 of 4 files reviewed, 4 unresolved discussions (waiting on eytan-starkware and TomerStarkware).
crates/cairo-lang-lowering/src/analysis/def_site.rs line 25 at r1 (raw file):
} impl fmt::Display for DefSites {
implement Debug for DefLocation and use the debug string of the derive here.
format!("{:#?}")
crates/cairo-lang-lowering/src/analysis/def_site.rs line 107 at r1 (raw file):
) { for &output in stmt.outputs() { self.def_sites[output.index()] = (block_id, stmt_idx + 1);
just use the DefLocation to begin with.
Code quote:
for &output in stmt.outputs() {
self.def_sites[output.index()] = (block_id, stmt_idx + 1);e9939df to
95e3604
Compare
21bf47f to
4cf78fb
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware made 3 comments.
Reviewable status: 1 of 4 files reviewed, 4 unresolved discussions (waiting on orizi and TomerStarkware).
crates/cairo-lang-lowering/src/analysis/def_site.rs line 25 at r1 (raw file):
Previously, orizi wrote…
implement Debug for
DefLocationand use the debug string of the derive here.
format!("{:#?}")
Done.
crates/cairo-lang-lowering/src/analysis/def_site.rs line 107 at r1 (raw file):
Previously, orizi wrote…
just use the DefLocation to begin with.
Done.
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 2 files, made 2 comments, and resolved 1 discussion.
Reviewable status: 2 of 4 files reviewed, 3 unresolved discussions (waiting on eytan-starkware and TomerStarkware).
crates/cairo-lang-lowering/src/analysis/def_site.rs line 25 at r1 (raw file):
Previously, eytan-starkware wrote…
Done.
i think you can just remove this entire impl and do 1 other suggestion I added instead
crates/cairo-lang-lowering/src/analysis/def_site_test.rs line 37 at r2 (raw file):
let lowering_str = formatted_lowered(db, Some(&lowered)); let result_str = DefSiteAnalysis::analyze(&lowered).to_string(); (lowering_str, result_str)
Suggestion:
(
formatted_lowered(db, Some(&lowered)),
format!("{:#?}", DefSiteAnalysis::analyze(&lowered).0
)4cf78fb to
27b79d7
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware made 2 comments.
Reviewable status: 2 of 4 files reviewed, 2 unresolved discussions (waiting on orizi and TomerStarkware).
crates/cairo-lang-lowering/src/analysis/def_site.rs line 25 at r1 (raw file):
Previously, orizi wrote…
i think you can just remove this entire impl and do 1 other suggestion I added instead
Agreed
crates/cairo-lang-lowering/src/analysis/def_site_test.rs line 37 at r2 (raw file):
let lowering_str = formatted_lowered(db, Some(&lowered)); let result_str = DefSiteAnalysis::analyze(&lowered).to_string(); (lowering_str, result_str)
Done.
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 3 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).
27b79d7 to
e0a55cc
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware reviewed 1 file and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).


Summary
Adds a
DefLocationenum and aDefSiteAnalysispass to the lowering analysis framework.DefLocationdistinguishes between variables defined at block entry (function parameters, goto remapping destinations, match arm bindings) and variables defined as outputs of a statement.DefSiteAnalysisimplements theDataflowAnalyzertrait using the existing forward dataflow framework and produces aDefSitesresult mapping each variable (by arena index) to itsDefLocation.Type of change
Please check one:
Why is this change needed?
Downstream optimization passes and semantic checks need to know where each variable in the lowered IR is first defined. Previously there was no dedicated analysis for this; callers had to reconstruct def-site information ad hoc. A shared, tested analysis avoids duplicated logic and provides a consistent representation.
What was the behavior or documentation before?
There was no
DefLocationtype and noDefSiteAnalysispass. Consumers of the lowered IR had no standard way to query where a variable was defined.What is the behavior or documentation after?
Calling
DefSiteAnalysis::analyze(lowered)returns aDefSitesvalue (aVec<DefLocation>indexed by variable arena index). Each entry is either:DefLocation::BlockEntry(block)— the variable is a function parameter, a goto remapping destination, or a match arm binding introduced at the entry ofblock.DefLocation::Statement((block, stmt_idx))— the variable is produced as an output of statementstmt_idxinblock.File-based tests covering linear functions, match arms, and goto remappings are included under
src/analysis/test_data/def_site.Related issue or discussion (if any)
Additional context
The
DefSiteAnalysisstate is accumulated globally (not per-block) because each variable has exactly one definition site in SSA-form lowered IR, so no per-block lattice state is needed. TheInfotype is()andmergeis a no-op.