Skip to content

Commit 57c3177

Browse files
committed
Make QueryDescription parameter a type.
1 parent f74fd03 commit 57c3177

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

src/librustc/ty/query/config.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use crate::dep_graph::{DepKind, DepNode};
55
use crate::ty::query::caches::QueryCache;
66
use crate::ty::query::plumbing::CycleError;
77
use crate::ty::query::QueryState;
8-
use crate::ty::TyCtxt;
98
use rustc_data_structures::profiling::ProfileCategory;
109
use rustc_hir::def_id::DefId;
1110

1211
use crate::ich::StableHashingContext;
1312
use rustc_data_structures::fingerprint::Fingerprint;
13+
use rustc_session::Session;
1414
use std::borrow::Cow;
1515
use std::fmt::Debug;
1616
use std::hash::Hash;
@@ -25,6 +25,12 @@ pub trait QueryConfig<CTX> {
2525

2626
pub trait QueryContext: Copy {
2727
type Query;
28+
29+
/// Access the session.
30+
fn session(&self) -> &Session;
31+
32+
/// Get string representation from DefPath.
33+
fn def_path_str(&self, def_id: DefId) -> String;
2834
}
2935

3036
pub(crate) trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
@@ -48,41 +54,37 @@ pub(crate) trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
4854
fn handle_cycle_error(tcx: CTX, error: CycleError<CTX>) -> Self::Value;
4955
}
5056

51-
pub(crate) trait QueryDescription<'tcx>: QueryAccessors<TyCtxt<'tcx>> {
52-
fn describe(tcx: TyCtxt<'_>, key: Self::Key) -> Cow<'static, str>;
57+
pub(crate) trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {
58+
fn describe(tcx: CTX, key: Self::Key) -> Cow<'static, str>;
5359

5460
#[inline]
55-
fn cache_on_disk(_: TyCtxt<'tcx>, _: Self::Key, _: Option<&Self::Value>) -> bool {
61+
fn cache_on_disk(_: CTX, _: Self::Key, _: Option<&Self::Value>) -> bool {
5662
false
5763
}
5864

59-
fn try_load_from_disk(_: TyCtxt<'tcx>, _: SerializedDepNodeIndex) -> Option<Self::Value> {
65+
fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option<Self::Value> {
6066
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
6167
}
6268
}
6369

64-
impl<'tcx, M> QueryDescription<'tcx> for M
70+
impl<CTX: QueryContext, M> QueryDescription<CTX> for M
6571
where
66-
M: QueryAccessors<TyCtxt<'tcx>, Key = DefId>,
67-
//M::Cache: QueryCache<DefId, M::Value>,
72+
M: QueryAccessors<CTX, Key = DefId>,
6873
{
69-
default fn describe(tcx: TyCtxt<'_>, def_id: DefId) -> Cow<'static, str> {
70-
if !tcx.sess.verbose() {
74+
default fn describe(tcx: CTX, def_id: DefId) -> Cow<'static, str> {
75+
if !tcx.session().verbose() {
7176
format!("processing `{}`", tcx.def_path_str(def_id)).into()
7277
} else {
7378
let name = ::std::any::type_name::<M>();
7479
format!("processing {:?} with query `{}`", def_id, name).into()
7580
}
7681
}
7782

78-
default fn cache_on_disk(_: TyCtxt<'tcx>, _: Self::Key, _: Option<&Self::Value>) -> bool {
83+
default fn cache_on_disk(_: CTX, _: Self::Key, _: Option<&Self::Value>) -> bool {
7984
false
8085
}
8186

82-
default fn try_load_from_disk(
83-
_: TyCtxt<'tcx>,
84-
_: SerializedDepNodeIndex,
85-
) -> Option<Self::Value> {
87+
default fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option<Self::Value> {
8688
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
8789
}
8890
}

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,8 @@ fn encode_query_results<'a, 'tcx, Q, E>(
994994
query_result_index: &mut EncodedQueryResultIndex,
995995
) -> Result<(), E::Error>
996996
where
997-
Q: super::config::QueryDescription<'tcx, Value: Encodable>,
997+
Q: super::config::QueryDescription<TyCtxt<'tcx>>,
998+
Q::Value: Encodable,
998999
E: 'a + TyEncoder,
9991000
{
10001001
let _timer = tcx

src/librustc/ty/query/plumbing.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use rustc_data_structures::sharded::Sharded;
1717
use rustc_data_structures::sync::{Lock, LockGuard};
1818
use rustc_data_structures::thin_vec::ThinVec;
1919
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level};
20+
use rustc_session::Session;
21+
use rustc_span::def_id::DefId;
2022
use rustc_span::source_map::DUMMY_SP;
2123
use rustc_span::Span;
2224
use std::collections::hash_map::Entry;
@@ -181,7 +183,7 @@ where
181183
mut lookup: QueryLookup<'tcx, TyCtxt<'tcx>, C::Key, C::Sharded>,
182184
) -> TryGetJob<'tcx, C>
183185
where
184-
Q: QueryDescription<'tcx, Key = C::Key, Value = C::Value, Cache = C>,
186+
Q: QueryDescription<TyCtxt<'tcx>, Key = C::Key, Value = C::Value, Cache = C>,
185187
{
186188
let lock = &mut *lookup.lock;
187189

@@ -356,6 +358,14 @@ where
356358

357359
impl QueryContext for TyCtxt<'tcx> {
358360
type Query = Query<'tcx>;
361+
362+
fn session(&self) -> &Session {
363+
&self.sess
364+
}
365+
366+
fn def_path_str(&self, def_id: DefId) -> String {
367+
TyCtxt::def_path_str(*self, def_id)
368+
}
359369
}
360370

361371
impl<'tcx> TyCtxt<'tcx> {
@@ -517,7 +527,7 @@ impl<'tcx> TyCtxt<'tcx> {
517527
}
518528

519529
#[inline(never)]
520-
pub(super) fn get_query<Q: QueryDescription<'tcx> + 'tcx>(
530+
pub(super) fn get_query<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
521531
self,
522532
span: Span,
523533
key: Q::Key,
@@ -536,7 +546,7 @@ impl<'tcx> TyCtxt<'tcx> {
536546
}
537547

538548
#[inline(always)]
539-
fn try_execute_query<Q: QueryDescription<'tcx> + 'tcx>(
549+
fn try_execute_query<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
540550
self,
541551
span: Span,
542552
key: Q::Key,
@@ -614,7 +624,7 @@ impl<'tcx> TyCtxt<'tcx> {
614624
result
615625
}
616626

617-
fn load_from_disk_and_cache_in_memory<Q: QueryDescription<'tcx>>(
627+
fn load_from_disk_and_cache_in_memory<Q: QueryDescription<TyCtxt<'tcx>>>(
618628
self,
619629
key: Q::Key,
620630
prev_dep_node_index: SerializedDepNodeIndex,
@@ -671,7 +681,7 @@ impl<'tcx> TyCtxt<'tcx> {
671681

672682
#[inline(never)]
673683
#[cold]
674-
fn incremental_verify_ich<Q: QueryDescription<'tcx>>(
684+
fn incremental_verify_ich<Q: QueryDescription<TyCtxt<'tcx>>>(
675685
self,
676686
result: &Q::Value,
677687
dep_node: &DepNode,
@@ -698,7 +708,7 @@ impl<'tcx> TyCtxt<'tcx> {
698708
}
699709

700710
#[inline(always)]
701-
fn force_query_with_job<Q: QueryDescription<'tcx> + 'tcx>(
711+
fn force_query_with_job<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
702712
self,
703713
key: Q::Key,
704714
job: JobOwner<'tcx, TyCtxt<'tcx>, Q::Cache>,
@@ -756,7 +766,7 @@ impl<'tcx> TyCtxt<'tcx> {
756766
/// side-effects -- e.g., in order to report errors for erroneous programs.
757767
///
758768
/// Note: The optimization is only available during incr. comp.
759-
pub(super) fn ensure_query<Q: QueryDescription<'tcx> + 'tcx>(self, key: Q::Key) {
769+
pub(super) fn ensure_query<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(self, key: Q::Key) {
760770
if Q::EVAL_ALWAYS {
761771
let _ = self.get_query::<Q>(DUMMY_SP, key);
762772
return;
@@ -784,7 +794,7 @@ impl<'tcx> TyCtxt<'tcx> {
784794
}
785795

786796
#[allow(dead_code)]
787-
pub(super) fn force_query<Q: QueryDescription<'tcx> + 'tcx>(
797+
pub(super) fn force_query<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
788798
self,
789799
key: Q::Key,
790800
span: Span,
@@ -920,7 +930,7 @@ macro_rules! define_queries_inner {
920930
}
921931
}
922932

923-
pub fn describe(&self, tcx: TyCtxt<'_>) -> Cow<'static, str> {
933+
pub fn describe(&self, tcx: TyCtxt<$tcx>) -> Cow<'static, str> {
924934
let (r, name) = match *self {
925935
$(Query::$name(key) => {
926936
(queries::$name::describe(tcx, key), stringify!($name))

src/librustc_macros/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ fn add_query_description_impl(
380380
quote! {
381381
#[allow(unused_variables)]
382382
fn describe(
383-
#tcx: TyCtxt<'_>,
383+
#tcx: TyCtxt<'tcx>,
384384
#key: #arg,
385385
) -> Cow<'static, str> {
386386
format!(#desc).into()
@@ -393,7 +393,7 @@ fn add_query_description_impl(
393393
let desc = desc.unwrap_or(quote! {});
394394

395395
impls.extend(quote! {
396-
impl<'tcx> QueryDescription<'tcx> for queries::#name<'tcx> {
396+
impl<'tcx> QueryDescription<TyCtxt<'tcx>> for queries::#name<'tcx> {
397397
#desc
398398
#cache
399399
}

0 commit comments

Comments
 (0)