8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use std:: cell:: { Ref , RefCell } ;
12
11
use rustc_data_structures:: indexed_vec:: IndexVec ;
12
+ use rustc_data_structures:: sync:: { RwLock , ReadGuard } ;
13
13
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher ,
14
14
StableHasherResult } ;
15
15
use ich:: StableHashingContext ;
@@ -19,7 +19,7 @@ use rustc_serialize as serialize;
19
19
20
20
#[ derive( Clone , Debug ) ]
21
21
pub struct Cache {
22
- predecessors : RefCell < Option < IndexVec < BasicBlock , Vec < BasicBlock > > > >
22
+ predecessors : RwLock < Option < IndexVec < BasicBlock , Vec < BasicBlock > > > >
23
23
}
24
24
25
25
@@ -46,7 +46,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Cache {
46
46
impl Cache {
47
47
pub fn new ( ) -> Self {
48
48
Cache {
49
- predecessors : RefCell :: new ( None )
49
+ predecessors : RwLock :: new ( None )
50
50
}
51
51
}
52
52
@@ -55,12 +55,12 @@ impl Cache {
55
55
* self . predecessors . borrow_mut ( ) = None ;
56
56
}
57
57
58
- pub fn predecessors ( & self , mir : & Mir ) -> Ref < IndexVec < BasicBlock , Vec < BasicBlock > > > {
58
+ pub fn predecessors ( & self , mir : & Mir ) -> ReadGuard < IndexVec < BasicBlock , Vec < BasicBlock > > > {
59
59
if self . predecessors . borrow ( ) . is_none ( ) {
60
60
* self . predecessors . borrow_mut ( ) = Some ( calculate_predecessors ( mir) ) ;
61
61
}
62
62
63
- Ref :: map ( self . predecessors . borrow ( ) , |p| p. as_ref ( ) . unwrap ( ) )
63
+ ReadGuard :: map ( self . predecessors . borrow ( ) , |p| p. as_ref ( ) . unwrap ( ) )
64
64
}
65
65
}
66
66
0 commit comments