2020-03-08 16:24:56 +00:00
|
|
|
//! Query configuration and description traits.
|
|
|
|
|
2020-03-27 06:43:11 +00:00
|
|
|
use crate::dep_graph::DepNode;
|
2019-02-05 17:20:45 +00:00
|
|
|
use crate::dep_graph::SerializedDepNodeIndex;
|
2020-03-19 13:13:31 +00:00
|
|
|
use crate::query::caches::QueryCache;
|
|
|
|
use crate::query::plumbing::CycleError;
|
2020-03-27 06:43:11 +00:00
|
|
|
use crate::query::{QueryContext, QueryState};
|
2019-11-11 22:15:36 +00:00
|
|
|
use rustc_data_structures::profiling::ProfileCategory;
|
2020-03-24 19:37:19 +00:00
|
|
|
use rustc_span::def_id::DefId;
|
2017-09-18 09:40:13 +00:00
|
|
|
|
2019-12-22 22:42:04 +00:00
|
|
|
use rustc_data_structures::fingerprint::Fingerprint;
|
2018-10-01 13:31:27 +00:00
|
|
|
use std::borrow::Cow;
|
2018-04-19 00:33:24 +00:00
|
|
|
use std::fmt::Debug;
|
2019-12-22 22:42:04 +00:00
|
|
|
use std::hash::Hash;
|
2017-09-18 09:40:13 +00:00
|
|
|
|
2020-03-24 22:50:47 +00:00
|
|
|
// The parameter `CTX` is required in librustc: implementations may need to access the `'tcx`
|
|
|
|
// lifetime in `CTX = TyCtxt<'tcx>`.
|
2020-03-08 16:24:56 +00:00
|
|
|
pub trait QueryConfig<CTX> {
|
2019-12-13 13:44:08 +00:00
|
|
|
const NAME: &'static str;
|
2018-05-19 17:50:58 +00:00
|
|
|
const CATEGORY: ProfileCategory;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
|
|
|
type Key: Eq + Hash + Clone + Debug;
|
2019-01-20 04:44:02 +00:00
|
|
|
type Value: Clone;
|
2018-06-13 13:44:43 +00:00
|
|
|
}
|
2018-04-18 02:35:40 +00:00
|
|
|
|
2020-03-19 13:13:31 +00:00
|
|
|
pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
|
2019-06-24 23:41:16 +00:00
|
|
|
const ANON: bool;
|
|
|
|
const EVAL_ALWAYS: bool;
|
2020-03-18 19:19:44 +00:00
|
|
|
const DEP_KIND: CTX::DepKind;
|
2019-06-24 23:41:16 +00:00
|
|
|
|
2020-03-24 22:46:47 +00:00
|
|
|
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
|
2020-02-08 06:38:00 +00:00
|
|
|
|
2018-04-27 10:08:54 +00:00
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2020-03-08 17:20:18 +00:00
|
|
|
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
2020-03-18 19:19:44 +00:00
|
|
|
fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode<CTX::DepKind>;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
2018-04-27 10:08:54 +00:00
|
|
|
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
2020-03-08 17:20:18 +00:00
|
|
|
fn compute(tcx: CTX, key: Self::Key) -> Self::Value;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
2020-03-18 19:19:44 +00:00
|
|
|
fn hash_result(
|
|
|
|
hcx: &mut CTX::StableHashingContext,
|
|
|
|
result: &Self::Value,
|
|
|
|
) -> Option<Fingerprint>;
|
2019-01-20 04:44:02 +00:00
|
|
|
|
2020-03-19 07:28:24 +00:00
|
|
|
fn handle_cycle_error(tcx: CTX, error: CycleError<CTX::Query>) -> Self::Value;
|
2017-09-18 09:40:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 13:13:31 +00:00
|
|
|
pub trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {
|
2020-03-08 18:42:11 +00:00
|
|
|
fn describe(tcx: CTX, key: Self::Key) -> Cow<'static, str>;
|
2017-11-14 18:52:49 +00:00
|
|
|
|
2017-12-04 19:08:25 +00:00
|
|
|
#[inline]
|
2020-03-08 18:42:11 +00:00
|
|
|
fn cache_on_disk(_: CTX, _: Self::Key, _: Option<&Self::Value>) -> bool {
|
2017-11-14 18:52:49 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2020-03-08 18:42:11 +00:00
|
|
|
fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option<Self::Value> {
|
2020-03-19 13:13:31 +00:00
|
|
|
panic!("QueryDescription::load_from_disk() called for an unsupported query.")
|
2017-11-14 18:52:49 +00:00
|
|
|
}
|
2017-09-18 09:40:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-08 18:42:11 +00:00
|
|
|
impl<CTX: QueryContext, M> QueryDescription<CTX> for M
|
2020-03-08 17:20:18 +00:00
|
|
|
where
|
2020-03-08 18:42:11 +00:00
|
|
|
M: QueryAccessors<CTX, Key = DefId>,
|
2020-03-08 17:20:18 +00:00
|
|
|
{
|
2020-03-08 18:42:11 +00:00
|
|
|
default fn describe(tcx: CTX, def_id: DefId) -> Cow<'static, str> {
|
2020-03-25 07:02:27 +00:00
|
|
|
if !tcx.verbose() {
|
2018-12-19 10:31:35 +00:00
|
|
|
format!("processing `{}`", tcx.def_path_str(def_id)).into()
|
2017-09-11 17:09:14 +00:00
|
|
|
} else {
|
2019-04-18 02:38:17 +00:00
|
|
|
let name = ::std::any::type_name::<M>();
|
2018-06-06 20:13:52 +00:00
|
|
|
format!("processing {:?} with query `{}`", def_id, name).into()
|
2017-09-11 17:09:14 +00:00
|
|
|
}
|
2017-09-18 09:40:13 +00:00
|
|
|
}
|
2019-09-18 22:14:02 +00:00
|
|
|
|
2020-03-08 18:42:11 +00:00
|
|
|
default fn cache_on_disk(_: CTX, _: Self::Key, _: Option<&Self::Value>) -> bool {
|
2019-09-18 22:14:02 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2020-03-08 18:42:11 +00:00
|
|
|
default fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option<Self::Value> {
|
2020-03-19 13:13:31 +00:00
|
|
|
panic!("QueryDescription::load_from_disk() called for an unsupported query.")
|
2019-09-18 22:14:02 +00:00
|
|
|
}
|
2017-09-18 09:40:13 +00:00
|
|
|
}
|