@@ -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
}
@@ -151,10 +133,7 @@ impl<'tcx, K: Idx, V: 'tcx> CacheSelector<'tcx, V> for VecCacheSelector<K> {
151
133
}
152
134
153
135
pub struct VecCache < K : Idx , V > {
154
- #[ cfg( parallel_compiler) ]
155
136
cache : Sharded < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
156
- #[ cfg( not( parallel_compiler) ) ]
157
- cache : Lock < IndexVec < K , Option < ( V , DepNodeIndex ) > > > ,
158
137
}
159
138
160
139
impl < K : Idx , V > Default for VecCache < K , V > {
@@ -173,38 +152,22 @@ where
173
152
174
153
#[ inline( always) ]
175
154
fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
176
- #[ cfg( parallel_compiler) ]
177
155
let lock = self . cache . get_shard_by_hash ( key. index ( ) as u64 ) . lock ( ) ;
178
- #[ cfg( not( parallel_compiler) ) ]
179
- let lock = self . cache . lock ( ) ;
156
+
180
157
if let Some ( Some ( value) ) = lock. get ( * key) { Some ( * value) } else { None }
181
158
}
182
159
183
160
#[ inline]
184
161
fn complete ( & self , key : K , value : V , index : DepNodeIndex ) {
185
- #[ cfg( parallel_compiler) ]
186
162
let mut lock = self . cache . get_shard_by_hash ( key. index ( ) as u64 ) . lock ( ) ;
187
- #[ cfg( not( parallel_compiler) ) ]
188
- let mut lock = self . cache . lock ( ) ;
163
+
189
164
lock. insert ( key, ( value, index) ) ;
190
165
}
191
166
192
167
fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
193
- #[ cfg( parallel_compiler) ]
194
- {
195
- let shards = self . cache . lock_shards ( ) ;
196
- for shard in shards. iter ( ) {
197
- for ( k, v) in shard. iter_enumerated ( ) {
198
- if let Some ( v) = v {
199
- f ( & k, & v. 0 , v. 1 ) ;
200
- }
201
- }
202
- }
203
- }
204
- #[ cfg( not( parallel_compiler) ) ]
205
- {
206
- let map = self . cache . lock ( ) ;
207
- for ( k, v) in map. iter_enumerated ( ) {
168
+ let shards = self . cache . lock_shards ( ) ;
169
+ for shard in shards. iter ( ) {
170
+ for ( k, v) in shard. iter_enumerated ( ) {
208
171
if let Some ( v) = v {
209
172
f ( & k, & v. 0 , v. 1 ) ;
210
173
}
0 commit comments