11use crate :: dep_graph:: DepNodeIndex ;
2+ use std:: cell:: RefCell ;
23
34use rustc_data_structures:: fx:: FxHashMap ;
45use rustc_data_structures:: sharded:: { self , Sharded } ;
@@ -41,7 +42,7 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> CacheSelector<'tcx, V> for DefaultCacheSelecto
4142}
4243
4344pub struct DefaultCache < K , V > {
44- cache : Lock < FxHashMap < K , ( V , DepNodeIndex ) > > ,
45+ cache : RefCell < FxHashMap < K , ( V , DepNodeIndex ) > > ,
4546}
4647
4748impl < K , V > Default for DefaultCache < K , V > {
@@ -61,22 +62,22 @@ where
6162 #[ inline( always) ]
6263 fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
6364 let key_hash = sharded:: make_hash ( key) ;
64- let lock = self . cache . lock ( ) ;
65+ let lock = self . cache . borrow_mut ( ) ;
6566 let result = lock. raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key) ;
6667
6768 if let Some ( ( _, value) ) = result { Some ( * value) } else { None }
6869 }
6970
7071 #[ inline]
7172 fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
72- let mut lock = self . cache . lock ( ) ;
73+ let mut lock = self . cache . borrow_mut ( ) ;
7374 // We may be overwriting another value. This is all right, since the dep-graph
7475 // will check that the fingerprint matches.
7576 lock. insert ( key, ( value, index) ) ;
7677 }
7778
7879 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 ( ) ;
8081 for ( k, v) in map. iter ( ) {
8182 f ( k, & v. 0 , v. 1 ) ;
8283 }
@@ -185,7 +186,7 @@ impl<'tcx, K: Idx, V: 'tcx> CacheSelector<'tcx, V> for VecCacheSelector<K> {
185186}
186187
187188pub struct VecCache < K : Idx , V > {
188- cache : Lock < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
189+ cache : RefCell < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
189190}
190191
191192impl < K : Idx , V > Default for VecCache < K , V > {
@@ -204,18 +205,18 @@ where
204205
205206 #[ inline( always) ]
206207 fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
207- let lock = self . cache . lock ( ) ;
208+ let lock = self . cache . borrow_mut ( ) ;
208209 if let Some ( Some ( value) ) = lock. get ( * key) { Some ( * value) } else { None }
209210 }
210211
211212 #[ inline]
212213 fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
213- let mut lock = self . cache . lock ( ) ;
214+ let mut lock = self . cache . borrow_mut ( ) ;
214215 lock. insert ( key, ( value, index) ) ;
215216 }
216217
217218 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 ( ) ;
219220 for ( k, v) in map. iter_enumerated ( ) {
220221 if let Some ( v) = v {
221222 f ( & k, & v. 0 , v. 1 ) ;
0 commit comments