@@ -14,10 +14,9 @@ use crate::ty::{self, TyCtxt};
14
14
use crate :: ty:: query:: Providers ;
15
15
use crate :: middle:: privacy;
16
16
use crate :: session:: config;
17
- use crate :: util:: nodemap:: { NodeSet , FxHashSet } ;
17
+ use crate :: util:: nodemap:: { HirIdSet , FxHashSet } ;
18
18
19
19
use rustc_target:: spec:: abi:: Abi ;
20
- use syntax:: ast;
21
20
use crate :: hir;
22
21
use crate :: hir:: def_id:: LOCAL_CRATE ;
23
22
use crate :: hir:: intravisit:: { Visitor , NestedVisitorMap } ;
@@ -70,10 +69,10 @@ struct ReachableContext<'a, 'tcx: 'a> {
70
69
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
71
70
tables : & ' a ty:: TypeckTables < ' tcx > ,
72
71
// The set of items which must be exported in the linkage sense.
73
- reachable_symbols : NodeSet ,
72
+ reachable_symbols : HirIdSet ,
74
73
// A worklist of item IDs. Each item ID in this worklist will be inlined
75
74
// and will be scanned for further references.
76
- worklist : Vec < ast :: NodeId > ,
75
+ worklist : Vec < hir :: HirId > ,
77
76
// Whether any output of this compilation is a library
78
77
any_library : bool ,
79
78
}
@@ -104,27 +103,28 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
104
103
105
104
match def {
106
105
Some ( Def :: Local ( node_id) ) | Some ( Def :: Upvar ( node_id, ..) ) => {
107
- self . reachable_symbols . insert ( node_id) ;
106
+ let hir_id = self . tcx . hir ( ) . node_to_hir_id ( node_id) ;
107
+ self . reachable_symbols . insert ( hir_id) ;
108
108
}
109
109
Some ( def) => {
110
- if let Some ( ( node_id , def_id) ) = def. opt_def_id ( ) . and_then ( |def_id| {
111
- self . tcx . hir ( ) . as_local_node_id ( def_id) . map ( |node_id | ( node_id , def_id) )
110
+ if let Some ( ( hir_id , def_id) ) = def. opt_def_id ( ) . and_then ( |def_id| {
111
+ self . tcx . hir ( ) . as_local_hir_id ( def_id) . map ( |hir_id | ( hir_id , def_id) )
112
112
} ) {
113
113
if self . def_id_represents_local_inlined_item ( def_id) {
114
- self . worklist . push ( node_id ) ;
114
+ self . worklist . push ( hir_id ) ;
115
115
} else {
116
116
match def {
117
117
// If this path leads to a constant, then we need to
118
118
// recurse into the constant to continue finding
119
119
// items that are reachable.
120
120
Def :: Const ( ..) | Def :: AssociatedConst ( ..) => {
121
- self . worklist . push ( node_id ) ;
121
+ self . worklist . push ( hir_id ) ;
122
122
}
123
123
124
124
// If this wasn't a static, then the destination is
125
125
// surely reachable.
126
126
_ => {
127
- self . reachable_symbols . insert ( node_id ) ;
127
+ self . reachable_symbols . insert ( hir_id ) ;
128
128
}
129
129
}
130
130
}
@@ -204,14 +204,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
204
204
continue
205
205
}
206
206
207
- if let Some ( ref item) = self . tcx . hir ( ) . find ( search_item) {
207
+ if let Some ( ref item) = self . tcx . hir ( ) . find_by_hir_id ( search_item) {
208
208
self . propagate_node ( item, search_item) ;
209
209
}
210
210
}
211
211
}
212
212
213
213
fn propagate_node ( & mut self , node : & Node < ' tcx > ,
214
- search_item : ast :: NodeId ) {
214
+ search_item : hir :: HirId ) {
215
215
if !self . any_library {
216
216
// If we are building an executable, only explicitly extern
217
217
// types need to be exported.
@@ -221,7 +221,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
221
221
} else {
222
222
false
223
223
} ;
224
- let def_id = self . tcx . hir ( ) . local_def_id ( item. id ) ;
224
+ let def_id = self . tcx . hir ( ) . local_def_id_from_hir_id ( item. hir_id ) ;
225
225
let codegen_attrs = self . tcx . codegen_fn_attrs ( def_id) ;
226
226
let is_extern = codegen_attrs. contains_extern_indicator ( ) ;
227
227
let std_internal = codegen_attrs. flags . contains (
@@ -242,7 +242,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
242
242
Node :: Item ( item) => {
243
243
match item. node {
244
244
hir:: ItemKind :: Fn ( .., body) => {
245
- let def_id = self . tcx . hir ( ) . local_def_id ( item. id ) ;
245
+ let def_id = self . tcx . hir ( ) . local_def_id_from_hir_id ( item. hir_id ) ;
246
246
if item_might_be_inlined ( self . tcx ,
247
247
& item,
248
248
self . tcx . codegen_fn_attrs ( def_id) ) {
@@ -295,7 +295,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
295
295
self . visit_nested_body ( body) ;
296
296
}
297
297
hir:: ImplItemKind :: Method ( _, body) => {
298
- let did = self . tcx . hir ( ) . get_parent_did ( search_item) ;
298
+ let did = self . tcx . hir ( ) . get_parent_did_by_hir_id ( search_item) ;
299
299
if method_might_be_inlined ( self . tcx , impl_item, did) {
300
300
self . visit_nested_body ( body)
301
301
}
@@ -317,7 +317,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
317
317
_ => {
318
318
bug ! (
319
319
"found unexpected node kind in worklist: {} ({:?})" ,
320
- self . tcx. hir( ) . node_to_string ( search_item) ,
320
+ self . tcx. hir( ) . hir_to_string ( search_item) ,
321
321
node,
322
322
) ;
323
323
}
@@ -336,7 +336,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
336
336
struct CollectPrivateImplItemsVisitor < ' a , ' tcx : ' a > {
337
337
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
338
338
access_levels : & ' a privacy:: AccessLevels ,
339
- worklist : & ' a mut Vec < ast :: NodeId > ,
339
+ worklist : & ' a mut Vec < hir :: HirId > ,
340
340
}
341
341
342
342
impl < ' a , ' tcx : ' a > ItemLikeVisitor < ' tcx > for CollectPrivateImplItemsVisitor < ' a , ' tcx > {
@@ -348,13 +348,18 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
348
348
let codegen_attrs = self . tcx . codegen_fn_attrs ( def_id) ;
349
349
if codegen_attrs. contains_extern_indicator ( ) ||
350
350
codegen_attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ) {
351
- self . worklist . push ( item. id ) ;
351
+ self . worklist . push ( item. hir_id ) ;
352
352
}
353
353
354
354
// We need only trait impls here, not inherent impls, and only non-exported ones
355
355
if let hir:: ItemKind :: Impl ( .., Some ( ref trait_ref) , _, ref impl_item_refs) = item. node {
356
- if !self . access_levels . is_reachable ( item. id ) {
357
- self . worklist . extend ( impl_item_refs. iter ( ) . map ( |r| r. id . node_id ) ) ;
356
+ let node_id = self . tcx . hir ( ) . hir_to_node_id ( item. hir_id ) ;
357
+ if !self . access_levels . is_reachable ( node_id) {
358
+ // FIXME(@ljedrz): rework back to a nice extend when item Ids contain HirId
359
+ for impl_item_ref in impl_item_refs {
360
+ let hir_id = self . tcx . hir ( ) . node_to_hir_id ( impl_item_ref. id . node_id ) ;
361
+ self . worklist . push ( hir_id) ;
362
+ }
358
363
359
364
let trait_def_id = match trait_ref. path . def {
360
365
Def :: Trait ( def_id) => def_id,
@@ -368,11 +373,11 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
368
373
let provided_trait_methods = self . tcx . provided_trait_methods ( trait_def_id) ;
369
374
self . worklist . reserve ( provided_trait_methods. len ( ) ) ;
370
375
for default_method in provided_trait_methods {
371
- let node_id = self . tcx
372
- . hir ( )
373
- . as_local_node_id ( default_method. def_id )
374
- . unwrap ( ) ;
375
- self . worklist . push ( node_id ) ;
376
+ let hir_id = self . tcx
377
+ . hir ( )
378
+ . as_local_hir_id ( default_method. def_id )
379
+ . unwrap ( ) ;
380
+ self . worklist . push ( hir_id ) ;
376
381
}
377
382
}
378
383
}
@@ -388,7 +393,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
388
393
// We introduce a new-type here, so we can have a specialized HashStable
389
394
// implementation for it.
390
395
#[ derive( Clone ) ]
391
- pub struct ReachableSet ( pub Lrc < NodeSet > ) ;
396
+ pub struct ReachableSet ( pub Lrc < HirIdSet > ) ;
392
397
393
398
fn reachable_set < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , crate_num : CrateNum ) -> ReachableSet {
394
399
debug_assert ! ( crate_num == LOCAL_CRATE ) ;
@@ -412,11 +417,12 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
412
417
// If other crates link to us, they're going to expect to be able to
413
418
// use the lang items, so we need to be sure to mark them as
414
419
// exported.
415
- reachable_context. worklist . extend ( access_levels. map . iter ( ) . map ( |( id, _) | * id) ) ;
420
+ reachable_context. worklist . extend (
421
+ access_levels. map . iter ( ) . map ( |( id, _) | tcx. hir ( ) . node_to_hir_id ( * id) ) ) ;
416
422
for item in tcx. lang_items ( ) . items ( ) . iter ( ) {
417
423
if let Some ( did) = * item {
418
- if let Some ( node_id ) = tcx. hir ( ) . as_local_node_id ( did) {
419
- reachable_context. worklist . push ( node_id ) ;
424
+ if let Some ( hir_id ) = tcx. hir ( ) . as_local_hir_id ( did) {
425
+ reachable_context. worklist . push ( hir_id ) ;
420
426
}
421
427
}
422
428
}
0 commit comments