use crate::ty::query::caches::QueryCache;
use crate::ty::query::plumbing::CycleError;
use crate::ty::query::QueryState;
-use crate::ty::TyCtxt;
use rustc_data_structures::profiling::ProfileCategory;
use rustc_hir::def_id::DefId;
use crate::ich::StableHashingContext;
use rustc_data_structures::fingerprint::Fingerprint;
+use rustc_session::Session;
use std::borrow::Cow;
use std::fmt::Debug;
use std::hash::Hash;
pub trait QueryContext: Copy {
type Query;
+
+ /// Access the session.
+ fn session(&self) -> &Session;
+
+ /// Get string representation from DefPath.
+ fn def_path_str(&self, def_id: DefId) -> String;
}
pub(crate) trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
fn handle_cycle_error(tcx: CTX, error: CycleError<CTX>) -> Self::Value;
}
-pub(crate) trait QueryDescription<'tcx>: QueryAccessors<TyCtxt<'tcx>> {
- fn describe(tcx: TyCtxt<'_>, key: Self::Key) -> Cow<'static, str>;
+pub(crate) trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {
+ fn describe(tcx: CTX, key: Self::Key) -> Cow<'static, str>;
#[inline]
- fn cache_on_disk(_: TyCtxt<'tcx>, _: Self::Key, _: Option<&Self::Value>) -> bool {
+ fn cache_on_disk(_: CTX, _: Self::Key, _: Option<&Self::Value>) -> bool {
false
}
- fn try_load_from_disk(_: TyCtxt<'tcx>, _: SerializedDepNodeIndex) -> Option<Self::Value> {
+ fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option<Self::Value> {
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
}
}
-impl<'tcx, M> QueryDescription<'tcx> for M
+impl<CTX: QueryContext, M> QueryDescription<CTX> for M
where
- M: QueryAccessors<TyCtxt<'tcx>, Key = DefId>,
- //M::Cache: QueryCache<DefId, M::Value>,
+ M: QueryAccessors<CTX, Key = DefId>,
{
- default fn describe(tcx: TyCtxt<'_>, def_id: DefId) -> Cow<'static, str> {
- if !tcx.sess.verbose() {
+ default fn describe(tcx: CTX, def_id: DefId) -> Cow<'static, str> {
+ if !tcx.session().verbose() {
format!("processing `{}`", tcx.def_path_str(def_id)).into()
} else {
let name = ::std::any::type_name::<M>();
}
}
- default fn cache_on_disk(_: TyCtxt<'tcx>, _: Self::Key, _: Option<&Self::Value>) -> bool {
+ default fn cache_on_disk(_: CTX, _: Self::Key, _: Option<&Self::Value>) -> bool {
false
}
- default fn try_load_from_disk(
- _: TyCtxt<'tcx>,
- _: SerializedDepNodeIndex,
- ) -> Option<Self::Value> {
+ default fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option<Self::Value> {
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
}
}
query_result_index: &mut EncodedQueryResultIndex,
) -> Result<(), E::Error>
where
- Q: super::config::QueryDescription<'tcx, Value: Encodable>,
+ Q: super::config::QueryDescription<TyCtxt<'tcx>>,
+ Q::Value: Encodable,
E: 'a + TyEncoder,
{
let _timer = tcx
use rustc_data_structures::sync::{Lock, LockGuard};
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level};
+use rustc_session::Session;
+use rustc_span::def_id::DefId;
use rustc_span::source_map::DUMMY_SP;
use rustc_span::Span;
use std::collections::hash_map::Entry;
mut lookup: QueryLookup<'tcx, TyCtxt<'tcx>, C::Key, C::Sharded>,
) -> TryGetJob<'tcx, C>
where
- Q: QueryDescription<'tcx, Key = C::Key, Value = C::Value, Cache = C>,
+ Q: QueryDescription<TyCtxt<'tcx>, Key = C::Key, Value = C::Value, Cache = C>,
{
let lock = &mut *lookup.lock;
impl QueryContext for TyCtxt<'tcx> {
type Query = Query<'tcx>;
+
+ fn session(&self) -> &Session {
+ &self.sess
+ }
+
+ fn def_path_str(&self, def_id: DefId) -> String {
+ TyCtxt::def_path_str(*self, def_id)
+ }
}
impl<'tcx> TyCtxt<'tcx> {
}
#[inline(never)]
- pub(super) fn get_query<Q: QueryDescription<'tcx> + 'tcx>(
+ pub(super) fn get_query<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
self,
span: Span,
key: Q::Key,
}
#[inline(always)]
- fn try_execute_query<Q: QueryDescription<'tcx> + 'tcx>(
+ fn try_execute_query<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
self,
span: Span,
key: Q::Key,
result
}
- fn load_from_disk_and_cache_in_memory<Q: QueryDescription<'tcx>>(
+ fn load_from_disk_and_cache_in_memory<Q: QueryDescription<TyCtxt<'tcx>>>(
self,
key: Q::Key,
prev_dep_node_index: SerializedDepNodeIndex,
#[inline(never)]
#[cold]
- fn incremental_verify_ich<Q: QueryDescription<'tcx>>(
+ fn incremental_verify_ich<Q: QueryDescription<TyCtxt<'tcx>>>(
self,
result: &Q::Value,
dep_node: &DepNode,
}
#[inline(always)]
- fn force_query_with_job<Q: QueryDescription<'tcx> + 'tcx>(
+ fn force_query_with_job<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
self,
key: Q::Key,
job: JobOwner<'tcx, TyCtxt<'tcx>, Q::Cache>,
/// side-effects -- e.g., in order to report errors for erroneous programs.
///
/// Note: The optimization is only available during incr. comp.
- pub(super) fn ensure_query<Q: QueryDescription<'tcx> + 'tcx>(self, key: Q::Key) {
+ pub(super) fn ensure_query<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(self, key: Q::Key) {
if Q::EVAL_ALWAYS {
let _ = self.get_query::<Q>(DUMMY_SP, key);
return;
}
#[allow(dead_code)]
- pub(super) fn force_query<Q: QueryDescription<'tcx> + 'tcx>(
+ pub(super) fn force_query<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
self,
key: Q::Key,
span: Span,
}
}
- pub fn describe(&self, tcx: TyCtxt<'_>) -> Cow<'static, str> {
+ pub fn describe(&self, tcx: TyCtxt<$tcx>) -> Cow<'static, str> {
let (r, name) = match *self {
$(Query::$name(key) => {
(queries::$name::describe(tcx, key), stringify!($name))
quote! {
#[allow(unused_variables)]
fn describe(
- #tcx: TyCtxt<'_>,
+ #tcx: TyCtxt<'tcx>,
#key: #arg,
) -> Cow<'static, str> {
format!(#desc).into()
let desc = desc.unwrap_or(quote! {});
impls.extend(quote! {
- impl<'tcx> QueryDescription<'tcx> for queries::#name<'tcx> {
+ impl<'tcx> QueryDescription<TyCtxt<'tcx>> for queries::#name<'tcx> {
#desc
#cache
}