@@ -56,7 +56,6 @@ use rustc_hir::def::{
56
56
} ;
57
57
use rustc_hir:: def_id:: { CRATE_DEF_ID , CrateNum , DefId , LOCAL_CRATE , LocalDefId , LocalDefIdMap } ;
58
58
use rustc_hir:: { PrimTy , TraitCandidate } ;
59
- use rustc_index:: IndexVec ;
60
59
use rustc_metadata:: creader:: { CStore , CrateLoader } ;
61
60
use rustc_middle:: metadata:: ModChild ;
62
61
use rustc_middle:: middle:: privacy:: EffectiveVisibilities ;
@@ -1141,7 +1140,7 @@ pub struct Resolver<'ra, 'tcx> {
1141
1140
ast_transform_scopes : FxHashMap < LocalExpnId , Module < ' ra > > ,
1142
1141
unused_macros : FxIndexMap < LocalDefId , ( NodeId , Ident ) > ,
1143
1142
/// 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 ) > > ,
1145
1144
proc_macro_stubs : FxHashSet < LocalDefId > ,
1146
1145
/// Traces collected during macro resolution and validated when it's complete.
1147
1146
single_segment_macro_resolutions :
@@ -1184,7 +1183,6 @@ pub struct Resolver<'ra, 'tcx> {
1184
1183
next_node_id : NodeId ,
1185
1184
1186
1185
node_id_to_def_id : NodeMap < Feed < ' tcx , LocalDefId > > ,
1187
- def_id_to_node_id : IndexVec < LocalDefId , ast:: NodeId > ,
1188
1186
1189
1187
/// Indices of unnamed struct or variant fields with unresolved attributes.
1190
1188
placeholder_field_indices : FxHashMap < NodeId , usize > ,
@@ -1202,7 +1200,7 @@ pub struct Resolver<'ra, 'tcx> {
1202
1200
trait_impls : FxIndexMap < DefId , Vec < LocalDefId > > ,
1203
1201
/// A list of proc macro LocalDefIds, written out in the order in which
1204
1202
/// they are declared in the static array generated by proc_macro_harness.
1205
- proc_macros : Vec < NodeId > ,
1203
+ proc_macros : Vec < LocalDefId > ,
1206
1204
confused_type_with_std_module : FxIndexMap < Span , Span > ,
1207
1205
/// Whether lifetime elision was successful.
1208
1206
lifetime_elision_allowed : FxHashSet < NodeId > ,
@@ -1369,7 +1367,6 @@ impl<'tcx> Resolver<'_, 'tcx> {
1369
1367
debug ! ( "create_def: def_id_to_node_id[{:?}] <-> {:?}" , def_id, node_id) ;
1370
1368
self . node_id_to_def_id . insert ( node_id, feed. downgrade ( ) ) ;
1371
1369
}
1372
- assert_eq ! ( self . def_id_to_node_id. push( node_id) , def_id) ;
1373
1370
1374
1371
feed
1375
1372
}
@@ -1385,6 +1382,19 @@ impl<'tcx> Resolver<'_, 'tcx> {
1385
1382
pub fn tcx ( & self ) -> TyCtxt < ' tcx > {
1386
1383
self . tcx
1387
1384
}
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
+ }
1388
1398
}
1389
1399
1390
1400
impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
@@ -1417,8 +1427,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1417
1427
& mut Default :: default ( ) ,
1418
1428
) ;
1419
1429
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 ) ;
1422
1430
let mut node_id_to_def_id = NodeMap :: default ( ) ;
1423
1431
let crate_feed = tcx. create_local_crate_def_id ( crate_span) ;
1424
1432
@@ -1553,7 +1561,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1553
1561
lint_buffer : LintBuffer :: default ( ) ,
1554
1562
next_node_id : CRATE_NODE_ID ,
1555
1563
node_id_to_def_id,
1556
- def_id_to_node_id,
1557
1564
placeholder_field_indices : Default :: default ( ) ,
1558
1565
invocation_parents,
1559
1566
legacy_const_generic_args : Default :: default ( ) ,
@@ -1633,7 +1640,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1633
1640
}
1634
1641
1635
1642
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 ;
1637
1644
let expn_that_defined = self . expn_that_defined ;
1638
1645
let extern_crate_map = self . extern_crate_map ;
1639
1646
let maybe_unused_trait_imports = self . maybe_unused_trait_imports ;
0 commit comments