1
1
use crate :: QueryCtxt ;
2
2
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
3
3
use rustc_data_structures:: memmap:: Mmap ;
4
- use rustc_data_structures:: sync:: { HashMapExt , Lock , Lrc , OnceCell , RwLock } ;
4
+ use rustc_data_structures:: sync:: { HashMapExt , Lock , Lrc , RwLock } ;
5
5
use rustc_data_structures:: unhash:: UnhashMap ;
6
6
use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , StableCrateId , LOCAL_CRATE } ;
7
7
use rustc_hir:: definitions:: DefPathHash ;
@@ -50,8 +50,6 @@ pub struct OnDiskCache<'sess> {
50
50
// session.
51
51
current_side_effects : Lock < FxHashMap < DepNodeIndex , QuerySideEffects > > ,
52
52
53
- cnum_map : OnceCell < UnhashMap < StableCrateId , CrateNum > > ,
54
-
55
53
source_map : & ' sess SourceMap ,
56
54
file_index_to_stable_id : FxHashMap < SourceFileIndex , EncodedSourceFileId > ,
57
55
@@ -139,8 +137,8 @@ struct EncodedSourceFileId {
139
137
}
140
138
141
139
impl EncodedSourceFileId {
142
- fn translate ( & self , cnum_map : & UnhashMap < StableCrateId , CrateNum > ) -> StableSourceFileId {
143
- let cnum = cnum_map [ & self . stable_crate_id ] ;
140
+ fn translate ( & self , tcx : TyCtxt < ' _ > ) -> StableSourceFileId {
141
+ let cnum = tcx . stable_crate_id_to_crate_num ( self . stable_crate_id ) ;
144
142
StableSourceFileId { file_name_hash : self . file_name_hash , cnum }
145
143
}
146
144
@@ -180,7 +178,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
180
178
serialized_data : RwLock :: new ( Some ( data) ) ,
181
179
file_index_to_stable_id : footer. file_index_to_stable_id ,
182
180
file_index_to_file : Default :: default ( ) ,
183
- cnum_map : OnceCell :: new ( ) ,
184
181
source_map : sess. source_map ( ) ,
185
182
current_side_effects : Default :: default ( ) ,
186
183
query_result_index : footer. query_result_index . into_iter ( ) . collect ( ) ,
@@ -198,7 +195,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
198
195
serialized_data : RwLock :: new ( None ) ,
199
196
file_index_to_stable_id : Default :: default ( ) ,
200
197
file_index_to_file : Default :: default ( ) ,
201
- cnum_map : OnceCell :: new ( ) ,
202
198
source_map,
203
199
current_side_effects : Default :: default ( ) ,
204
200
query_result_index : Default :: default ( ) ,
@@ -466,14 +462,11 @@ impl<'sess> OnDiskCache<'sess> {
466
462
where
467
463
T : Decodable < CacheDecoder < ' a , ' tcx > > ,
468
464
{
469
- let cnum_map = self . cnum_map . get_or_init ( || Self :: compute_cnum_map ( tcx) ) ;
470
-
471
465
let serialized_data = self . serialized_data . read ( ) ;
472
466
let mut decoder = CacheDecoder {
473
467
tcx,
474
468
opaque : opaque:: Decoder :: new ( serialized_data. as_deref ( ) . unwrap_or ( & [ ] ) , pos. to_usize ( ) ) ,
475
469
source_map : self . source_map ,
476
- cnum_map,
477
470
file_index_to_file : & self . file_index_to_file ,
478
471
file_index_to_stable_id : & self . file_index_to_stable_id ,
479
472
alloc_decoding_session : self . alloc_decoding_state . new_decoding_session ( ) ,
@@ -484,23 +477,6 @@ impl<'sess> OnDiskCache<'sess> {
484
477
} ;
485
478
f ( & mut decoder)
486
479
}
487
-
488
- // This function builds mapping from previous-session-`CrateNum` to
489
- // current-session-`CrateNum`. There might be `CrateNum`s from the previous
490
- // `Session` that don't occur in the current one. For these, the mapping
491
- // maps to None.
492
- fn compute_cnum_map ( tcx : TyCtxt < ' _ > ) -> UnhashMap < StableCrateId , CrateNum > {
493
- tcx. dep_graph . with_ignore ( || {
494
- tcx. crates ( ( ) )
495
- . iter ( )
496
- . chain ( std:: iter:: once ( & LOCAL_CRATE ) )
497
- . map ( |& cnum| {
498
- let hash = tcx. def_path_hash ( cnum. as_def_id ( ) ) . stable_crate_id ( ) ;
499
- ( hash, cnum)
500
- } )
501
- . collect ( )
502
- } )
503
- }
504
480
}
505
481
506
482
//- DECODING -------------------------------------------------------------------
@@ -512,7 +488,6 @@ pub struct CacheDecoder<'a, 'tcx> {
512
488
tcx : TyCtxt < ' tcx > ,
513
489
opaque : opaque:: Decoder < ' a > ,
514
490
source_map : & ' a SourceMap ,
515
- cnum_map : & ' a UnhashMap < StableCrateId , CrateNum > ,
516
491
file_index_to_file : & ' a Lock < FxHashMap < SourceFileIndex , Lrc < SourceFile > > > ,
517
492
file_index_to_stable_id : & ' a FxHashMap < SourceFileIndex , EncodedSourceFileId > ,
518
493
alloc_decoding_session : AllocDecodingSession < ' a > ,
@@ -525,18 +500,18 @@ pub struct CacheDecoder<'a, 'tcx> {
525
500
impl < ' a , ' tcx > CacheDecoder < ' a , ' tcx > {
526
501
fn file_index_to_file ( & self , index : SourceFileIndex ) -> Lrc < SourceFile > {
527
502
let CacheDecoder {
503
+ tcx,
528
504
ref file_index_to_file,
529
505
ref file_index_to_stable_id,
530
506
ref source_map,
531
- ref cnum_map,
532
507
..
533
508
} = * self ;
534
509
535
510
file_index_to_file
536
511
. borrow_mut ( )
537
512
. entry ( index)
538
513
. or_insert_with ( || {
539
- let stable_id = file_index_to_stable_id[ & index] . translate ( cnum_map ) ;
514
+ let stable_id = file_index_to_stable_id[ & index] . translate ( tcx ) ;
540
515
source_map
541
516
. source_file_by_stable_id ( stable_id)
542
517
. expect ( "failed to lookup `SourceFile` in new context" )
@@ -678,7 +653,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for ExpnId {
678
653
return Ok ( expn_id) ;
679
654
}
680
655
681
- let krate = decoder. cnum_map [ & hash. stable_crate_id ( ) ] ;
656
+ let krate = decoder. tcx . stable_crate_id_to_crate_num ( hash. stable_crate_id ( ) ) ;
682
657
683
658
let expn_id = if krate == LOCAL_CRATE {
684
659
// We look up the position of the associated `ExpnData` and decode it.
@@ -751,7 +726,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Span {
751
726
impl < ' a , ' tcx > Decodable < CacheDecoder < ' a , ' tcx > > for CrateNum {
752
727
fn decode ( d : & mut CacheDecoder < ' a , ' tcx > ) -> Result < Self , String > {
753
728
let stable_id = StableCrateId :: decode ( d) ?;
754
- let cnum = d. cnum_map [ & stable_id] ;
729
+ let cnum = d. tcx . stable_crate_id_to_crate_num ( stable_id) ;
755
730
Ok ( cnum)
756
731
}
757
732
}
0 commit comments