Skip to content

Commit 5bc0460

Browse files
committed
Auto merge of #153387 - Zalathar:call-query, r=<try>
Get rid of `QueryVTable::call_query_method_fn`
2 parents d933cf4 + bab6f12 commit 5bc0460

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
116116
pub cache: C,
117117
pub will_cache_on_disk_for_key_fn: Option<fn(tcx: TyCtxt<'tcx>, key: &C::Key) -> bool>,
118118

119-
/// Function pointer that calls `tcx.$query(key)` for this query and
120-
/// discards the returned value.
121-
///
122-
/// This is a weird thing to be doing, and probably not what you want.
123-
/// It is used for loading query results from disk-cache in some cases.
124-
pub call_query_method_fn: fn(tcx: TyCtxt<'tcx>, key: C::Key),
125-
126119
/// Function pointer that actually calls this query's provider.
127120
/// Also performs some associated secondary tasks; see the macro-defined
128121
/// implementation in `mod invoke_provider_fn` for more details.

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ use rustc_middle::query::on_disk_cache::{
1919
};
2020
use rustc_middle::query::plumbing::QueryVTable;
2121
use rustc_middle::query::{
22-
QueryCache, QueryJobId, QueryKey, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra,
23-
erase,
22+
QueryCache, QueryJobId, QueryKey, QueryMode, QueryStackDeferred, QueryStackFrame,
23+
QueryStackFrameExtra, erase,
2424
};
2525
use rustc_middle::ty::codec::TyEncoder;
2626
use rustc_middle::ty::print::with_reduced_queries;
2727
use rustc_middle::ty::tls::{self, ImplicitCtxt};
2828
use rustc_middle::ty::{self, TyCtxt};
2929
use rustc_serialize::{Decodable, Encodable};
30+
use rustc_span::DUMMY_SP;
3031
use rustc_span::def_id::LOCAL_CRATE;
3132

3233
use 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

Comments
 (0)