1
1
use crate :: dep_graph:: DepNodeIndex ;
2
+ use std:: cell:: RefCell ;
2
3
3
4
use rustc_data_structures:: fx:: FxHashMap ;
4
5
use rustc_data_structures:: sharded:: { self , Sharded } ;
@@ -41,7 +42,7 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> CacheSelector<'tcx, V> for DefaultCacheSelecto
41
42
}
42
43
43
44
pub struct DefaultCache < K , V > {
44
- cache : Lock < FxHashMap < K , ( V , DepNodeIndex ) > > ,
45
+ cache : RefCell < FxHashMap < K , ( V , DepNodeIndex ) > > ,
45
46
}
46
47
47
48
impl < K , V > Default for DefaultCache < K , V > {
@@ -61,22 +62,22 @@ where
61
62
#[ inline( always) ]
62
63
fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
63
64
let key_hash = sharded:: make_hash ( key) ;
64
- let lock = self . cache . lock ( ) ;
65
+ let lock = self . cache . borrow_mut ( ) ;
65
66
let result = lock. raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key) ;
66
67
67
68
if let Some ( ( _, value) ) = result { Some ( * value) } else { None }
68
69
}
69
70
70
71
#[ inline]
71
72
fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
72
- let mut lock = self . cache . lock ( ) ;
73
+ let mut lock = self . cache . borrow_mut ( ) ;
73
74
// We may be overwriting another value. This is all right, since the dep-graph
74
75
// will check that the fingerprint matches.
75
76
lock. insert ( key, ( value, index) ) ;
76
77
}
77
78
78
79
fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
79
- let map = self . cache . lock ( ) ;
80
+ let map = self . cache . borrow_mut ( ) ;
80
81
for ( k, v) in map. iter ( ) {
81
82
f ( k, & v. 0 , v. 1 ) ;
82
83
}
@@ -185,7 +186,7 @@ impl<'tcx, K: Idx, V: 'tcx> CacheSelector<'tcx, V> for VecCacheSelector<K> {
185
186
}
186
187
187
188
pub struct VecCache < K : Idx , V > {
188
- cache : Lock < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
189
+ cache : RefCell < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
189
190
}
190
191
191
192
impl < K : Idx , V > Default for VecCache < K , V > {
@@ -204,18 +205,18 @@ where
204
205
205
206
#[ inline( always) ]
206
207
fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
207
- let lock = self . cache . lock ( ) ;
208
+ let lock = self . cache . borrow_mut ( ) ;
208
209
if let Some ( Some ( value) ) = lock. get ( * key) { Some ( * value) } else { None }
209
210
}
210
211
211
212
#[ inline]
212
213
fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
213
- let mut lock = self . cache . lock ( ) ;
214
+ let mut lock = self . cache . borrow_mut ( ) ;
214
215
lock. insert ( key, ( value, index) ) ;
215
216
}
216
217
217
218
fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
218
- let map = self . cache . lock ( ) ;
219
+ let map = self . cache . borrow_mut ( ) ;
219
220
for ( k, v) in map. iter_enumerated ( ) {
220
221
if let Some ( v) = v {
221
222
f ( & k, & v. 0 , v. 1 ) ;
0 commit comments