@@ -5,7 +5,6 @@ use rustc_data_structures::fx::FxHashMap;
5
5
use rustc_data_structures:: sharded;
6
6
#[ cfg( parallel_compiler) ]
7
7
use rustc_data_structures:: sharded:: Sharded ;
8
- #[ cfg( not( parallel_compiler) ) ]
9
8
use rustc_data_structures:: sync:: Lock ;
10
9
use rustc_data_structures:: sync:: WorkerLocal ;
11
10
use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -117,6 +116,52 @@ where
117
116
}
118
117
}
119
118
119
+ pub struct SingleCacheSelector ;
120
+
121
+ impl < ' tcx , V : ' tcx > CacheSelector < ' tcx , V > for SingleCacheSelector {
122
+ type Cache = SingleCache < V >
123
+ where
124
+ V : Copy ;
125
+ type ArenaCache = ArenaCache < ' tcx , ( ) , V > ;
126
+ }
127
+
128
+ pub struct SingleCache < V > {
129
+ cache : Lock < Option < ( V , DepNodeIndex ) > > ,
130
+ }
131
+
132
+ impl < V > Default for SingleCache < V > {
133
+ fn default ( ) -> Self {
134
+ SingleCache { cache : Lock :: new ( None ) }
135
+ }
136
+ }
137
+
138
+ impl < V : Copy + Debug > QueryStorage for SingleCache < V > {
139
+ type Value = V ;
140
+ type Stored = V ;
141
+ }
142
+
143
+ impl < V > QueryCache for SingleCache < V >
144
+ where
145
+ V : Copy + Debug ,
146
+ {
147
+ type Key = ( ) ;
148
+
149
+ #[ inline( always) ]
150
+ fn lookup ( & self , _key : & ( ) ) -> Option < ( V , DepNodeIndex ) > {
151
+ * self . cache . lock ( )
152
+ }
153
+
154
+ #[ inline]
155
+ fn complete ( & self , _key : ( ) , value : V , index : DepNodeIndex ) -> Self :: Stored {
156
+ * self . cache . lock ( ) = Some ( ( value. clone ( ) , index) ) ;
157
+ value
158
+ }
159
+
160
+ fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
161
+ self . cache . lock ( ) . as_ref ( ) . map ( |value| f ( & ( ) , & value. 0 , value. 1 ) ) ;
162
+ }
163
+ }
164
+
120
165
pub struct ArenaCache < ' tcx , K , V > {
121
166
arena : WorkerLocal < TypedArena < ( V , DepNodeIndex ) > > ,
122
167
#[ cfg( parallel_compiler) ]
0 commit comments