@@ -2,7 +2,6 @@ use crate::dep_graph::DepNodeIndex;
22
33use rustc_data_structures:: fx:: FxHashMap ;
44use rustc_data_structures:: sharded;
5- #[ cfg( parallel_compiler) ]
65use rustc_data_structures:: sharded:: Sharded ;
76use rustc_data_structures:: sync:: Lock ;
87use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -37,10 +36,7 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> CacheSelector<'tcx, V> for DefaultCacheSelecto
3736}
3837
3938pub struct DefaultCache < K , V > {
40- #[ cfg( parallel_compiler) ]
4139 cache : Sharded < FxHashMap < K , ( V , DepNodeIndex ) > > ,
42- #[ cfg( not( parallel_compiler) ) ]
43- cache : Lock < FxHashMap < K , ( V , DepNodeIndex ) > > ,
4440}
4541
4642impl < K , V > Default for DefaultCache < K , V > {
@@ -60,40 +56,26 @@ where
6056 #[ inline( always) ]
6157 fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
6258 let key_hash = sharded:: make_hash ( key) ;
63- #[ cfg( parallel_compiler) ]
6459 let lock = self . cache . get_shard_by_hash ( key_hash) . lock ( ) ;
65- #[ cfg( not( parallel_compiler) ) ]
66- let lock = self . cache . lock ( ) ;
60+
6761 let result = lock. raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key) ;
6862
6963 if let Some ( ( _, value) ) = result { Some ( * value) } else { None }
7064 }
7165
7266 #[ inline]
7367 fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
74- #[ cfg( parallel_compiler) ]
7568 let mut lock = self . cache . get_shard_by_value ( & key) . lock ( ) ;
76- #[ cfg( not( parallel_compiler) ) ]
77- let mut lock = self . cache . lock ( ) ;
69+
7870 // We may be overwriting another value. This is all right, since the dep-graph
7971 // will check that the fingerprint matches.
8072 lock. insert ( key, ( value, index) ) ;
8173 }
8274
8375 fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
84- #[ cfg( parallel_compiler) ]
85- {
86- let shards = self . cache . lock_shards ( ) ;
87- for shard in shards. iter ( ) {
88- for ( k, v) in shard. iter ( ) {
89- f ( k, & v. 0 , v. 1 ) ;
90- }
91- }
92- }
93- #[ cfg( not( parallel_compiler) ) ]
94- {
95- let map = self . cache . lock ( ) ;
96- for ( k, v) in map. iter ( ) {
76+ let shards = self . cache . lock_shards ( ) ;
77+ for shard in shards. iter ( ) {
78+ for ( k, v) in shard. iter ( ) {
9779 f ( k, & v. 0 , v. 1 ) ;
9880 }
9981 }
@@ -149,10 +131,7 @@ impl<'tcx, K: Idx, V: 'tcx> CacheSelector<'tcx, V> for VecCacheSelector<K> {
149131}
150132
151133pub struct VecCache < K : Idx , V > {
152- #[ cfg( parallel_compiler) ]
153134 cache : Sharded < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
154- #[ cfg( not( parallel_compiler) ) ]
155- cache : Lock < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
156135}
157136
158137impl < K : Idx , V > Default for VecCache < K , V > {
@@ -171,38 +150,22 @@ where
171150
172151 #[ inline( always) ]
173152 fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
174- #[ cfg( parallel_compiler) ]
175153 let lock = self . cache . get_shard_by_hash ( key. index ( ) as u64 ) . lock ( ) ;
176- #[ cfg( not( parallel_compiler) ) ]
177- let lock = self . cache . lock ( ) ;
154+
178155 if let Some ( Some ( value) ) = lock. get ( * key) { Some ( * value) } else { None }
179156 }
180157
181158 #[ inline]
182159 fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
183- #[ cfg( parallel_compiler) ]
184160 let mut lock = self . cache . get_shard_by_hash ( key. index ( ) as u64 ) . lock ( ) ;
185- #[ cfg( not( parallel_compiler) ) ]
186- let mut lock = self . cache . lock ( ) ;
161+
187162 lock. insert ( key, ( value, index) ) ;
188163 }
189164
190165 fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
191- #[ cfg( parallel_compiler) ]
192- {
193- let shards = self . cache . lock_shards ( ) ;
194- for shard in shards. iter ( ) {
195- for ( k, v) in shard. iter_enumerated ( ) {
196- if let Some ( v) = v {
197- f ( & k, & v. 0 , v. 1 ) ;
198- }
199- }
200- }
201- }
202- #[ cfg( not( parallel_compiler) ) ]
203- {
204- let map = self . cache . lock ( ) ;
205- for ( k, v) in map. iter_enumerated ( ) {
166+ let shards = self . cache . lock_shards ( ) ;
167+ for shard in shards. iter ( ) {
168+ for ( k, v) in shard. iter_enumerated ( ) {
206169 if let Some ( v) = v {
207170 f ( & k, & v. 0 , v. 1 ) ;
208171 }
0 commit comments