@@ -6,7 +6,38 @@ use std::borrow::Cow;
6
6
use std:: io:: { self , Write } ;
7
7
8
8
use super :: * ;
9
+ use itertools:: Itertools ;
9
10
use 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
+ }
10
41
11
42
impl < ' tcx > RegionInferenceContext < ' tcx > {
12
43
/// Write out the region constraint graph.
@@ -46,10 +77,10 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> {
46
77
Some ( dot:: LabelText :: LabelStr ( Cow :: Borrowed ( "box" ) ) )
47
78
}
48
79
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 ( ) )
50
81
}
51
82
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 ( ) )
53
84
}
54
85
}
55
86
@@ -96,8 +127,9 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for SccConstraints<'a, 'tcx> {
96
127
Some ( dot:: LabelText :: LabelStr ( Cow :: Borrowed ( "box" ) ) )
97
128
}
98
129
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 ( ) )
101
133
}
102
134
}
103
135
0 commit comments