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