Skip to content

Commit 3c43aa5

Browse files
committed
Auto merge of #50102 - Zoxc:query-nomacro, r=michaelwoerister
Move query code outside macros and store query jobs separately from query results Based on #50067 r? @michaelwoerister
2 parents 71d3dac + f678bf0 commit 3c43aa5

File tree

11 files changed

+508
-509
lines changed

11 files changed

+508
-509
lines changed

src/librustc/ty/maps/config.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,45 @@
99
// except according to those terms.
1010

1111
use dep_graph::SerializedDepNodeIndex;
12+
use dep_graph::DepNode;
1213
use hir::def_id::{CrateNum, DefId, DefIndex};
1314
use mir::interpret::{GlobalId};
1415
use traits::query::{CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal};
1516
use ty::{self, ParamEnvAnd, Ty, TyCtxt};
1617
use ty::subst::Substs;
1718
use ty::maps::queries;
19+
use ty::maps::Query;
20+
use ty::maps::QueryMap;
1821

1922
use std::hash::Hash;
23+
use std::fmt::Debug;
2024
use syntax_pos::symbol::InternedString;
25+
use rustc_data_structures::sync::Lock;
26+
use rustc_data_structures::stable_hasher::HashStable;
27+
use ich::StableHashingContext;
2128

2229
/// Query configuration and description traits.
2330
24-
pub trait QueryConfig {
25-
type Key: Eq + Hash + Clone;
26-
type Value;
31+
pub trait QueryConfig<'tcx> {
32+
const NAME: &'static str;
33+
34+
type Key: Eq + Hash + Clone + Debug;
35+
type Value: Clone + for<'a> HashStable<StableHashingContext<'a>>;
36+
37+
fn query(key: Self::Key) -> Query<'tcx>;
38+
39+
// Don't use this method to access query results, instead use the methods on TyCtxt
40+
fn query_map<'a>(tcx: TyCtxt<'a, 'tcx, '_>) -> &'a Lock<QueryMap<'tcx, Self>>;
41+
42+
fn to_dep_node(tcx: TyCtxt<'_, 'tcx, '_>, key: &Self::Key) -> DepNode;
43+
44+
// Don't use this method to compute query results, instead use the methods on TyCtxt
45+
fn compute(tcx: TyCtxt<'_, 'tcx, '_>, key: Self::Key) -> Self::Value;
46+
47+
fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>) -> Self::Value;
2748
}
2849

29-
pub(super) trait QueryDescription<'tcx>: QueryConfig {
50+
pub trait QueryDescription<'tcx>: QueryConfig<'tcx> {
3051
fn describe(tcx: TyCtxt, key: Self::Key) -> String;
3152

3253
#[inline]
@@ -41,7 +62,7 @@ pub(super) trait QueryDescription<'tcx>: QueryConfig {
4162
}
4263
}
4364

44-
impl<'tcx, M: QueryConfig<Key=DefId>> QueryDescription<'tcx> for M {
65+
impl<'tcx, M: QueryConfig<'tcx, Key=DefId>> QueryDescription<'tcx> for M {
4566
default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
4667
if !tcx.sess.verbose() {
4768
format!("processing `{}`", tcx.item_path_str(def_id))

src/librustc/ty/maps/job.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ use ty::context::TyCtxt;
1717
use errors::Diagnostic;
1818

1919
/// Indicates the state of a query for a given key in a query map
20-
pub(super) enum QueryResult<'tcx, T> {
20+
pub(super) enum QueryResult<'tcx> {
2121
/// An already executing query. The query job can be used to await for its completion
2222
Started(Lrc<QueryJob<'tcx>>),
2323

24-
/// The query is complete and produced `T`
25-
Complete(T),
26-
2724
/// The query panicked. Queries trying to wait on this will raise a fatal error / silently panic
2825
Poisoned,
2926
}

src/librustc/ty/maps/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use dep_graph::{DepConstructor, DepNode};
12-
use errors::DiagnosticBuilder;
1312
use hir::def_id::{CrateNum, DefId, DefIndex};
1413
use hir::def::{Def, Export};
1514
use hir::{self, TraitCandidate, ItemLocalId, TransFnAttrs};
@@ -43,7 +42,7 @@ use ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
4342
use ty::steal::Steal;
4443
use ty::subst::Substs;
4544
use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
46-
use util::common::{profq_msg, ErrorReported, ProfileQueriesMsg};
45+
use util::common::{ErrorReported};
4746

4847
use rustc_data_structures::indexed_set::IdxSetBuf;
4948
use rustc_target::spec::PanicStrategy;
@@ -68,7 +67,6 @@ pub use self::plumbing::force_from_dep_node;
6867

6968
mod job;
7069
pub use self::job::{QueryJob, QueryInfo};
71-
use self::job::QueryResult;
7270

7371
mod keys;
7472
pub use self::keys::Key;

src/librustc/ty/maps/on_disk_cache.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use syntax::codemap::{CodeMap, StableFilemapId};
3030
use syntax_pos::{BytePos, Span, DUMMY_SP, FileMap};
3131
use syntax_pos::hygiene::{Mark, SyntaxContext, ExpnInfo};
3232
use ty;
33-
use ty::maps::job::QueryResult;
3433
use ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
3534
use ty::context::TyCtxt;
3635
use util::common::time;
@@ -239,14 +238,12 @@ impl<'sess> OnDiskCache<'sess> {
239238
encode_query_results::<specialization_graph_of, _>(tcx, enc, qri)?;
240239

241240
// const eval is special, it only encodes successfully evaluated constants
242-
use ty::maps::plumbing::GetCacheInternal;
243-
for (key, entry) in const_eval::get_cache_internal(tcx).map.iter() {
241+
use ty::maps::QueryConfig;
242+
let map = const_eval::query_map(tcx).borrow();
243+
assert!(map.active.is_empty());
244+
for (key, entry) in map.results.iter() {
244245
use ty::maps::config::QueryDescription;
245246
if const_eval::cache_on_disk(key.clone()) {
246-
let entry = match *entry {
247-
QueryResult::Complete(ref v) => v,
248-
_ => panic!("incomplete query"),
249-
};
250247
if let Ok(ref value) = entry.value {
251248
let dep_node = SerializedDepNodeIndex::new(entry.index.index());
252249

@@ -1124,7 +1121,7 @@ fn encode_query_results<'enc, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11241121
encoder: &mut CacheEncoder<'enc, 'a, 'tcx, E>,
11251122
query_result_index: &mut EncodedQueryResultIndex)
11261123
-> Result<(), E::Error>
1127-
where Q: super::plumbing::GetCacheInternal<'tcx>,
1124+
where Q: super::config::QueryDescription<'tcx>,
11281125
E: 'enc + TyEncoder,
11291126
Q::Value: Encodable,
11301127
{
@@ -1133,12 +1130,10 @@ fn encode_query_results<'enc, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11331130

11341131
time(tcx.sess, desc, || {
11351132

1136-
for (key, entry) in Q::get_cache_internal(tcx).map.iter() {
1133+
let map = Q::query_map(tcx).borrow();
1134+
assert!(map.active.is_empty());
1135+
for (key, entry) in map.results.iter() {
11371136
if Q::cache_on_disk(key.clone()) {
1138-
let entry = match *entry {
1139-
QueryResult::Complete(ref v) => v,
1140-
_ => panic!("incomplete query"),
1141-
};
11421137
let dep_node = SerializedDepNodeIndex::new(entry.index.index());
11431138

11441139
// Record position of the cache entry

0 commit comments

Comments
 (0)