Skip to content

Commit 9012d4e

Browse files
committed
Get rid of QueryVTable::call_query_method_fn
Calling the query method is equivalent to doing a cache lookup and then calling `execute_query_fn`, so we can just do that manually instead.
1 parent 70d86e3 commit 9012d4e

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
114114
pub state: QueryState<'tcx, C::Key>,
115115
pub cache: C,
116116

117-
/// Function pointer that calls `tcx.$query(key)` for this query and
118-
/// discards the returned value.
119-
///
120-
/// This is a weird thing to be doing, and probably not what you want.
121-
/// It is used for loading query results from disk-cache in some cases.
122-
pub call_query_method_fn: fn(tcx: TyCtxt<'tcx>, key: C::Key),
123-
124117
/// Function pointer that actually calls this query's provider.
125118
/// Also performs some associated secondary tasks; see the macro-defined
126119
/// 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_fn)(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_fn)(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

@@ -427,11 +445,6 @@ macro_rules! define_queries {
427445
state: Default::default(),
428446
cache: Default::default(),
429447

430-
call_query_method_fn: |tcx, key| {
431-
// Call the query method for its side-effect of loading a value
432-
// from disk-cache; the caller doesn't need the value.
433-
let _ = tcx.$name(key);
434-
},
435448
invoke_provider_fn: self::invoke_provider_fn::__rust_begin_short_backtrace,
436449

437450
#[cfg($cache_on_disk)]

0 commit comments

Comments
 (0)