@@ -94,6 +94,9 @@ pub struct DepKindStruct {
9494 // FIXME: Make this a simple boolean once DepNodeParams::can_reconstruct_query_key
9595 // can be made a specialized associated const.
9696 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 ) ,
97100}
98101
99102impl std:: ops:: Deref for DepKind {
@@ -152,7 +155,8 @@ macro_rules! contains_eval_always_attr {
152155#[ allow( non_upper_case_globals) ]
153156pub mod dep_kind {
154157 use super :: * ;
155- use crate :: ty:: query:: query_keys;
158+ use crate :: ty:: query:: { queries, query_keys} ;
159+ use rustc_query_system:: query:: QueryDescription ;
156160
157161 // We use this for most things when incr. comp. is turned off.
158162 pub const Null : DepKindStruct = DepKindStruct {
@@ -161,6 +165,7 @@ pub mod dep_kind {
161165 is_eval_always : false ,
162166
163167 can_reconstruct_query_key : || true ,
168+ try_load_from_on_disk_cache : |_, _| { } ,
164169 } ;
165170
166171 // Represents metadata from an extern crate.
@@ -170,6 +175,7 @@ pub mod dep_kind {
170175 is_eval_always : true ,
171176
172177 can_reconstruct_query_key : || true ,
178+ try_load_from_on_disk_cache : |_, _| { } ,
173179 } ;
174180
175181 pub const TraitSelect : DepKindStruct = DepKindStruct {
@@ -178,6 +184,7 @@ pub mod dep_kind {
178184 is_eval_always : false ,
179185
180186 can_reconstruct_query_key : || false ,
187+ try_load_from_on_disk_cache : |_, _| { } ,
181188 } ;
182189
183190 pub const CompileCodegenUnit : DepKindStruct = DepKindStruct {
@@ -186,6 +193,7 @@ pub mod dep_kind {
186193 is_eval_always : false ,
187194
188195 can_reconstruct_query_key : || false ,
196+ try_load_from_on_disk_cache : |_, _| { } ,
189197 } ;
190198
191199 macro_rules! define_query_dep_kinds {
@@ -205,11 +213,32 @@ pub mod dep_kind {
205213 :: can_reconstruct_query_key( )
206214 }
207215
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+
208236 DepKindStruct {
209237 has_params,
210238 is_anon,
211239 is_eval_always,
212240 can_reconstruct_query_key,
241+ try_load_from_on_disk_cache,
213242 }
214243 } ; ) *
215244 ) ;
0 commit comments