@@ -6,7 +6,38 @@ use std::borrow::Cow;
66use std:: io:: { self , Write } ;
77
88use super :: * ;
9+ use itertools:: Itertools ;
910use rustc_graphviz as dot;
11+ use rustc_middle:: ty:: UniverseIndex ;
12+
13+ fn render_outlives_constraint ( constraint : & OutlivesConstraint < ' _ > ) -> String {
14+ match constraint. locations {
15+ Locations :: All ( _) => "All(...)" . to_string ( ) ,
16+ Locations :: Single ( loc) => format ! ( "{loc:?}" ) ,
17+ }
18+ }
19+
20+ fn render_universe ( u : UniverseIndex ) -> String {
21+ if u. is_root ( ) {
22+ return "" . to_string ( ) ;
23+ }
24+
25+ format ! ( "/{:?}" , u)
26+ }
27+
28+ fn render_region_vid ( rvid : RegionVid , regioncx : & RegionInferenceContext < ' _ > ) -> String {
29+ let universe_str = render_universe ( regioncx. region_definition ( rvid) . universe ) ;
30+
31+ let external_name_str = if let Some ( external_name) =
32+ regioncx. region_definition ( rvid) . external_name . and_then ( |e| e. get_name ( ) )
33+ {
34+ format ! ( " ({external_name})" )
35+ } else {
36+ "" . to_string ( )
37+ } ;
38+
39+ format ! ( "{:?}{universe_str}{external_name_str}" , rvid)
40+ }
1041
1142impl < ' tcx > RegionInferenceContext < ' tcx > {
1243 /// Write out the region constraint graph.
@@ -46,10 +77,10 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> {
4677 Some ( dot:: LabelText :: LabelStr ( Cow :: Borrowed ( "box" ) ) )
4778 }
4879 fn node_label ( & ' this self , n : & RegionVid ) -> dot:: LabelText < ' this > {
49- dot:: LabelText :: LabelStr ( format ! ( "{n:?}" ) . into ( ) )
80+ dot:: LabelText :: LabelStr ( render_region_vid ( * n , self . regioncx ) . into ( ) )
5081 }
5182 fn edge_label ( & ' this self , e : & OutlivesConstraint < ' tcx > ) -> dot:: LabelText < ' this > {
52- dot:: LabelText :: LabelStr ( format ! ( "{:?}" , e . locations ) . into ( ) )
83+ dot:: LabelText :: LabelStr ( render_outlives_constraint ( e ) . into ( ) )
5384 }
5485}
5586
@@ -96,8 +127,9 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for SccConstraints<'a, 'tcx> {
96127 Some ( dot:: LabelText :: LabelStr ( Cow :: Borrowed ( "box" ) ) )
97128 }
98129 fn node_label ( & ' this self , n : & ConstraintSccIndex ) -> dot:: LabelText < ' this > {
99- let nodes = & self . nodes_per_scc [ * n] ;
100- dot:: LabelText :: LabelStr ( format ! ( "{n:?} = {nodes:?}" ) . into ( ) )
130+ let nodes_str =
131+ self . nodes_per_scc [ * n] . iter ( ) . map ( |n| render_region_vid ( * n, self . regioncx ) ) . join ( ", " ) ;
132+ dot:: LabelText :: LabelStr ( format ! ( "SCC({n}) = {{{nodes_str}}}" , n = n. as_usize( ) ) . into ( ) )
101133 }
102134}
103135
0 commit comments