@@ -347,22 +347,21 @@ impl<'sess> OnDiskCache<'sess> {
347
347
return None
348
348
} ;
349
349
350
- let mut cnum_map = self . cnum_map . borrow_mut ( ) ;
351
- if cnum_map. is_none ( ) {
350
+ // Initialize the cnum_map if it is not initialized yet.
351
+ if self . cnum_map . borrow ( ) . is_none ( ) {
352
+ let mut cnum_map = self . cnum_map . borrow_mut ( ) ;
352
353
* cnum_map = Some ( Self :: compute_cnum_map ( tcx, & self . prev_cnums [ ..] ) ) ;
353
354
}
354
-
355
- let mut synthetic_expansion_infos = self . synthetic_expansion_infos . borrow_mut ( ) ;
356
- let mut file_index_to_file = self . file_index_to_file . borrow_mut ( ) ;
355
+ let cnum_map = self . cnum_map . borrow ( ) ;
357
356
358
357
let mut decoder = CacheDecoder {
359
358
tcx,
360
359
opaque : opaque:: Decoder :: new ( & self . serialized_data [ ..] , pos. to_usize ( ) ) ,
361
360
codemap : self . codemap ,
362
361
cnum_map : cnum_map. as_ref ( ) . unwrap ( ) ,
363
- file_index_to_file : & mut file_index_to_file,
362
+ file_index_to_file : & self . file_index_to_file ,
364
363
file_index_to_stable_id : & self . file_index_to_stable_id ,
365
- synthetic_expansion_infos : & mut synthetic_expansion_infos,
364
+ synthetic_expansion_infos : & self . synthetic_expansion_infos ,
366
365
} ;
367
366
368
367
match decode_tagged ( & mut decoder, dep_node_index) {
@@ -421,21 +420,21 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
421
420
opaque : opaque:: Decoder < ' x > ,
422
421
codemap : & ' x CodeMap ,
423
422
cnum_map : & ' x IndexVec < CrateNum , Option < CrateNum > > ,
424
- synthetic_expansion_infos : & ' x mut FxHashMap < AbsoluteBytePos , SyntaxContext > ,
425
- file_index_to_file : & ' x mut FxHashMap < FileMapIndex , Rc < FileMap > > ,
423
+ synthetic_expansion_infos : & ' x RefCell < FxHashMap < AbsoluteBytePos , SyntaxContext > > ,
424
+ file_index_to_file : & ' x RefCell < FxHashMap < FileMapIndex , Rc < FileMap > > > ,
426
425
file_index_to_stable_id : & ' x FxHashMap < FileMapIndex , StableFilemapId > ,
427
426
}
428
427
429
428
impl < ' a , ' tcx , ' x > CacheDecoder < ' a , ' tcx , ' x > {
430
- fn file_index_to_file ( & mut self , index : FileMapIndex ) -> Rc < FileMap > {
429
+ fn file_index_to_file ( & self , index : FileMapIndex ) -> Rc < FileMap > {
431
430
let CacheDecoder {
432
- ref mut file_index_to_file,
431
+ ref file_index_to_file,
433
432
ref file_index_to_stable_id,
434
433
ref codemap,
435
434
..
436
435
} = * self ;
437
436
438
- file_index_to_file. entry ( index) . or_insert_with ( || {
437
+ file_index_to_file. borrow_mut ( ) . entry ( index) . or_insert_with ( || {
439
438
let stable_id = file_index_to_stable_id[ & index] ;
440
439
codemap. filemap_by_stable_id ( stable_id)
441
440
. expect ( "Failed to lookup FileMap in new context." )
@@ -572,19 +571,24 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx, 'x> {
572
571
let pos = AbsoluteBytePos :: new ( self . opaque . position ( ) ) ;
573
572
let expn_info: ExpnInfo = Decodable :: decode ( self ) ?;
574
573
let ctxt = SyntaxContext :: allocate_directly ( expn_info) ;
575
- self . synthetic_expansion_infos . insert ( pos, ctxt) ;
574
+ self . synthetic_expansion_infos . borrow_mut ( ) . insert ( pos, ctxt) ;
576
575
ctxt
577
576
}
578
577
TAG_EXPANSION_INFO_SHORTHAND => {
579
578
let pos = AbsoluteBytePos :: decode ( self ) ?;
580
- if let Some ( ctxt) = self . synthetic_expansion_infos . get ( & pos) . cloned ( ) {
579
+ let cached_ctxt = self . synthetic_expansion_infos
580
+ . borrow ( )
581
+ . get ( & pos)
582
+ . cloned ( ) ;
583
+
584
+ if let Some ( ctxt) = cached_ctxt {
581
585
ctxt
582
586
} else {
583
587
let expn_info = self . with_position ( pos. to_usize ( ) , |this| {
584
588
ExpnInfo :: decode ( this)
585
589
} ) ?;
586
590
let ctxt = SyntaxContext :: allocate_directly ( expn_info) ;
587
- self . synthetic_expansion_infos . insert ( pos, ctxt) ;
591
+ self . synthetic_expansion_infos . borrow_mut ( ) . insert ( pos, ctxt) ;
588
592
ctxt
589
593
}
590
594
}
0 commit comments