2020-03-08 17:24:56 +01:00
|
|
|
//! Query configuration and description traits.
|
|
|
|
|
2022-12-30 23:25:19 +01:00
|
|
|
use crate::dep_graph::{DepNode, DepNodeParams, SerializedDepNodeIndex};
|
2022-09-01 20:43:12 -05:00
|
|
|
use crate::error::HandleCycleError;
|
2021-09-26 01:40:17 +02:00
|
|
|
use crate::ich::StableHashingContext;
|
2020-03-19 14:13:31 +01:00
|
|
|
use crate::query::caches::QueryCache;
|
2022-02-19 22:44:19 -05:00
|
|
|
use crate::query::{QueryContext, QueryState};
|
2017-09-18 05:40:13 -04:00
|
|
|
|
2019-01-20 05:44:02 +01:00
|
|
|
use rustc_data_structures::fingerprint::Fingerprint;
|
2018-04-19 02:33:24 +02:00
|
|
|
use std::fmt::Debug;
|
2019-06-12 14:39:12 +02:00
|
|
|
use std::hash::Hash;
|
2017-09-18 05:40:13 -04:00
|
|
|
|
2022-12-30 23:25:19 +01:00
|
|
|
pub type HashResult<Qcx, Q> =
|
|
|
|
Option<fn(&mut StableHashingContext<'_>, &<Q as QueryConfig<Qcx>>::Value) -> Fingerprint>;
|
|
|
|
|
|
|
|
pub type TryLoadFromDisk<Qcx, Q> =
|
|
|
|
Option<fn(Qcx, SerializedDepNodeIndex) -> Option<<Q as QueryConfig<Qcx>>::Value>>;
|
|
|
|
|
2022-11-05 21:04:19 +01:00
|
|
|
pub trait QueryConfig<Qcx: QueryContext> {
|
2019-12-13 14:44:08 +01:00
|
|
|
const NAME: &'static str;
|
2018-04-19 02:33:24 +02:00
|
|
|
|
2022-12-30 23:25:19 +01:00
|
|
|
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Clone + Debug;
|
2023-02-08 19:53:48 +01:00
|
|
|
type Value: Debug + Copy;
|
2022-11-05 16:04:43 +01:00
|
|
|
|
2023-02-08 19:53:48 +01:00
|
|
|
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
|
2022-11-05 16:04:43 +01:00
|
|
|
|
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2022-12-23 18:39:49 +05:30
|
|
|
fn query_state<'a>(tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::DepKind>
|
2022-11-05 16:04:43 +01:00
|
|
|
where
|
2022-11-05 21:04:19 +01:00
|
|
|
Qcx: 'a;
|
2022-11-05 16:04:43 +01:00
|
|
|
|
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2022-11-05 21:04:19 +01:00
|
|
|
fn query_cache<'a>(tcx: Qcx) -> &'a Self::Cache
|
2022-11-05 16:04:43 +01:00
|
|
|
where
|
2022-11-05 21:04:19 +01:00
|
|
|
Qcx: 'a;
|
2022-11-05 16:04:43 +01:00
|
|
|
|
2022-11-05 21:04:19 +01:00
|
|
|
fn cache_on_disk(tcx: Qcx::DepContext, key: &Self::Key) -> bool;
|
2022-11-05 16:04:43 +01:00
|
|
|
|
|
|
|
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
2023-02-08 19:53:48 +01:00
|
|
|
fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Value;
|
2018-04-18 04:35:40 +02:00
|
|
|
|
2023-02-08 19:53:48 +01:00
|
|
|
fn compute(tcx: Qcx::DepContext, key: Self::Key) -> Self::Value;
|
2020-03-06 22:43:08 +01:00
|
|
|
|
2022-12-30 23:25:19 +01:00
|
|
|
fn try_load_from_disk(qcx: Qcx, idx: &Self::Key) -> TryLoadFromDisk<Qcx, Self>;
|
|
|
|
|
|
|
|
const ANON: bool;
|
|
|
|
const EVAL_ALWAYS: bool;
|
|
|
|
const DEPTH_LIMIT: bool;
|
|
|
|
const FEEDABLE: bool;
|
|
|
|
|
|
|
|
const DEP_KIND: Qcx::DepKind;
|
|
|
|
const HANDLE_CYCLE_ERROR: HandleCycleError;
|
|
|
|
|
|
|
|
const HASH_RESULT: HashResult<Qcx, Self>;
|
2020-03-28 13:12:20 +01:00
|
|
|
|
2022-12-30 23:25:19 +01:00
|
|
|
// Just here for convernience and checking that the key matches the kind, don't override this.
|
|
|
|
fn construct_dep_node(tcx: Qcx::DepContext, key: &Self::Key) -> DepNode<Qcx::DepKind> {
|
|
|
|
DepNode::construct(tcx, Self::DEP_KIND, key)
|
2021-07-11 20:08:17 +02:00
|
|
|
}
|
2020-03-06 22:15:46 +01:00
|
|
|
}
|