@@ -19,14 +19,15 @@ use rustc_middle::query::on_disk_cache::{
1919} ;
2020use rustc_middle:: query:: plumbing:: QueryVTable ;
2121use rustc_middle:: query:: {
22- QueryCache , QueryJobId , QueryKey , QueryStackDeferred , QueryStackFrame , QueryStackFrameExtra ,
23- erase,
22+ QueryCache , QueryJobId , QueryKey , QueryMode , QueryStackDeferred , QueryStackFrame ,
23+ QueryStackFrameExtra , erase,
2424} ;
2525use rustc_middle:: ty:: codec:: TyEncoder ;
2626use rustc_middle:: ty:: print:: with_reduced_queries;
2727use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
2828use rustc_middle:: ty:: { self , TyCtxt } ;
2929use rustc_serialize:: { Decodable , Encodable } ;
30+ use rustc_span:: DUMMY_SP ;
3031use rustc_span:: def_id:: LOCAL_CRATE ;
3132
3233use crate :: error:: { QueryOverflow , QueryOverflowNote } ;
@@ -221,10 +222,27 @@ pub(crate) fn promote_from_disk_inner<'tcx, Q: GetQueryVTable<'tcx>>(
221222 dep_node. key_fingerprint
222223 )
223224 } ) ;
224- if query. will_cache_on_disk_for_key ( tcx, & key) {
225- // Call `tcx.$query(key)` for its side-effect of loading the disk-cached
226- // value into memory.
227- ( query. call_query_method_fn ) ( tcx, key) ;
225+
226+ // If the recovered key isn't eligible for cache-on-disk, then there's no
227+ // value on disk to promote.
228+ if !query. will_cache_on_disk_for_key ( tcx, & key) {
229+ return ;
230+ }
231+
232+ match query. cache . lookup ( & key) {
233+ // If the value is already in memory, then promotion isn't needed.
234+ Some ( _) => { }
235+
236+ // "Execute" the query to load its disk-cached value into memory.
237+ //
238+ // We know that the key is cache-on-disk and its node is green,
239+ // so there _must_ be a value on disk to load.
240+ //
241+ // FIXME(Zalathar): Is there a reasonable way to skip more of the
242+ // query bookkeeping when doing this?
243+ None => {
244+ ( query. execute_query_fn ) ( tcx, DUMMY_SP , key, QueryMode :: Get ) ;
245+ }
228246 }
229247}
230248
@@ -433,11 +451,6 @@ macro_rules! define_queries {
433451 #[ cfg( not( $cache_on_disk) ) ]
434452 will_cache_on_disk_for_key_fn: None ,
435453
436- call_query_method_fn: |tcx, key| {
437- // Call the query method for its side-effect of loading a value
438- // from disk-cache; the caller doesn't need the value.
439- let _ = tcx. $name( key) ;
440- } ,
441454 invoke_provider_fn: self :: invoke_provider_fn:: __rust_begin_short_backtrace,
442455
443456 #[ cfg( $cache_on_disk) ]
0 commit comments