18
18
/// For clarity, rename the graphviz crate locally to dot.
19
19
use graphviz as dot;
20
20
21
+ use hir:: def_id:: { DefId , DefIndex } ;
21
22
use ty:: { self , TyCtxt } ;
22
23
use middle:: region:: CodeExtent ;
23
24
use super :: Constraint ;
@@ -32,7 +33,6 @@ use std::fs::File;
32
33
use std:: io;
33
34
use std:: io:: prelude:: * ;
34
35
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
35
- use syntax:: ast;
36
36
37
37
fn print_help_message ( ) {
38
38
println ! ( "\
@@ -55,7 +55,7 @@ graphs will be printed. \n\
55
55
56
56
pub fn maybe_print_constraints_for < ' a , ' gcx , ' tcx > (
57
57
region_vars : & RegionVarBindings < ' a , ' gcx , ' tcx > ,
58
- subject_node : ast :: NodeId )
58
+ context : DefId )
59
59
{
60
60
let tcx = region_vars. tcx ;
61
61
@@ -64,9 +64,9 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
64
64
}
65
65
66
66
let requested_node = env:: var ( "RUST_REGION_GRAPH_NODE" )
67
- . ok ( ) . and_then ( |s| s. parse ( ) . map ( ast :: NodeId :: new) . ok ( ) ) ;
67
+ . ok ( ) . and_then ( |s| s. parse ( ) . map ( DefIndex :: new) . ok ( ) ) ;
68
68
69
- if requested_node. is_some ( ) && requested_node != Some ( subject_node ) {
69
+ if requested_node. is_some ( ) && requested_node != Some ( context . index ) {
70
70
return ;
71
71
}
72
72
@@ -98,7 +98,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
98
98
let mut new_str = String :: new ( ) ;
99
99
for c in output_template. chars ( ) {
100
100
if c == '%' {
101
- new_str. push_str ( & subject_node . to_string ( ) ) ;
101
+ new_str. push_str ( & context . index . as_usize ( ) . to_string ( ) ) ;
102
102
} else {
103
103
new_str. push ( c) ;
104
104
}
@@ -110,7 +110,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
110
110
} ;
111
111
112
112
let constraints = & * region_vars. constraints . borrow ( ) ;
113
- match dump_region_constraints_to ( tcx, constraints, & output_path) {
113
+ match dump_region_constraints_to ( tcx, context , constraints, & output_path) {
114
114
Ok ( ( ) ) => { }
115
115
Err ( e) => {
116
116
let msg = format ! ( "io error dumping region constraints: {}" , e) ;
@@ -122,6 +122,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
122
122
struct ConstraintGraph < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
123
123
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
124
124
graph_name : String ,
125
+ context : DefId ,
125
126
map : & ' a FxHashMap < Constraint < ' tcx > , SubregionOrigin < ' tcx > > ,
126
127
node_ids : FxHashMap < Node < ' tcx > , usize > ,
127
128
}
@@ -142,6 +143,7 @@ enum Edge<'tcx> {
142
143
impl < ' a , ' gcx , ' tcx > ConstraintGraph < ' a , ' gcx , ' tcx > {
143
144
fn new ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
144
145
name : String ,
146
+ context : DefId ,
145
147
map : & ' a ConstraintMap < ' tcx > )
146
148
-> ConstraintGraph < ' a , ' gcx , ' tcx > {
147
149
let mut i = 0 ;
@@ -159,17 +161,18 @@ impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
159
161
add_node ( n2) ;
160
162
}
161
163
162
- tcx. region_maps ( ) . each_encl_scope ( |sub, sup| {
164
+ tcx. region_maps ( context ) . each_encl_scope ( |sub, sup| {
163
165
add_node ( Node :: Region ( ty:: ReScope ( sub) ) ) ;
164
166
add_node ( Node :: Region ( ty:: ReScope ( sup) ) ) ;
165
167
} ) ;
166
168
}
167
169
168
170
ConstraintGraph {
169
- tcx : tcx,
171
+ tcx,
172
+ context,
173
+ map,
174
+ node_ids,
170
175
graph_name : name,
171
- map : map,
172
- node_ids : node_ids,
173
176
}
174
177
}
175
178
}
@@ -245,7 +248,8 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
245
248
fn edges ( & self ) -> dot:: Edges < Edge < ' tcx > > {
246
249
debug ! ( "constraint graph has {} edges" , self . map. len( ) ) ;
247
250
let mut v: Vec < _ > = self . map . keys ( ) . map ( |e| Edge :: Constraint ( * e) ) . collect ( ) ;
248
- self . tcx . region_maps ( ) . each_encl_scope ( |sub, sup| v. push ( Edge :: EnclScope ( sub, sup) ) ) ;
251
+ self . tcx . region_maps ( self . context )
252
+ . each_encl_scope ( |sub, sup| v. push ( Edge :: EnclScope ( sub, sup) ) ) ;
249
253
debug ! ( "region graph has {} edges" , v. len( ) ) ;
250
254
Cow :: Owned ( v)
251
255
}
@@ -264,13 +268,14 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
264
268
pub type ConstraintMap < ' tcx > = FxHashMap < Constraint < ' tcx > , SubregionOrigin < ' tcx > > ;
265
269
266
270
fn dump_region_constraints_to < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
271
+ context : DefId ,
267
272
map : & ConstraintMap < ' tcx > ,
268
273
path : & str )
269
274
-> io:: Result < ( ) > {
270
275
debug ! ( "dump_region_constraints map (len: {}) path: {}" ,
271
276
map. len( ) ,
272
277
path) ;
273
- let g = ConstraintGraph :: new ( tcx, format ! ( "region_constraints" ) , map) ;
278
+ let g = ConstraintGraph :: new ( tcx, format ! ( "region_constraints" ) , context , map) ;
274
279
debug ! ( "dump_region_constraints calling render" ) ;
275
280
let mut v = Vec :: new ( ) ;
276
281
dot:: render ( & g, & mut v) . unwrap ( ) ;
0 commit comments