@@ -94,6 +94,9 @@ pub struct DepKindStruct {
94
94
// FIXME: Make this a simple boolean once DepNodeParams::can_reconstruct_query_key
95
95
// can be made a specialized associated const.
96
96
can_reconstruct_query_key : fn ( ) -> bool ,
97
+
98
+ /// Invoke a query to put the on-disk cached value in memory.
99
+ pub ( super ) try_load_from_on_disk_cache : fn ( TyCtxt < ' _ > , & DepNode ) ,
97
100
}
98
101
99
102
impl std:: ops:: Deref for DepKind {
@@ -152,7 +155,8 @@ macro_rules! contains_eval_always_attr {
152
155
#[ allow( non_upper_case_globals) ]
153
156
pub mod dep_kind {
154
157
use super :: * ;
155
- use crate :: ty:: query:: query_keys;
158
+ use crate :: ty:: query:: { queries, query_keys} ;
159
+ use rustc_query_system:: query:: QueryDescription ;
156
160
157
161
// We use this for most things when incr. comp. is turned off.
158
162
pub const Null : DepKindStruct = DepKindStruct {
@@ -161,6 +165,7 @@ pub mod dep_kind {
161
165
is_eval_always : false ,
162
166
163
167
can_reconstruct_query_key : || true ,
168
+ try_load_from_on_disk_cache : |_, _| { } ,
164
169
} ;
165
170
166
171
// Represents metadata from an extern crate.
@@ -170,6 +175,7 @@ pub mod dep_kind {
170
175
is_eval_always : true ,
171
176
172
177
can_reconstruct_query_key : || true ,
178
+ try_load_from_on_disk_cache : |_, _| { } ,
173
179
} ;
174
180
175
181
pub const TraitSelect : DepKindStruct = DepKindStruct {
@@ -178,6 +184,7 @@ pub mod dep_kind {
178
184
is_eval_always : false ,
179
185
180
186
can_reconstruct_query_key : || false ,
187
+ try_load_from_on_disk_cache : |_, _| { } ,
181
188
} ;
182
189
183
190
pub const CompileCodegenUnit : DepKindStruct = DepKindStruct {
@@ -186,6 +193,7 @@ pub mod dep_kind {
186
193
is_eval_always : false ,
187
194
188
195
can_reconstruct_query_key : || false ,
196
+ try_load_from_on_disk_cache : |_, _| { } ,
189
197
} ;
190
198
191
199
macro_rules! define_query_dep_kinds {
@@ -205,11 +213,32 @@ pub mod dep_kind {
205
213
:: can_reconstruct_query_key( )
206
214
}
207
215
216
+ fn recover<' tcx>( tcx: TyCtxt <' tcx>, dep_node: & DepNode ) -> Option <query_keys:: $variant<' tcx>> {
217
+ <query_keys:: $variant<' _> as DepNodeParams <TyCtxt <' _>>>:: recover( tcx, dep_node)
218
+ }
219
+
220
+ fn try_load_from_on_disk_cache( tcx: TyCtxt <' _>, dep_node: & DepNode ) {
221
+ if !can_reconstruct_query_key( ) {
222
+ return
223
+ }
224
+
225
+ debug_assert!( tcx. dep_graph
226
+ . node_color( dep_node)
227
+ . map( |c| c. is_green( ) )
228
+ . unwrap_or( false ) ) ;
229
+
230
+ let key = recover( tcx, dep_node) . unwrap_or_else( || panic!( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash) ) ;
231
+ if queries:: $variant:: cache_on_disk( tcx, & key, None ) {
232
+ let _ = tcx. $variant( key) ;
233
+ }
234
+ }
235
+
208
236
DepKindStruct {
209
237
has_params,
210
238
is_anon,
211
239
is_eval_always,
212
240
can_reconstruct_query_key,
241
+ try_load_from_on_disk_cache,
213
242
}
214
243
} ; ) *
215
244
) ;
0 commit comments