rust/compiler/rustc_query_system/src/query/config.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.4 KiB
Rust
Raw Normal View History

2020-03-08 16:24:56 +00:00
//! Query configuration and description traits.
use crate::dep_graph::DepNode;
2019-02-05 17:20:45 +00:00
use crate::dep_graph::SerializedDepNodeIndex;
use crate::error::HandleCycleError;
use crate::ich::StableHashingContext;
2020-03-19 13:13:31 +00:00
use crate::query::caches::QueryCache;
use crate::query::{QueryContext, QueryState};
2017-09-18 09:40:13 +00:00
use rustc_data_structures::fingerprint::Fingerprint;
use std::fmt::Debug;
2019-06-12 12:39:12 +00:00
use std::hash::Hash;
2017-09-18 09:40:13 +00:00
pub trait QueryConfig<Qcx: QueryContext> {
const NAME: &'static str;
type Key: Eq + Hash + Clone + Debug;
type Value: Debug;
type Stored: Debug + Clone + std::borrow::Borrow<Self::Value>;
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
// Don't use this method to access query results, instead use the methods on TyCtxt
2022-12-23 13:09:49 +00:00
fn query_state<'a>(tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::DepKind>
where
Qcx: 'a;
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_cache<'a>(tcx: Qcx) -> &'a Self::Cache
where
Qcx: 'a;
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn make_vtable(tcx: Qcx, key: &Self::Key) -> QueryVTable<Qcx, Self::Key, Self::Value>;
fn cache_on_disk(tcx: Qcx::DepContext, key: &Self::Key) -> bool;
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Stored;
2018-06-13 13:44:43 +00:00
}
#[derive(Copy, Clone)]
pub struct QueryVTable<Qcx: QueryContext, K, V> {
2020-03-06 21:56:05 +00:00
pub anon: bool,
pub dep_kind: Qcx::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,
pub feedable: bool,
2020-03-06 21:15:46 +00:00
pub compute: fn(Qcx::DepContext, K) -> V,
2021-10-16 20:31:48 +00:00
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
pub handle_cycle_error: HandleCycleError,
// NOTE: this is also `None` if `cache_on_disk()` returns false, not just if it's unsupported by the query
pub try_load_from_disk: Option<fn(Qcx, SerializedDepNodeIndex) -> Option<V>>,
}
impl<Qcx: QueryContext, K, V> QueryVTable<Qcx, K, V> {
pub(crate) fn to_dep_node(&self, tcx: Qcx::DepContext, key: &K) -> DepNode<Qcx::DepKind>
where
K: crate::dep_graph::DepNodeParams<Qcx::DepContext>,
{
DepNode::construct(tcx, self.dep_kind, key)
2020-03-28 12:12:20 +00:00
}
pub(crate) fn compute(&self, tcx: Qcx::DepContext, key: K) -> V {
2021-07-11 18:08:17 +00:00
(self.compute)(tcx, key)
}
2020-03-06 21:15:46 +00:00
}