1818/// For clarity, rename the graphviz crate locally to dot.
1919use graphviz as dot;
2020
21+ use hir:: def_id:: { DefId , DefIndex } ;
2122use ty:: { self , TyCtxt } ;
2223use middle:: region:: CodeExtent ;
2324use super :: Constraint ;
@@ -32,7 +33,6 @@ use std::fs::File;
3233use std:: io;
3334use std:: io:: prelude:: * ;
3435use std:: sync:: atomic:: { AtomicBool , Ordering } ;
35- use syntax:: ast;
3636
3737fn print_help_message ( ) {
3838 println ! ( "\
@@ -55,7 +55,7 @@ graphs will be printed. \n\
5555
5656pub fn maybe_print_constraints_for < ' a , ' gcx , ' tcx > (
5757 region_vars : & RegionVarBindings < ' a , ' gcx , ' tcx > ,
58- subject_node : ast :: NodeId )
58+ context : DefId )
5959{
6060 let tcx = region_vars. tcx ;
6161
@@ -64,9 +64,9 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
6464 }
6565
6666 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 ( ) ) ;
6868
69- if requested_node. is_some ( ) && requested_node != Some ( subject_node ) {
69+ if requested_node. is_some ( ) && requested_node != Some ( context . index ) {
7070 return ;
7171 }
7272
@@ -98,7 +98,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
9898 let mut new_str = String :: new ( ) ;
9999 for c in output_template. chars ( ) {
100100 if c == '%' {
101- new_str. push_str ( & subject_node . to_string ( ) ) ;
101+ new_str. push_str ( & context . index . as_usize ( ) . to_string ( ) ) ;
102102 } else {
103103 new_str. push ( c) ;
104104 }
@@ -110,7 +110,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
110110 } ;
111111
112112 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) {
114114 Ok ( ( ) ) => { }
115115 Err ( e) => {
116116 let msg = format ! ( "io error dumping region constraints: {}" , e) ;
@@ -122,6 +122,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
122122struct ConstraintGraph < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
123123 tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
124124 graph_name : String ,
125+ context : DefId ,
125126 map : & ' a FxHashMap < Constraint < ' tcx > , SubregionOrigin < ' tcx > > ,
126127 node_ids : FxHashMap < Node < ' tcx > , usize > ,
127128}
@@ -142,6 +143,7 @@ enum Edge<'tcx> {
142143impl < ' a , ' gcx , ' tcx > ConstraintGraph < ' a , ' gcx , ' tcx > {
143144 fn new ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
144145 name : String ,
146+ context : DefId ,
145147 map : & ' a ConstraintMap < ' tcx > )
146148 -> ConstraintGraph < ' a , ' gcx , ' tcx > {
147149 let mut i = 0 ;
@@ -159,17 +161,18 @@ impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
159161 add_node ( n2) ;
160162 }
161163
162- tcx. region_maps ( ) . each_encl_scope ( |sub, sup| {
164+ tcx. region_maps ( context ) . each_encl_scope ( |sub, sup| {
163165 add_node ( Node :: Region ( ty:: ReScope ( sub) ) ) ;
164166 add_node ( Node :: Region ( ty:: ReScope ( sup) ) ) ;
165167 } ) ;
166168 }
167169
168170 ConstraintGraph {
169- tcx : tcx,
171+ tcx,
172+ context,
173+ map,
174+ node_ids,
170175 graph_name : name,
171- map : map,
172- node_ids : node_ids,
173176 }
174177 }
175178}
@@ -245,7 +248,8 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
245248 fn edges ( & self ) -> dot:: Edges < Edge < ' tcx > > {
246249 debug ! ( "constraint graph has {} edges" , self . map. len( ) ) ;
247250 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) ) ) ;
249253 debug ! ( "region graph has {} edges" , v. len( ) ) ;
250254 Cow :: Owned ( v)
251255 }
@@ -264,13 +268,14 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
264268pub type ConstraintMap < ' tcx > = FxHashMap < Constraint < ' tcx > , SubregionOrigin < ' tcx > > ;
265269
266270fn dump_region_constraints_to < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
271+ context : DefId ,
267272 map : & ConstraintMap < ' tcx > ,
268273 path : & str )
269274 -> io:: Result < ( ) > {
270275 debug ! ( "dump_region_constraints map (len: {}) path: {}" ,
271276 map. len( ) ,
272277 path) ;
273- let g = ConstraintGraph :: new ( tcx, format ! ( "region_constraints" ) , map) ;
278+ let g = ConstraintGraph :: new ( tcx, format ! ( "region_constraints" ) , context , map) ;
274279 debug ! ( "dump_region_constraints calling render" ) ;
275280 let mut v = Vec :: new ( ) ;
276281 dot:: render ( & g, & mut v) . unwrap ( ) ;
0 commit comments