@@ -14,10 +14,9 @@ use crate::ty::{self, TyCtxt};
1414use crate :: ty:: query:: Providers ;
1515use crate :: middle:: privacy;
1616use crate :: session:: config;
17- use crate :: util:: nodemap:: { NodeSet , FxHashSet } ;
17+ use crate :: util:: nodemap:: { HirIdSet , FxHashSet } ;
1818
1919use rustc_target:: spec:: abi:: Abi ;
20- use syntax:: ast;
2120use crate :: hir;
2221use crate :: hir:: def_id:: LOCAL_CRATE ;
2322use crate :: hir:: intravisit:: { Visitor , NestedVisitorMap } ;
@@ -70,10 +69,10 @@ struct ReachableContext<'a, 'tcx: 'a> {
7069 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
7170 tables : & ' a ty:: TypeckTables < ' tcx > ,
7271 // The set of items which must be exported in the linkage sense.
73- reachable_symbols : NodeSet ,
72+ reachable_symbols : HirIdSet ,
7473 // A worklist of item IDs. Each item ID in this worklist will be inlined
7574 // and will be scanned for further references.
76- worklist : Vec < ast :: NodeId > ,
75+ worklist : Vec < hir :: HirId > ,
7776 // Whether any output of this compilation is a library
7877 any_library : bool ,
7978}
@@ -104,27 +103,28 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
104103
105104 match def {
106105 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) ;
108108 }
109109 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) )
112112 } ) {
113113 if self . def_id_represents_local_inlined_item ( def_id) {
114- self . worklist . push ( node_id ) ;
114+ self . worklist . push ( hir_id ) ;
115115 } else {
116116 match def {
117117 // If this path leads to a constant, then we need to
118118 // recurse into the constant to continue finding
119119 // items that are reachable.
120120 Def :: Const ( ..) | Def :: AssociatedConst ( ..) => {
121- self . worklist . push ( node_id ) ;
121+ self . worklist . push ( hir_id ) ;
122122 }
123123
124124 // If this wasn't a static, then the destination is
125125 // surely reachable.
126126 _ => {
127- self . reachable_symbols . insert ( node_id ) ;
127+ self . reachable_symbols . insert ( hir_id ) ;
128128 }
129129 }
130130 }
@@ -204,14 +204,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
204204 continue
205205 }
206206
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) {
208208 self . propagate_node ( item, search_item) ;
209209 }
210210 }
211211 }
212212
213213 fn propagate_node ( & mut self , node : & Node < ' tcx > ,
214- search_item : ast :: NodeId ) {
214+ search_item : hir :: HirId ) {
215215 if !self . any_library {
216216 // If we are building an executable, only explicitly extern
217217 // types need to be exported.
@@ -221,7 +221,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
221221 } else {
222222 false
223223 } ;
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 ) ;
225225 let codegen_attrs = self . tcx . codegen_fn_attrs ( def_id) ;
226226 let is_extern = codegen_attrs. contains_extern_indicator ( ) ;
227227 let std_internal = codegen_attrs. flags . contains (
@@ -242,7 +242,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
242242 Node :: Item ( item) => {
243243 match item. node {
244244 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 ) ;
246246 if item_might_be_inlined ( self . tcx ,
247247 & item,
248248 self . tcx . codegen_fn_attrs ( def_id) ) {
@@ -295,7 +295,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
295295 self . visit_nested_body ( body) ;
296296 }
297297 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) ;
299299 if method_might_be_inlined ( self . tcx , impl_item, did) {
300300 self . visit_nested_body ( body)
301301 }
@@ -317,7 +317,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
317317 _ => {
318318 bug ! (
319319 "found unexpected node kind in worklist: {} ({:?})" ,
320- self . tcx. hir( ) . node_to_string ( search_item) ,
320+ self . tcx. hir( ) . hir_to_string ( search_item) ,
321321 node,
322322 ) ;
323323 }
@@ -336,7 +336,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
336336struct CollectPrivateImplItemsVisitor < ' a , ' tcx : ' a > {
337337 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
338338 access_levels : & ' a privacy:: AccessLevels ,
339- worklist : & ' a mut Vec < ast :: NodeId > ,
339+ worklist : & ' a mut Vec < hir :: HirId > ,
340340}
341341
342342impl < ' a , ' tcx : ' a > ItemLikeVisitor < ' tcx > for CollectPrivateImplItemsVisitor < ' a , ' tcx > {
@@ -348,13 +348,18 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
348348 let codegen_attrs = self . tcx . codegen_fn_attrs ( def_id) ;
349349 if codegen_attrs. contains_extern_indicator ( ) ||
350350 codegen_attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ) {
351- self . worklist . push ( item. id ) ;
351+ self . worklist . push ( item. hir_id ) ;
352352 }
353353
354354 // We need only trait impls here, not inherent impls, and only non-exported ones
355355 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+ }
358363
359364 let trait_def_id = match trait_ref. path . def {
360365 Def :: Trait ( def_id) => def_id,
@@ -368,11 +373,11 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
368373 let provided_trait_methods = self . tcx . provided_trait_methods ( trait_def_id) ;
369374 self . worklist . reserve ( provided_trait_methods. len ( ) ) ;
370375 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 ) ;
376381 }
377382 }
378383 }
@@ -388,7 +393,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
388393// We introduce a new-type here, so we can have a specialized HashStable
389394// implementation for it.
390395#[ derive( Clone ) ]
391- pub struct ReachableSet ( pub Lrc < NodeSet > ) ;
396+ pub struct ReachableSet ( pub Lrc < HirIdSet > ) ;
392397
393398fn reachable_set < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , crate_num : CrateNum ) -> ReachableSet {
394399 debug_assert ! ( crate_num == LOCAL_CRATE ) ;
@@ -412,11 +417,12 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
412417 // If other crates link to us, they're going to expect to be able to
413418 // use the lang items, so we need to be sure to mark them as
414419 // 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) ) ) ;
416422 for item in tcx. lang_items ( ) . items ( ) . iter ( ) {
417423 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 ) ;
420426 }
421427 }
422428 }
0 commit comments