@@ -56,7 +56,6 @@ use rustc_hir::def::{
5656} ;
5757use rustc_hir:: def_id:: { CRATE_DEF_ID , CrateNum , DefId , LOCAL_CRATE , LocalDefId , LocalDefIdMap } ;
5858use rustc_hir:: { PrimTy , TraitCandidate } ;
59- use rustc_index:: IndexVec ;
6059use rustc_metadata:: creader:: { CStore , CrateLoader } ;
6160use rustc_middle:: metadata:: ModChild ;
6261use rustc_middle:: middle:: privacy:: EffectiveVisibilities ;
@@ -1141,7 +1140,7 @@ pub struct Resolver<'ra, 'tcx> {
11411140 ast_transform_scopes : FxHashMap < LocalExpnId , Module < ' ra > > ,
11421141 unused_macros : FxIndexMap < LocalDefId , ( NodeId , Ident ) > ,
11431142 /// A map from the macro to all its potentially unused arms.
1144- unused_macro_rules : FxIndexMap < LocalDefId , UnordMap < usize , ( Ident , Span ) > > ,
1143+ unused_macro_rules : FxIndexMap < NodeId , UnordMap < usize , ( Ident , Span ) > > ,
11451144 proc_macro_stubs : FxHashSet < LocalDefId > ,
11461145 /// Traces collected during macro resolution and validated when it's complete.
11471146 single_segment_macro_resolutions :
@@ -1184,7 +1183,6 @@ pub struct Resolver<'ra, 'tcx> {
11841183 next_node_id : NodeId ,
11851184
11861185 node_id_to_def_id : NodeMap < Feed < ' tcx , LocalDefId > > ,
1187- def_id_to_node_id : IndexVec < LocalDefId , ast:: NodeId > ,
11881186
11891187 /// Indices of unnamed struct or variant fields with unresolved attributes.
11901188 placeholder_field_indices : FxHashMap < NodeId , usize > ,
@@ -1202,7 +1200,7 @@ pub struct Resolver<'ra, 'tcx> {
12021200 trait_impls : FxIndexMap < DefId , Vec < LocalDefId > > ,
12031201 /// A list of proc macro LocalDefIds, written out in the order in which
12041202 /// they are declared in the static array generated by proc_macro_harness.
1205- proc_macros : Vec < NodeId > ,
1203+ proc_macros : Vec < LocalDefId > ,
12061204 confused_type_with_std_module : FxIndexMap < Span , Span > ,
12071205 /// Whether lifetime elision was successful.
12081206 lifetime_elision_allowed : FxHashSet < NodeId > ,
@@ -1369,7 +1367,6 @@ impl<'tcx> Resolver<'_, 'tcx> {
13691367 debug ! ( "create_def: def_id_to_node_id[{:?}] <-> {:?}" , def_id, node_id) ;
13701368 self . node_id_to_def_id . insert ( node_id, feed. downgrade ( ) ) ;
13711369 }
1372- assert_eq ! ( self . def_id_to_node_id. push( node_id) , def_id) ;
13731370
13741371 feed
13751372 }
@@ -1385,6 +1382,19 @@ impl<'tcx> Resolver<'_, 'tcx> {
13851382 pub fn tcx ( & self ) -> TyCtxt < ' tcx > {
13861383 self . tcx
13871384 }
1385+
1386+ /// This function is very slow, as it iterates over the entire
1387+ /// [Resolver::node_id_to_def_id] map just to find the [NodeId]
1388+ /// that corresponds to the given [LocalDefId]. Only use this in
1389+ /// diagnostics code paths.
1390+ fn def_id_to_node_id ( & self , def_id : LocalDefId ) -> NodeId {
1391+ self . node_id_to_def_id
1392+ . items ( )
1393+ . filter ( |( _, v) | v. key ( ) == def_id)
1394+ . map ( |( k, _) | * k)
1395+ . get_only ( )
1396+ . unwrap ( )
1397+ }
13881398}
13891399
13901400impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
@@ -1417,8 +1427,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14171427 & mut Default :: default ( ) ,
14181428 ) ;
14191429
1420- let mut def_id_to_node_id = IndexVec :: default ( ) ;
1421- assert_eq ! ( def_id_to_node_id. push( CRATE_NODE_ID ) , CRATE_DEF_ID ) ;
14221430 let mut node_id_to_def_id = NodeMap :: default ( ) ;
14231431 let crate_feed = tcx. create_local_crate_def_id ( crate_span) ;
14241432
@@ -1553,7 +1561,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15531561 lint_buffer : LintBuffer :: default ( ) ,
15541562 next_node_id : CRATE_NODE_ID ,
15551563 node_id_to_def_id,
1556- def_id_to_node_id,
15571564 placeholder_field_indices : Default :: default ( ) ,
15581565 invocation_parents,
15591566 legacy_const_generic_args : Default :: default ( ) ,
@@ -1633,7 +1640,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16331640 }
16341641
16351642 pub fn into_outputs ( self ) -> ResolverOutputs {
1636- let proc_macros = self . proc_macros . iter ( ) . map ( |id| self . local_def_id ( * id ) ) . collect ( ) ;
1643+ let proc_macros = self . proc_macros ;
16371644 let expn_that_defined = self . expn_that_defined ;
16381645 let extern_crate_map = self . extern_crate_map ;
16391646 let maybe_unused_trait_imports = self . maybe_unused_trait_imports ;
0 commit comments