Skip to content

Commit 286fbe5

Browse files
committed
Auto merge of #152160 - nnethercote:start-cutting-down-rustc_query_system, r=Zalathar
Start cutting down `rustc_query_system` The query system is implemented in `rustc_query_system`, `rustc_middle`, and `rustc_query_impl`. `rustc_query_system` is hamstrung by not having access to `TyCtxt`, and there seems to be consensus to eliminate it. It's contents can be moved into the other two crates. Moving as much stuff as possible to `rustc_query_impl` is preferred, because `rustc_middle` is already so big. This PR starts this process. It moves one small function to `rustc_middle` and a good chunk of code to `rustc_query_impl`. Once `rustc_query_system` is gone (or at least shrunk down a lot more) some of the traits like `DepContext`, `QueryContext`, and `QueryDispatcher` will be removable. r? @Zalathar
2 parents be4794c + a6dd4d8 commit 286fbe5

File tree

10 files changed

+821
-845
lines changed

10 files changed

+821
-845
lines changed

compiler/rustc_middle/src/query/inner.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,33 @@
22
//! `tcx.$query(..)` and its variations.
33
44
use rustc_query_system::dep_graph::{DepKind, DepNodeKey};
5-
use rustc_query_system::query::{QueryCache, QueryMode, try_get_cached};
5+
use rustc_query_system::query::{QueryCache, QueryMode};
66
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
77

88
use crate::dep_graph;
99
use crate::query::erase::{self, Erasable, Erased};
1010
use crate::query::plumbing::QueryVTable;
1111
use crate::ty::TyCtxt;
1212

13+
/// Checks whether there is already a value for this key in the in-memory
14+
/// query cache, returning that value if present.
15+
///
16+
/// (Also performs some associated bookkeeping, if a value was found.)
17+
#[inline(always)]
18+
fn try_get_cached<'tcx, C>(tcx: TyCtxt<'tcx>, cache: &C, key: &C::Key) -> Option<C::Value>
19+
where
20+
C: QueryCache,
21+
{
22+
match cache.lookup(key) {
23+
Some((value, index)) => {
24+
tcx.prof.query_cache_hit(index.into());
25+
tcx.dep_graph.read_index(index);
26+
Some(value)
27+
}
28+
None => None,
29+
}
30+
}
31+
1332
/// Shared implementation of `tcx.$query(..)` and `tcx.at(span).$query(..)`
1433
/// for all queries.
1534
#[inline(always)]

0 commit comments

Comments
 (0)