-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better graphviz output for SCCs and NLL constraints #123797
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,38 @@ use std::borrow::Cow; | |
use std::io::{self, Write}; | ||
|
||
use super::*; | ||
use itertools::Itertools; | ||
use rustc_graphviz as dot; | ||
use rustc_middle::ty::UniverseIndex; | ||
|
||
fn render_outlives_constraint(constraint: &OutlivesConstraint<'_>) -> String { | ||
match constraint.locations { | ||
Locations::All(_) => "All(...)".to_string(), | ||
Locations::Single(loc) => format!("{loc:?}"), | ||
} | ||
} | ||
|
||
fn render_universe(u: UniverseIndex) -> String { | ||
if u.is_root() { | ||
return "".to_string(); | ||
} | ||
|
||
format!("/{:?}", u) | ||
} | ||
Comment on lines
+13
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are only used once, so we can inline them in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, do you want this enough for me to open a new PR with that change? |
||
|
||
fn render_region_vid(rvid: RegionVid, regioncx: &RegionInferenceContext<'_>) -> String { | ||
let universe_str = render_universe(regioncx.region_definition(rvid).universe); | ||
|
||
let external_name_str = if let Some(external_name) = | ||
regioncx.region_definition(rvid).external_name.and_then(|e| e.get_name()) | ||
{ | ||
format!(" ({external_name})") | ||
} else { | ||
"".to_string() | ||
}; | ||
|
||
format!("{:?}{universe_str}{external_name_str}", rvid) | ||
} | ||
|
||
impl<'tcx> RegionInferenceContext<'tcx> { | ||
/// Write out the region constraint graph. | ||
|
@@ -46,10 +77,10 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> { | |
Some(dot::LabelText::LabelStr(Cow::Borrowed("box"))) | ||
} | ||
fn node_label(&'this self, n: &RegionVid) -> dot::LabelText<'this> { | ||
dot::LabelText::LabelStr(format!("{n:?}").into()) | ||
dot::LabelText::LabelStr(render_region_vid(*n, self.regioncx).into()) | ||
} | ||
fn edge_label(&'this self, e: &OutlivesConstraint<'tcx>) -> dot::LabelText<'this> { | ||
dot::LabelText::LabelStr(format!("{:?}", e.locations).into()) | ||
dot::LabelText::LabelStr(render_outlives_constraint(e).into()) | ||
} | ||
} | ||
|
||
|
@@ -96,8 +127,9 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for SccConstraints<'a, 'tcx> { | |
Some(dot::LabelText::LabelStr(Cow::Borrowed("box"))) | ||
} | ||
fn node_label(&'this self, n: &ConstraintSccIndex) -> dot::LabelText<'this> { | ||
let nodes = &self.nodes_per_scc[*n]; | ||
dot::LabelText::LabelStr(format!("{n:?} = {nodes:?}").into()) | ||
let nodes_str = | ||
self.nodes_per_scc[*n].iter().map(|n| render_region_vid(*n, self.regioncx)).join(", "); | ||
dot::LabelText::LabelStr(format!("SCC({n}) = {{{nodes_str}}}", n = n.as_usize()).into()) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might as well remove the ellipsis altogether, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered this as my first option, but felt uneasy about leaving something out without showing that’s what I’m doing. Otherwise I don’t think it’s a bad option!