Skip to content

refactor(interpreter): read analysis results through one view - #853

Merged
zhenrongliew merged 4 commits into
rustfrom
dl/analysis-results-view
Nov 11, 2026
Merged

zhenrongliew merged 4 commits into
rustfrom
dl/analysis-results-view

Conversation

@zhenrongliew

Copy link
Copy Markdown
Collaborator

One read-only way to read converged facts from all three abstract engines (constprop, demand, liveness).

  • analyze now returns Analyzed<Engine>: the converged state of exactly one
    analysis. It cannot run again, so every analysis is fresh and has one root.
  • AnalysisResults, implemented on Analyzed for each engine:
    • per context: root, contexts, callable_of, fact, facts, response
    • per callable (provided): callables, contexts_of, joined,
      joined_facts, joined_response
  • response(ctx) is what a context answers its caller: constprop's return
    product, demand's parameter facts, None for liveness.

Motivation

Engines computed facts for every value in every context, but clients could read only the root's result, through three different APIs, two of which copied. Constprop exposed no per-value facts at all.

Example

main():
  %a, %b = call @pair(1, 2)
  %c, %d = call @pair(3, 4)
  %s = add %a, %d
  ret %s

pair(%x, %y):
  %k = const 10
  %p = add %x, %k
  %q = add %y, %k
  ret %p, %q

Constprop:

Query API Answer
main’s return response(root()) [Const(25)]
%a in main fact(root(), %a) Const(11)
All facts in main facts(root()) %a = 11, %b = 12, %c = 13, %d = 14, %s = 25
Analyzed instances of pair contexts_of(pair) pair@[1, 2], pair@[3, 4]

A context distinguishes a callable by its argument values.
Within each pair context, fact(context, value) and response(context) give:

Context %x %y %k %p %q Response
pair@[1, 2] 1 2 10 11 12 [11, 12]
pair@[3, 4] 3 4 10 13 14 [13, 14]

Demand:

Query API Answer
Is %a needed? is_demanded(root(), %a) Yes
Is %b needed? is_demanded(root(), %b) No
Does main need any parameters? response(root()) [] — it has none
Analyzed instances of pair contexts_of(pair) pair@[Live, Dead], pair@[Dead, Live]

The first call needs %p; the second needs %q:

Context %p %x %q %y %k Parameter response
pair@[Live, Dead] Live Live Dead Dead Live [Live, Dead]
pair@[Dead, Live] Dead Dead Live Live Live [Dead, Live]

joined_fact(pair, value) combines demand across contexts: a value is live if any context needs it. Here, every value in pair is live in the combined result.

- Updated the analysis methods in the interpreter to return `Analyzed` states instead of raw results, enhancing clarity and consistency.
- Modified tests to accommodate the new analysis result structure, ensuring that the response extraction aligns with the updated API.
- Removed deprecated code related to previous analysis result handling, streamlining the codebase.
- Adjusted documentation to reflect changes in the analysis API and its usage across various modules.
@zhenrongliew
zhenrongliew requested review from Roger-luo, alexcgatea and planza-quera and a balanced review from Copilot November 10, 2026 16:36

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 11, 2026 15:36

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@alexcgatea
alexcgatea self-requested a review November 11, 2026 15:48

@alexcgatea alexcgatea left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@zhenrongliew
zhenrongliew merged commit 2958d85 into rust Nov 11, 2026
1 check passed
@zhenrongliew
zhenrongliew deleted the dl/analysis-results-view branch November 11, 2026 18:35
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