2020-03-08 17:24:56 +01:00
|
|
|
//! Query configuration and description traits.
|
|
|
|
|
2020-03-27 07:43:11 +01:00
|
|
|
use crate::dep_graph::DepNode;
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::dep_graph::SerializedDepNodeIndex;
|
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;
|
2022-01-23 12:34:26 -06:00
|
|
|
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
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
|
|
|
|
2020-10-12 16:04:49 +02:00
|
|
|
pub trait QueryConfig {
|
2019-12-13 14:44:08 +01:00
|
|
|
const NAME: &'static str;
|
2018-04-19 02:33:24 +02:00
|
|
|
|
|
|
|
type Key: Eq + Hash + Clone + Debug;
|
2020-03-27 18:41:13 +01:00
|
|
|
type Value;
|
|
|
|
type Stored: Clone;
|
2018-06-13 16:44:43 +03:00
|
|
|
}
|
2018-04-18 04:35:40 +02:00
|
|
|
|
2022-07-19 19:57:44 -04:00
|
|
|
pub struct QueryVTable<CTX: QueryContext, K, V> {
|
2020-03-06 22:56:05 +01:00
|
|
|
pub anon: bool,
|
|
|
|
pub dep_kind: CTX::DepKind,
|
2020-03-06 22:15:46 +01:00
|
|
|
pub eval_always: bool,
|
2022-08-24 09:42:12 +08:00
|
|
|
pub depth_limit: bool,
|
2021-10-17 17:37:20 +02:00
|
|
|
pub cache_on_disk: bool,
|
2020-03-06 22:15:46 +01:00
|
|
|
|
2021-07-11 20:08:17 +02:00
|
|
|
pub compute: fn(CTX::DepContext, K) -> V,
|
2021-10-16 22:31:48 +02:00
|
|
|
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
2022-01-23 12:34:26 -06:00
|
|
|
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_, ErrorGuaranteed>) -> V,
|
2021-10-17 17:37:20 +02:00
|
|
|
pub try_load_from_disk: Option<fn(CTX, SerializedDepNodeIndex) -> Option<V>>,
|
2020-03-06 22:43:08 +01:00
|
|
|
}
|
|
|
|
|
2022-07-19 19:57:44 -04:00
|
|
|
impl<CTX: QueryContext, K, V> QueryVTable<CTX, K, V> {
|
2020-10-18 21:01:36 +02:00
|
|
|
pub(crate) fn to_dep_node(&self, tcx: CTX::DepContext, key: &K) -> DepNode<CTX::DepKind>
|
2020-03-28 13:51:37 +01:00
|
|
|
where
|
2020-10-18 21:01:36 +02:00
|
|
|
K: crate::dep_graph::DepNodeParams<CTX::DepContext>,
|
2020-03-28 13:51:37 +01:00
|
|
|
{
|
|
|
|
DepNode::construct(tcx, self.dep_kind, key)
|
2020-03-28 13:12:20 +01:00
|
|
|
}
|
|
|
|
|
2021-07-11 20:08:17 +02:00
|
|
|
pub(crate) fn compute(&self, tcx: CTX::DepContext, key: K) -> V {
|
|
|
|
(self.compute)(tcx, key)
|
|
|
|
}
|
|
|
|
|
2020-03-06 22:43:08 +01:00
|
|
|
pub(crate) fn try_load_from_disk(&self, tcx: CTX, index: SerializedDepNodeIndex) -> Option<V> {
|
2021-10-17 17:37:20 +02:00
|
|
|
self.try_load_from_disk
|
|
|
|
.expect("QueryDescription::load_from_disk() called for an unsupported query.")(
|
|
|
|
tcx, index,
|
|
|
|
)
|
2020-03-06 22:43:08 +01:00
|
|
|
}
|
2020-03-06 22:15:46 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 17:37:20 +02:00
|
|
|
pub trait QueryDescription<CTX: QueryContext>: QueryConfig {
|
|
|
|
const TRY_LOAD_FROM_DISK: Option<fn(CTX, SerializedDepNodeIndex) -> Option<Self::Value>>;
|
2019-06-25 01:41:16 +02:00
|
|
|
|
2020-03-27 18:41:13 +01:00
|
|
|
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
|
2020-02-08 07:38:00 +01:00
|
|
|
|
2021-10-17 17:37:20 +02:00
|
|
|
fn describe(tcx: CTX, key: Self::Key) -> String;
|
|
|
|
|
2018-04-27 12:08:54 +02:00
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2022-02-07 11:03:51 -05:00
|
|
|
fn query_state<'a>(tcx: CTX) -> &'a QueryState<Self::Key>
|
2020-12-26 16:36:55 +01:00
|
|
|
where
|
|
|
|
CTX: 'a;
|
2021-02-06 13:49:08 +01:00
|
|
|
|
|
|
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
2022-02-19 22:44:19 -05:00
|
|
|
fn query_cache<'a>(tcx: CTX) -> &'a Self::Cache
|
2021-02-06 13:49:08 +01:00
|
|
|
where
|
|
|
|
CTX: 'a;
|
2018-04-19 02:33:24 +02:00
|
|
|
|
2018-04-27 12:08:54 +02:00
|
|
|
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
2022-07-19 19:57:44 -04:00
|
|
|
fn make_vtable(tcx: CTX, key: &Self::Key) -> QueryVTable<CTX, Self::Key, Self::Value>;
|
2017-11-14 19:52:49 +01:00
|
|
|
|
2021-10-23 18:12:43 +02:00
|
|
|
fn cache_on_disk(tcx: CTX::DepContext, key: &Self::Key) -> bool;
|
2022-08-29 10:20:14 -05: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 22:15:46 +01:00
|
|
|
}
|