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;
|
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;
|
2022-02-20 03:44:19 +00:00
|
|
|
use crate::query::{QueryContext, 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
|
|
|
|
2020-10-12 14:04:49 +00:00
|
|
|
pub trait QueryConfig {
|
2019-12-13 13:44:08 +00:00
|
|
|
const NAME: &'static str;
|
2018-04-19 00:33:24 +00:00
|
|
|
|
|
|
|
type Key: Eq + Hash + Clone + Debug;
|
2020-03-27 17:41:13 +00:00
|
|
|
type Value;
|
|
|
|
type Stored: Clone;
|
2018-06-13 13:44:43 +00:00
|
|
|
}
|
2018-04-18 02:35:40 +00:00
|
|
|
|
2022-09-02 01:43:12 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2022-07-19 23:57:44 +00:00
|
|
|
pub struct QueryVTable<CTX: QueryContext, K, V> {
|
2020-03-06 21:56:05 +00:00
|
|
|
pub anon: bool,
|
|
|
|
pub dep_kind: CTX::DepKind,
|
2020-03-06 21:15:46 +00:00
|
|
|
pub eval_always: bool,
|
2022-08-24 01:42:12 +00:00
|
|
|
pub depth_limit: bool,
|
2020-03-06 21:15:46 +00:00
|
|
|
|
2021-07-11 18:08:17 +00:00
|
|
|
pub compute: fn(CTX::DepContext, K) -> V,
|
2021-10-16 20:31:48 +00:00
|
|
|
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
2022-09-02 01:43:12 +00:00
|
|
|
pub handle_cycle_error: HandleCycleError,
|
2022-09-07 00:09:32 +00:00
|
|
|
// NOTE: this is also `None` if `cache_on_disk()` returns false, not just if it's unsupported by the query
|
2021-10-17 15:37:20 +00:00
|
|
|
pub try_load_from_disk: Option<fn(CTX, SerializedDepNodeIndex) -> Option<V>>,
|
2020-03-06 21:43:08 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 23:57:44 +00:00
|
|
|
impl<CTX: QueryContext, K, V> QueryVTable<CTX, K, V> {
|
2020-10-18 19:01:36 +00:00
|
|
|
pub(crate) fn to_dep_node(&self, tcx: CTX::DepContext, key: &K) -> DepNode<CTX::DepKind>
|
2020-03-28 12:51:37 +00:00
|
|
|
where
|
2020-10-18 19:01:36 +00:00
|
|
|
K: crate::dep_graph::DepNodeParams<CTX::DepContext>,
|
2020-03-28 12:51:37 +00:00
|
|
|
{
|
|
|
|
DepNode::construct(tcx, self.dep_kind, key)
|
2020-03-28 12:12:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 18:08:17 +00:00
|
|
|
pub(crate) fn compute(&self, tcx: CTX::DepContext, key: K) -> V {
|
|
|
|
(self.compute)(tcx, key)
|
|
|
|
}
|
2020-03-06 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 15:37:20 +00:00
|
|
|
pub trait QueryDescription<CTX: QueryContext>: QueryConfig {
|
2020-03-27 17:41:13 +00:00
|
|
|
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, 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
|
2022-02-07 16:03:51 +00:00
|
|
|
fn query_state<'a>(tcx: CTX) -> &'a QueryState<Self::Key>
|
2020-12-26 15:36:55 +00:00
|
|
|
where
|
|
|
|
CTX: 'a;
|
2021-02-06 12:49:08 +00:00
|
|
|
|
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2022-02-20 03:44:19 +00:00
|
|
|
fn query_cache<'a>(tcx: CTX) -> &'a Self::Cache
|
2021-02-06 12:49:08 +00:00
|
|
|
where
|
|
|
|
CTX: 'a;
|
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
|
2022-07-19 23:57:44 +00:00
|
|
|
fn make_vtable(tcx: CTX, key: &Self::Key) -> QueryVTable<CTX, Self::Key, Self::Value>;
|
2017-11-14 18:52:49 +00:00
|
|
|
|
2021-10-23 16:12:43 +00:00
|
|
|
fn cache_on_disk(tcx: CTX::DepContext, key: &Self::Key) -> bool;
|
2022-08-29 15:20:14 +00:00
|
|
|
|
|
|
|
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
|
|
|
fn execute_query(tcx: CTX::DepContext, k: Self::Key) -> Self::Stored;
|
2020-03-06 21:15:46 +00:00
|
|
|
}
|