2020-03-08 16:24:56 +00:00
|
|
|
//! Query configuration and description traits.
|
|
|
|
|
2022-12-30 22:25:19 +00:00
|
|
|
use crate::dep_graph::{DepNode, DepNodeParams, SerializedDepNodeIndex};
|
2022-09-02 01:43:12 +00:00
|
|
|
use crate::error::HandleCycleError;
|
2021-09-25 23:40:17 +00:00
|
|
|
use crate::ich::StableHashingContext;
|
2020-03-19 13:13:31 +00:00
|
|
|
use crate::query::caches::QueryCache;
|
2023-02-07 07:32:30 +00:00
|
|
|
use crate::query::{QueryContext, QueryInfo, QueryState};
|
2017-09-18 09:40:13 +00:00
|
|
|
|
2019-01-20 04:44:02 +00:00
|
|
|
use rustc_data_structures::fingerprint::Fingerprint;
|
2018-04-19 00:33:24 +00:00
|
|
|
use std::fmt::Debug;
|
2019-06-12 12:39:12 +00:00
|
|
|
use std::hash::Hash;
|
2017-09-18 09:40:13 +00:00
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
pub type HashResult<V> = Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>;
|
2022-12-30 22:25:19 +00:00
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
pub type TryLoadFromDisk<Qcx, V> = Option<fn(Qcx, SerializedDepNodeIndex) -> Option<V>>;
|
2022-12-30 22:25:19 +00:00
|
|
|
|
2023-02-25 21:15:30 +00:00
|
|
|
pub trait QueryConfig<Qcx: QueryContext>: Copy {
|
2023-02-07 07:32:30 +00:00
|
|
|
fn name(self) -> &'static str;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
2023-02-17 16:33:05 +00:00
|
|
|
// `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap,
|
|
|
|
// but it isn't necessary.
|
|
|
|
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Copy + Debug;
|
2023-02-08 18:53:48 +00:00
|
|
|
type Value: Debug + Copy;
|
2022-11-05 15:04:43 +00:00
|
|
|
|
2023-02-08 18:53:48 +00:00
|
|
|
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
|
2022-11-05 15:04:43 +00:00
|
|
|
|
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2023-02-07 07:32:30 +00:00
|
|
|
fn query_state<'a>(self, tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::DepKind>
|
2022-11-05 15:04:43 +00:00
|
|
|
where
|
2022-11-05 20:04:19 +00:00
|
|
|
Qcx: 'a;
|
2022-11-05 15:04:43 +00:00
|
|
|
|
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2023-02-07 07:32:30 +00:00
|
|
|
fn query_cache<'a>(self, tcx: Qcx) -> &'a Self::Cache
|
2022-11-05 15:04:43 +00:00
|
|
|
where
|
2022-11-05 20:04:19 +00:00
|
|
|
Qcx: 'a;
|
2022-11-05 15:04:43 +00:00
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
fn cache_on_disk(self, tcx: Qcx::DepContext, key: &Self::Key) -> bool;
|
2022-11-05 15:04:43 +00:00
|
|
|
|
|
|
|
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
2023-02-07 07:32:30 +00:00
|
|
|
fn execute_query(self, tcx: Qcx::DepContext, k: Self::Key) -> Self::Value;
|
2018-04-18 02:35:40 +00:00
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
fn compute(self, tcx: Qcx, key: Self::Key) -> Self::Value;
|
2020-03-06 21:43:08 +00:00
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
fn try_load_from_disk(self, qcx: Qcx, idx: &Self::Key) -> TryLoadFromDisk<Qcx, Self::Value>;
|
2022-12-30 22:25:19 +00:00
|
|
|
|
2023-03-06 14:57:05 +00:00
|
|
|
fn loadable_from_disk(self, qcx: Qcx, key: &Self::Key, idx: SerializedDepNodeIndex) -> bool;
|
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
fn from_cycle_error(
|
|
|
|
self,
|
|
|
|
tcx: Qcx::DepContext,
|
|
|
|
cycle: &[QueryInfo<Qcx::DepKind>],
|
|
|
|
) -> Self::Value;
|
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
fn anon(self) -> bool;
|
|
|
|
fn eval_always(self) -> bool;
|
|
|
|
fn depth_limit(self) -> bool;
|
|
|
|
fn feedable(self) -> bool;
|
2022-12-30 22:25:19 +00:00
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
fn dep_kind(self) -> Qcx::DepKind;
|
|
|
|
fn handle_cycle_error(self) -> HandleCycleError;
|
|
|
|
fn hash_result(self) -> HashResult<Self::Value>;
|
2020-03-28 12:12:20 +00:00
|
|
|
|
2022-12-30 22:25:19 +00:00
|
|
|
// Just here for convernience and checking that the key matches the kind, don't override this.
|
2023-02-07 07:32:30 +00:00
|
|
|
fn construct_dep_node(self, tcx: Qcx::DepContext, key: &Self::Key) -> DepNode<Qcx::DepKind> {
|
|
|
|
DepNode::construct(tcx, self.dep_kind(), key)
|
2021-07-11 18:08:17 +00:00
|
|
|
}
|
2020-03-06 21:15:46 +00:00
|
|
|
}
|