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.

78 lines
2.6 KiB
Rust
Raw Normal View History

2020-03-08 16:24:56 +00:00
//! Query configuration and description traits.
use std::fmt::Debug;
2019-06-12 12:39:12 +00:00
use std::hash::Hash;
use rustc_data_structures::fingerprint::Fingerprint;
2023-08-27 21:32:55 +00:00
use rustc_span::ErrorGuaranteed;
use crate::dep_graph::{DepKind, DepNode, DepNodeParams, 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::{CycleError, DepNodeIndex, QueryContext, QueryState};
2017-09-18 09:40:13 +00:00
pub type HashResult<V> = Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>;
pub trait QueryConfig<Qcx: QueryContext>: Copy {
fn name(self) -> &'static str;
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;
type Value: Copy;
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
fn format_value(self) -> fn(&Self::Value) -> String;
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(self, tcx: Qcx) -> &'a QueryState<Self::Key>
where
Qcx: 'a;
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_cache<'a>(self, tcx: Qcx) -> &'a Self::Cache
where
Qcx: 'a;
fn cache_on_disk(self, 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(self, tcx: Qcx::DepContext, k: Self::Key) -> Self::Value;
fn compute(self, tcx: Qcx, key: Self::Key) -> Self::Value;
2023-02-07 07:32:30 +00:00
fn try_load_from_disk(
self,
tcx: Qcx,
key: &Self::Key,
prev_index: SerializedDepNodeIndex,
index: DepNodeIndex,
) -> Option<Self::Value>;
fn loadable_from_disk(self, qcx: Qcx, key: &Self::Key, idx: SerializedDepNodeIndex) -> bool;
2023-03-26 10:24:44 +00:00
/// Synthesize an error value to let compilation continue after a cycle.
fn value_from_cycle_error(
2023-02-07 07:32:30 +00:00
self,
tcx: Qcx::DepContext,
cycle_error: &CycleError,
2023-08-27 21:32:55 +00:00
guar: ErrorGuaranteed,
2023-02-07 07:32:30 +00:00
) -> Self::Value;
fn anon(self) -> bool;
fn eval_always(self) -> bool;
fn depth_limit(self) -> bool;
fn feedable(self) -> bool;
fn dep_kind(self) -> DepKind;
fn handle_cycle_error(self) -> HandleCycleError;
fn hash_result(self) -> HashResult<Self::Value>;
2020-03-28 12:12:20 +00:00
// Just here for convenience and checking that the key matches the kind, don't override this.
fn construct_dep_node(self, tcx: Qcx::DepContext, key: &Self::Key) -> DepNode {
DepNode::construct(tcx, self.dep_kind(), key)
2021-07-11 18:08:17 +00:00
}
2020-03-06 21:15:46 +00:00
}