2019-02-05 17:20:45 +00:00
|
|
|
use crate::dep_graph::SerializedDepNodeIndex;
|
2019-06-24 23:41:16 +00:00
|
|
|
use crate::dep_graph::{DepKind, DepNode};
|
2019-03-29 01:50:31 +00:00
|
|
|
use crate::hir::def_id::{CrateNum, DefId};
|
|
|
|
use crate::ty::TyCtxt;
|
2019-02-05 17:20:45 +00:00
|
|
|
use crate::ty::query::queries;
|
2019-04-04 23:41:49 +00:00
|
|
|
use crate::ty::query::{Query, QueryName};
|
2019-02-05 17:20:45 +00:00
|
|
|
use crate::ty::query::QueryCache;
|
2019-01-24 19:05:19 +00:00
|
|
|
use crate::ty::query::plumbing::CycleError;
|
2019-02-05 17:20:45 +00:00
|
|
|
use crate::util::profiling::ProfileCategory;
|
2017-09-18 09:40:13 +00:00
|
|
|
|
2018-10-01 13:31:27 +00:00
|
|
|
use std::borrow::Cow;
|
2017-09-18 09:40:13 +00:00
|
|
|
use std::hash::Hash;
|
2018-04-19 00:33:24 +00:00
|
|
|
use std::fmt::Debug;
|
2019-06-12 12:39:12 +00:00
|
|
|
use rustc_data_structures::sharded::Sharded;
|
2019-01-20 04:44:02 +00:00
|
|
|
use rustc_data_structures::fingerprint::Fingerprint;
|
2019-02-05 17:20:45 +00:00
|
|
|
use crate::ich::StableHashingContext;
|
2017-09-18 09:40:13 +00:00
|
|
|
|
2018-06-13 13:44:43 +00:00
|
|
|
// Query configuration and description traits.
|
2017-09-18 09:40:13 +00:00
|
|
|
|
2019-06-11 09:21:38 +00:00
|
|
|
// FIXME(eddyb) false positive, the lifetime parameter is used for `Key`/`Value`.
|
|
|
|
#[allow(unused_lifetimes)]
|
2018-04-18 02:35:40 +00:00
|
|
|
pub trait QueryConfig<'tcx> {
|
2019-04-04 23:41:49 +00:00
|
|
|
const NAME: QueryName;
|
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
|
|
|
|
2018-12-03 00:14:35 +00:00
|
|
|
pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
|
2019-06-24 23:41:16 +00:00
|
|
|
const ANON: bool;
|
|
|
|
const EVAL_ALWAYS: bool;
|
|
|
|
|
2018-04-18 02:35:40 +00:00
|
|
|
fn query(key: Self::Key) -> Query<'tcx>;
|
2018-04-27 10:08:54 +00:00
|
|
|
|
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2019-06-12 12:39:12 +00:00
|
|
|
fn query_cache<'a>(tcx: TyCtxt<'tcx>) -> &'a Sharded<QueryCache<'tcx, Self>>;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
2019-06-13 21:48:52 +00:00
|
|
|
fn to_dep_node(tcx: TyCtxt<'tcx>, key: &Self::Key) -> DepNode;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
2019-06-24 23:41:16 +00:00
|
|
|
fn dep_kind() -> DepKind;
|
|
|
|
|
2018-04-27 10:08:54 +00:00
|
|
|
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
2019-06-13 21:48:52 +00:00
|
|
|
fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
2019-01-20 04:44:02 +00:00
|
|
|
fn hash_result(
|
|
|
|
hcx: &mut StableHashingContext<'_>,
|
|
|
|
result: &Self::Value
|
|
|
|
) -> Option<Fingerprint>;
|
|
|
|
|
2019-06-13 21:48:52 +00:00
|
|
|
fn handle_cycle_error(tcx: TyCtxt<'tcx>, error: CycleError<'tcx>) -> Self::Value;
|
2017-09-18 09:40:13 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 00:14:35 +00:00
|
|
|
pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
|
2019-06-13 21:48:52 +00:00
|
|
|
fn describe(tcx: TyCtxt<'_>, key: Self::Key) -> Cow<'static, str>;
|
2017-11-14 18:52:49 +00:00
|
|
|
|
2017-12-04 19:08:25 +00:00
|
|
|
#[inline]
|
2019-04-05 11:11:44 +00:00
|
|
|
fn cache_on_disk(_: TyCtxt<'tcx>, _: Self::Key, _: Option<&Self::Value>) -> bool {
|
2017-11-14 18:52:49 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2019-06-13 21:48:52 +00:00
|
|
|
fn try_load_from_disk(_: TyCtxt<'tcx>, _: SerializedDepNodeIndex) -> Option<Self::Value> {
|
2017-12-04 19:08:25 +00:00
|
|
|
bug!("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
|
|
|
}
|
|
|
|
|
2019-06-11 21:11:55 +00:00
|
|
|
impl<'tcx, M: QueryAccessors<'tcx, Key = DefId>> QueryDescription<'tcx> for M {
|
2019-06-13 21:48:52 +00:00
|
|
|
default fn describe(tcx: TyCtxt<'_>, def_id: DefId) -> Cow<'static, str> {
|
2017-09-11 17:09:14 +00:00
|
|
|
if !tcx.sess.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
|
|
|
|
|
|
|
default fn cache_on_disk(_: TyCtxt<'tcx>, _: Self::Key, _: Option<&Self::Value>) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2019-09-18 22:42:50 +00:00
|
|
|
default fn try_load_from_disk(
|
|
|
|
_: TyCtxt<'tcx>,
|
|
|
|
_: SerializedDepNodeIndex,
|
|
|
|
) -> Option<Self::Value> {
|
2019-09-18 22:14:02 +00:00
|
|
|
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
|
|
|
|
}
|
2017-09-18 09:40:13 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 19:30:23 +00:00
|
|
|
impl<'tcx> QueryDescription<'tcx> for queries::analysis<'tcx> {
|
2019-06-13 21:48:52 +00:00
|
|
|
fn describe(_tcx: TyCtxt<'_>, _: CrateNum) -> Cow<'static, str> {
|
2018-12-08 19:30:23 +00:00
|
|
|
"running analysis passes on this crate".into()
|
|
|
|
}
|
|
|
|
}
|