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