Skip to content

lib: converge part2: logic to create value flow graphs and finding the value dominator#9543

Open
drieber wants to merge 1 commit into
mainfrom
push-zymvuwzoloqs
Open

lib: converge part2: logic to create value flow graphs and finding the value dominator#9543
drieber wants to merge 1 commit into
mainfrom
push-zymvuwzoloqs

Conversation

@drieber
Copy link
Copy Markdown
Contributor

@drieber drieber commented May 21, 2026

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added/updated tests to cover my changes
  • I fully understand the code that I am submitting (what it does,
    how it works, how it's organized), including any code drafted by an LLM.
  • For any prose generated by an LLM, I have proof-read and copy-edited with
    an eye towards deleting anything that is irrelevant, clarifying anything
    that is confusing, and adding details that are relevant. This includes,
    for example, commit descriptions, PR descriptions, and code comments.

@drieber drieber marked this pull request as ready for review May 21, 2026 19:21
@drieber drieber requested a review from a team as a code owner May 21, 2026 19:21
@drieber drieber mentioned this pull request May 21, 2026
6 tasks
Copy link
Copy Markdown
Contributor

@scott2000 scott2000 left a comment

Choose a reason for hiding this comment

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

Looks good to me overall


// Below is the implementation of value flow graphs and dominator value finding
// for FlowGraphs.
impl<N> FlowGraph<N>
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.

nit: it might be easier to read if these methods are moved into the existing impl block for FlowGraph

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.

I combined the two impl<N> FlowGraph<N> blocks into one by moving the new method into this block. Let me know if you prefer I put everything into the existing impl block (as you had suggested). At first I thought it is better later in the file, but I do not have a strong opinion about this.

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.

Normally I think it's nice to keep the impl block near the type declaration to make it easier to find, but I don't have a strong opinion. Another option would be to move the FlowGraph type later in the file as well.

.map_err(|e| FindDominatorValueError::ValueFnError(e))?;

// num_final_values is the number of *distinct* final values.
let final_values = value_cache.get_values();
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.

If I'm understanding correctly, it looks like this assumes that the value_cache is initially empty (or it only contains final nodes) before this function is called. Maybe it would be good to either document this assumption, or construct the ValueCache directly inside this function to ensure it's initially empty?

Or if find_dominator_value_with_value_cache isn't planned to be called directly, maybe it could be inlined into find_dominator_value instead.

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.

I don't assume value_cache is empty. The jj-converge library logic (in PR/9345) calls find_dominator_value_with_value_cache. find_dominator_value is only used in tests inside this file, but I made it public because it is a simpler API that could in theory be useful.

I improved the comment on top of find_dominator_value_with_value_cache a bit, but the comment does not say whether value_cache should be empty or not. I think there is no need to. But if you prefer I could add "Note that value_cache may or may not be empty."

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.

I'm still a bit confused. Based on the naming, it seems to me like final_values is supposed to contain only the values corresponding to final_nodes. However, if value_cache contains additional nodes beyond final_nodes, then final_values will also contain additional values I believe (but maybe I misunderstood).

If this behavior is intentional, maybe all_cached_values would be a better name than final_values, since that makes it more clear that they don't necessarily correspond to final_nodes?

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.

I see what you are saying. If the value_cache is not empty then the cardinality comparisons I am relying on may not make sense. That is a valid point. Probably the best way forward is to remove those optimizations from this PR, that can be added later if necessary. WDYT?

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.

That sounds good to me.

Comment thread lib/src/graph_dominators.rs Outdated
Comment thread lib/src/graph_dominators.rs Outdated
@drieber drieber force-pushed the push-zymvuwzoloqs branch from ffedc63 to d64ecaa Compare May 26, 2026 04:36
@drieber drieber enabled auto-merge May 26, 2026 04:54
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