@@ -347,22 +347,21 @@ impl<'sess> OnDiskCache<'sess> {
347347 return None
348348 } ;
349349
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 ( ) ;
352353 * cnum_map = Some ( Self :: compute_cnum_map ( tcx, & self . prev_cnums [ ..] ) ) ;
353354 }
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 ( ) ;
357356
358357 let mut decoder = CacheDecoder {
359358 tcx,
360359 opaque : opaque:: Decoder :: new ( & self . serialized_data [ ..] , pos. to_usize ( ) ) ,
361360 codemap : self . codemap ,
362361 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 ,
364363 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 ,
366365 } ;
367366
368367 match decode_tagged ( & mut decoder, dep_node_index) {
@@ -421,21 +420,21 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
421420 opaque : opaque:: Decoder < ' x > ,
422421 codemap : & ' x CodeMap ,
423422 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 > > > ,
426425 file_index_to_stable_id : & ' x FxHashMap < FileMapIndex , StableFilemapId > ,
427426}
428427
429428impl < ' 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 > {
431430 let CacheDecoder {
432- ref mut file_index_to_file,
431+ ref file_index_to_file,
433432 ref file_index_to_stable_id,
434433 ref codemap,
435434 ..
436435 } = * self ;
437436
438- file_index_to_file. entry ( index) . or_insert_with ( || {
437+ file_index_to_file. borrow_mut ( ) . entry ( index) . or_insert_with ( || {
439438 let stable_id = file_index_to_stable_id[ & index] ;
440439 codemap. filemap_by_stable_id ( stable_id)
441440 . expect ( "Failed to lookup FileMap in new context." )
@@ -572,19 +571,24 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx, 'x> {
572571 let pos = AbsoluteBytePos :: new ( self . opaque . position ( ) ) ;
573572 let expn_info: ExpnInfo = Decodable :: decode ( self ) ?;
574573 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) ;
576575 ctxt
577576 }
578577 TAG_EXPANSION_INFO_SHORTHAND => {
579578 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 {
581585 ctxt
582586 } else {
583587 let expn_info = self . with_position ( pos. to_usize ( ) , |this| {
584588 ExpnInfo :: decode ( this)
585589 } ) ?;
586590 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) ;
588592 ctxt
589593 }
590594 }
0 commit comments