88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use std:: cell:: { Ref , RefCell } ;
1211use rustc_data_structures:: indexed_vec:: IndexVec ;
12+ use rustc_data_structures:: sync:: { RwLock , ReadGuard } ;
1313use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher ,
1414 StableHasherResult } ;
1515use ich:: StableHashingContext ;
@@ -19,7 +19,7 @@ use rustc_serialize as serialize;
1919
2020#[ derive( Clone , Debug ) ]
2121pub struct Cache {
22- predecessors : RefCell < Option < IndexVec < BasicBlock , Vec < BasicBlock > > > >
22+ predecessors : RwLock < Option < IndexVec < BasicBlock , Vec < BasicBlock > > > >
2323}
2424
2525
@@ -46,7 +46,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Cache {
4646impl Cache {
4747 pub fn new ( ) -> Self {
4848 Cache {
49- predecessors : RefCell :: new ( None )
49+ predecessors : RwLock :: new ( None )
5050 }
5151 }
5252
@@ -55,12 +55,12 @@ impl Cache {
5555 * self . predecessors . borrow_mut ( ) = None ;
5656 }
5757
58- pub fn predecessors ( & self , mir : & Mir ) -> Ref < IndexVec < BasicBlock , Vec < BasicBlock > > > {
58+ pub fn predecessors ( & self , mir : & Mir ) -> ReadGuard < IndexVec < BasicBlock , Vec < BasicBlock > > > {
5959 if self . predecessors . borrow ( ) . is_none ( ) {
6060 * self . predecessors . borrow_mut ( ) = Some ( calculate_predecessors ( mir) ) ;
6161 }
6262
63- Ref :: map ( self . predecessors . borrow ( ) , |p| p. as_ref ( ) . unwrap ( ) )
63+ ReadGuard :: map ( self . predecessors . borrow ( ) , |p| p. as_ref ( ) . unwrap ( ) )
6464 }
6565}
6666
0 commit comments