@@ -12,7 +12,6 @@ use rustc_data_structures::graph;
12
12
use cfg:: * ;
13
13
use middle:: region:: CodeExtent ;
14
14
use ty:: { self , TyCtxt } ;
15
- use syntax:: ast;
16
15
use syntax:: ptr:: P ;
17
16
18
17
use hir:: { self , PatKind } ;
@@ -30,13 +29,13 @@ struct CFGBuilder<'a, 'tcx: 'a> {
30
29
31
30
#[ derive( Copy , Clone ) ]
32
31
struct BlockScope {
33
- block_expr_id : ast :: NodeId , // id of breakable block expr node
32
+ block_expr_id : hir :: ItemLocalId , // id of breakable block expr node
34
33
break_index : CFGIndex , // where to go on `break`
35
34
}
36
35
37
36
#[ derive( Copy , Clone ) ]
38
37
struct LoopScope {
39
- loop_id : ast :: NodeId , // id of loop/while node
38
+ loop_id : hir :: ItemLocalId , // id of loop/while node
40
39
continue_index : CFGIndex , // where to go on a `loop`
41
40
break_index : CFGIndex , // where to go on a `break`
42
41
}
@@ -70,6 +69,7 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
70
69
cfg_builder. add_contained_edge ( body_exit, fn_exit) ;
71
70
let CFGBuilder { graph, .. } = cfg_builder;
72
71
CFG {
72
+ owner_def_id,
73
73
graph,
74
74
entry,
75
75
exit : fn_exit,
@@ -79,10 +79,10 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
79
79
impl < ' a , ' tcx > CFGBuilder < ' a , ' tcx > {
80
80
fn block ( & mut self , blk : & hir:: Block , pred : CFGIndex ) -> CFGIndex {
81
81
if blk. targeted_by_break {
82
- let expr_exit = self . add_ast_node ( blk. id , & [ ] ) ;
82
+ let expr_exit = self . add_ast_node ( blk. hir_id . local_id , & [ ] ) ;
83
83
84
84
self . breakable_block_scopes . push ( BlockScope {
85
- block_expr_id : blk. id ,
85
+ block_expr_id : blk. hir_id . local_id ,
86
86
break_index : expr_exit,
87
87
} ) ;
88
88
@@ -104,21 +104,22 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
104
104
105
105
let expr_exit = self . opt_expr ( & blk. expr , stmts_exit) ;
106
106
107
- self . add_ast_node ( blk. id , & [ expr_exit] )
107
+ self . add_ast_node ( blk. hir_id . local_id , & [ expr_exit] )
108
108
}
109
109
}
110
110
111
111
fn stmt ( & mut self , stmt : & hir:: Stmt , pred : CFGIndex ) -> CFGIndex {
112
+ let hir_id = self . tcx . hir . node_to_hir_id ( stmt. node . id ( ) ) ;
112
113
match stmt. node {
113
- hir:: StmtDecl ( ref decl, id ) => {
114
+ hir:: StmtDecl ( ref decl, _ ) => {
114
115
let exit = self . decl ( & decl, pred) ;
115
- self . add_ast_node ( id , & [ exit] )
116
+ self . add_ast_node ( hir_id . local_id , & [ exit] )
116
117
}
117
118
118
- hir:: StmtExpr ( ref expr, id ) |
119
- hir:: StmtSemi ( ref expr, id ) => {
119
+ hir:: StmtExpr ( ref expr, _ ) |
120
+ hir:: StmtSemi ( ref expr, _ ) => {
120
121
let exit = self . expr ( & expr, pred) ;
121
- self . add_ast_node ( id , & [ exit] )
122
+ self . add_ast_node ( hir_id . local_id , & [ exit] )
122
123
}
123
124
}
124
125
}
@@ -140,31 +141,31 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
140
141
PatKind :: Path ( _) |
141
142
PatKind :: Lit ( ..) |
142
143
PatKind :: Range ( ..) |
143
- PatKind :: Wild => self . add_ast_node ( pat. id , & [ pred] ) ,
144
+ PatKind :: Wild => self . add_ast_node ( pat. hir_id . local_id , & [ pred] ) ,
144
145
145
146
PatKind :: Box ( ref subpat) |
146
147
PatKind :: Ref ( ref subpat, _) |
147
148
PatKind :: Binding ( .., Some ( ref subpat) ) => {
148
149
let subpat_exit = self . pat ( & subpat, pred) ;
149
- self . add_ast_node ( pat. id , & [ subpat_exit] )
150
+ self . add_ast_node ( pat. hir_id . local_id , & [ subpat_exit] )
150
151
}
151
152
152
153
PatKind :: TupleStruct ( _, ref subpats, _) |
153
154
PatKind :: Tuple ( ref subpats, _) => {
154
155
let pats_exit = self . pats_all ( subpats. iter ( ) , pred) ;
155
- self . add_ast_node ( pat. id , & [ pats_exit] )
156
+ self . add_ast_node ( pat. hir_id . local_id , & [ pats_exit] )
156
157
}
157
158
158
159
PatKind :: Struct ( _, ref subpats, _) => {
159
160
let pats_exit = self . pats_all ( subpats. iter ( ) . map ( |f| & f. node . pat ) , pred) ;
160
- self . add_ast_node ( pat. id , & [ pats_exit] )
161
+ self . add_ast_node ( pat. hir_id . local_id , & [ pats_exit] )
161
162
}
162
163
163
164
PatKind :: Slice ( ref pre, ref vec, ref post) => {
164
165
let pre_exit = self . pats_all ( pre. iter ( ) , pred) ;
165
166
let vec_exit = self . pats_all ( vec. iter ( ) , pre_exit) ;
166
167
let post_exit = self . pats_all ( post. iter ( ) , vec_exit) ;
167
- self . add_ast_node ( pat. id , & [ post_exit] )
168
+ self . add_ast_node ( pat. hir_id . local_id , & [ post_exit] )
168
169
}
169
170
}
170
171
}
@@ -180,7 +181,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
180
181
match expr. node {
181
182
hir:: ExprBlock ( ref blk) => {
182
183
let blk_exit = self . block ( & blk, pred) ;
183
- self . add_ast_node ( expr. id , & [ blk_exit] )
184
+ self . add_ast_node ( expr. hir_id . local_id , & [ blk_exit] )
184
185
}
185
186
186
187
hir:: ExprIf ( ref cond, ref then, None ) => {
@@ -200,7 +201,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
200
201
//
201
202
let cond_exit = self . expr ( & cond, pred) ; // 1
202
203
let then_exit = self . expr ( & then, cond_exit) ; // 2
203
- self . add_ast_node ( expr. id , & [ cond_exit, then_exit] ) // 3,4
204
+ self . add_ast_node ( expr. hir_id . local_id , & [ cond_exit, then_exit] ) // 3,4
204
205
}
205
206
206
207
hir:: ExprIf ( ref cond, ref then, Some ( ref otherwise) ) => {
@@ -221,7 +222,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
221
222
let cond_exit = self . expr ( & cond, pred) ; // 1
222
223
let then_exit = self . expr ( & then, cond_exit) ; // 2
223
224
let else_exit = self . expr ( & otherwise, cond_exit) ; // 3
224
- self . add_ast_node ( expr. id , & [ then_exit, else_exit] ) // 4, 5
225
+ self . add_ast_node ( expr. hir_id . local_id , & [ then_exit, else_exit] ) // 4, 5
225
226
}
226
227
227
228
hir:: ExprWhile ( ref cond, ref body, _) => {
@@ -245,12 +246,12 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
245
246
let loopback = self . add_dummy_node ( & [ pred] ) ; // 1
246
247
247
248
// Create expr_exit without pred (cond_exit)
248
- let expr_exit = self . add_ast_node ( expr. id , & [ ] ) ; // 3
249
+ let expr_exit = self . add_ast_node ( expr. hir_id . local_id , & [ ] ) ; // 3
249
250
250
251
// The LoopScope needs to be on the loop_scopes stack while evaluating the
251
252
// condition and the body of the loop (both can break out of the loop)
252
253
self . loop_scopes . push ( LoopScope {
253
- loop_id : expr. id ,
254
+ loop_id : expr. hir_id . local_id ,
254
255
continue_index : loopback,
255
256
break_index : expr_exit
256
257
} ) ;
@@ -282,9 +283,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
282
283
// may cause additional edges.
283
284
284
285
let loopback = self . add_dummy_node ( & [ pred] ) ; // 1
285
- let expr_exit = self . add_ast_node ( expr. id , & [ ] ) ; // 2
286
+ let expr_exit = self . add_ast_node ( expr. hir_id . local_id , & [ ] ) ; // 2
286
287
self . loop_scopes . push ( LoopScope {
287
- loop_id : expr. id ,
288
+ loop_id : expr. hir_id . local_id ,
288
289
continue_index : loopback,
289
290
break_index : expr_exit,
290
291
} ) ;
@@ -295,7 +296,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
295
296
}
296
297
297
298
hir:: ExprMatch ( ref discr, ref arms, _) => {
298
- self . match_ ( expr. id , & discr, & arms, pred)
299
+ self . match_ ( expr. hir_id . local_id , & discr, & arms, pred)
299
300
}
300
301
301
302
hir:: ExprBinary ( op, ref l, ref r) if op. node . is_lazy ( ) => {
@@ -315,30 +316,30 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
315
316
//
316
317
let l_exit = self . expr ( & l, pred) ; // 1
317
318
let r_exit = self . expr ( & r, l_exit) ; // 2
318
- self . add_ast_node ( expr. id , & [ l_exit, r_exit] ) // 3,4
319
+ self . add_ast_node ( expr. hir_id . local_id , & [ l_exit, r_exit] ) // 3,4
319
320
}
320
321
321
322
hir:: ExprRet ( ref v) => {
322
323
let v_exit = self . opt_expr ( v, pred) ;
323
- let b = self . add_ast_node ( expr. id , & [ v_exit] ) ;
324
+ let b = self . add_ast_node ( expr. hir_id . local_id , & [ v_exit] ) ;
324
325
self . add_returning_edge ( expr, b) ;
325
326
self . add_unreachable_node ( )
326
327
}
327
328
328
329
hir:: ExprBreak ( destination, ref opt_expr) => {
329
330
let v = self . opt_expr ( opt_expr, pred) ;
330
- let ( scope_id , break_dest) =
331
+ let ( target_scope , break_dest) =
331
332
self . find_scope_edge ( expr, destination, ScopeCfKind :: Break ) ;
332
- let b = self . add_ast_node ( expr. id , & [ v] ) ;
333
- self . add_exiting_edge ( expr, b, scope_id , break_dest) ;
333
+ let b = self . add_ast_node ( expr. hir_id . local_id , & [ v] ) ;
334
+ self . add_exiting_edge ( expr, b, target_scope , break_dest) ;
334
335
self . add_unreachable_node ( )
335
336
}
336
337
337
338
hir:: ExprAgain ( destination) => {
338
- let ( scope_id , cont_dest) =
339
+ let ( target_scope , cont_dest) =
339
340
self . find_scope_edge ( expr, destination, ScopeCfKind :: Continue ) ;
340
- let a = self . add_ast_node ( expr. id , & [ pred] ) ;
341
- self . add_exiting_edge ( expr, a, scope_id , cont_dest) ;
341
+ let a = self . add_ast_node ( expr. hir_id . local_id , & [ pred] ) ;
342
+ self . add_exiting_edge ( expr, a, target_scope , cont_dest) ;
342
343
self . add_unreachable_node ( )
343
344
}
344
345
@@ -397,7 +398,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
397
398
hir:: ExprInlineAsm ( _, ref outputs, ref inputs) => {
398
399
let post_outputs = self . exprs ( outputs. iter ( ) . map ( |e| & * e) , pred) ;
399
400
let post_inputs = self . exprs ( inputs. iter ( ) . map ( |e| & * e) , post_outputs) ;
400
- self . add_ast_node ( expr. id , & [ post_inputs] )
401
+ self . add_ast_node ( expr. hir_id . local_id , & [ post_inputs] )
401
402
}
402
403
403
404
hir:: ExprClosure ( ..) |
@@ -444,10 +445,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
444
445
//! Handles case of an expression that evaluates `subexprs` in order
445
446
446
447
let subexprs_exit = self . exprs ( subexprs, pred) ;
447
- self . add_ast_node ( expr. id , & [ subexprs_exit] )
448
+ self . add_ast_node ( expr. hir_id . local_id , & [ subexprs_exit] )
448
449
}
449
450
450
- fn match_ ( & mut self , id : ast :: NodeId , discr : & hir:: Expr ,
451
+ fn match_ ( & mut self , id : hir :: ItemLocalId , discr : & hir:: Expr ,
451
452
arms : & [ hir:: Arm ] , pred : CFGIndex ) -> CFGIndex {
452
453
// The CFG for match expression is quite complex, so no ASCII
453
454
// art for it (yet).
@@ -552,8 +553,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
552
553
self . add_node ( CFGNodeData :: Dummy , preds)
553
554
}
554
555
555
- fn add_ast_node ( & mut self , id : ast:: NodeId , preds : & [ CFGIndex ] ) -> CFGIndex {
556
- assert ! ( id != ast:: DUMMY_NODE_ID ) ;
556
+ fn add_ast_node ( & mut self , id : hir:: ItemLocalId , preds : & [ CFGIndex ] ) -> CFGIndex {
557
557
self . add_node ( CFGNodeData :: AST ( id) , preds)
558
558
}
559
559
@@ -579,14 +579,13 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
579
579
fn add_exiting_edge ( & mut self ,
580
580
from_expr : & hir:: Expr ,
581
581
from_index : CFGIndex ,
582
- scope_id : ast :: NodeId ,
582
+ target_scope : CodeExtent ,
583
583
to_index : CFGIndex ) {
584
584
let mut data = CFGEdgeData { exiting_scopes : vec ! [ ] } ;
585
585
let mut scope = CodeExtent :: Misc ( from_expr. id ) ;
586
- let target_scope = CodeExtent :: Misc ( scope_id) ;
587
586
let region_maps = self . tcx . region_maps ( self . owner_def_id ) ;
588
587
while scope != target_scope {
589
- data. exiting_scopes . push ( scope. node_id ( ) ) ;
588
+ data. exiting_scopes . push ( self . tcx . hir . node_to_hir_id ( scope. node_id ( ) ) . local_id ) ;
590
589
scope = region_maps. encl_scope ( scope) ;
591
590
}
592
591
self . graph . add_edge ( from_index, to_index, data) ;
@@ -607,13 +606,13 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
607
606
fn find_scope_edge ( & self ,
608
607
expr : & hir:: Expr ,
609
608
destination : hir:: Destination ,
610
- scope_cf_kind : ScopeCfKind ) -> ( ast :: NodeId , CFGIndex ) {
609
+ scope_cf_kind : ScopeCfKind ) -> ( CodeExtent , CFGIndex ) {
611
610
612
611
match destination. target_id {
613
612
hir:: ScopeTarget :: Block ( block_expr_id) => {
614
613
for b in & self . breakable_block_scopes {
615
- if b. block_expr_id == block_expr_id {
616
- return ( block_expr_id, match scope_cf_kind {
614
+ if b. block_expr_id == self . tcx . hir . node_to_hir_id ( block_expr_id) . local_id {
615
+ return ( CodeExtent :: Misc ( block_expr_id) , match scope_cf_kind {
617
616
ScopeCfKind :: Break => b. break_index ,
618
617
ScopeCfKind :: Continue => bug ! ( "can't continue to block" ) ,
619
618
} ) ;
@@ -623,8 +622,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
623
622
}
624
623
hir:: ScopeTarget :: Loop ( hir:: LoopIdResult :: Ok ( loop_id) ) => {
625
624
for l in & self . loop_scopes {
626
- if l. loop_id == loop_id {
627
- return ( loop_id, match scope_cf_kind {
625
+ if l. loop_id == self . tcx . hir . node_to_hir_id ( loop_id) . local_id {
626
+ return ( CodeExtent :: Misc ( loop_id) , match scope_cf_kind {
628
627
ScopeCfKind :: Break => l. break_index ,
629
628
ScopeCfKind :: Continue => l. continue_index ,
630
629
} ) ;
0 commit comments