@@ -2,7 +2,6 @@ use crate::dep_graph::DepNodeIndex;
2
2
3
3
use rustc_data_structures:: fx:: FxHashMap ;
4
4
use rustc_data_structures:: sharded;
5
- #[ cfg( parallel_compiler) ]
6
5
use rustc_data_structures:: sharded:: Sharded ;
7
6
use rustc_data_structures:: sync:: Lock ;
8
7
use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -37,10 +36,7 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> CacheSelector<'tcx, V> for DefaultCacheSelecto
37
36
}
38
37
39
38
pub struct DefaultCache < K , V > {
40
- #[ cfg( parallel_compiler) ]
41
39
cache : Sharded < FxHashMap < K , ( V , DepNodeIndex ) > > ,
42
- #[ cfg( not( parallel_compiler) ) ]
43
- cache : Lock < FxHashMap < K , ( V , DepNodeIndex ) > > ,
44
40
}
45
41
46
42
impl < K , V > Default for DefaultCache < K , V > {
@@ -60,40 +56,26 @@ where
60
56
#[ inline( always) ]
61
57
fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
62
58
let key_hash = sharded:: make_hash ( key) ;
63
- #[ cfg( parallel_compiler) ]
64
59
let lock = self . cache . get_shard_by_hash ( key_hash) . lock ( ) ;
65
- #[ cfg( not( parallel_compiler) ) ]
66
- let lock = self . cache . lock ( ) ;
60
+
67
61
let result = lock. raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key) ;
68
62
69
63
if let Some ( ( _, value) ) = result { Some ( * value) } else { None }
70
64
}
71
65
72
66
#[ inline]
73
67
fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
74
- #[ cfg( parallel_compiler) ]
75
68
let mut lock = self . cache . get_shard_by_value ( & key) . lock ( ) ;
76
- #[ cfg( not( parallel_compiler) ) ]
77
- let mut lock = self . cache . lock ( ) ;
69
+
78
70
// We may be overwriting another value. This is all right, since the dep-graph
79
71
// will check that the fingerprint matches.
80
72
lock. insert ( key, ( value, index) ) ;
81
73
}
82
74
83
75
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 ( ) {
97
79
f ( k, & v. 0 , v. 1 ) ;
98
80
}
99
81
}
@@ -149,10 +131,7 @@ impl<'tcx, K: Idx, V: 'tcx> CacheSelector<'tcx, V> for VecCacheSelector<K> {
149
131
}
150
132
151
133
pub struct VecCache < K : Idx , V > {
152
- #[ cfg( parallel_compiler) ]
153
134
cache : Sharded < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
154
- #[ cfg( not( parallel_compiler) ) ]
155
- cache : Lock < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
156
135
}
157
136
158
137
impl < K : Idx , V > Default for VecCache < K , V > {
@@ -171,38 +150,22 @@ where
171
150
172
151
#[ inline( always) ]
173
152
fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
174
- #[ cfg( parallel_compiler) ]
175
153
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
+
178
155
if let Some ( Some ( value) ) = lock. get ( * key) { Some ( * value) } else { None }
179
156
}
180
157
181
158
#[ inline]
182
159
fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
183
- #[ cfg( parallel_compiler) ]
184
160
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
+
187
162
lock. insert ( key, ( value, index) ) ;
188
163
}
189
164
190
165
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 ( ) {
206
169
if let Some ( v) = v {
207
170
f ( & k, & v. 0 , v. 1 ) ;
208
171
}
0 commit comments