rustc_query_system/query/
config.rs
1use std::fmt::Debug;
4use std::hash::Hash;
5
6use rustc_data_structures::fingerprint::Fingerprint;
7use rustc_span::ErrorGuaranteed;
8
9use crate::dep_graph::{DepKind, DepNode, DepNodeParams, SerializedDepNodeIndex};
10use crate::error::HandleCycleError;
11use crate::ich::StableHashingContext;
12use crate::query::caches::QueryCache;
13use crate::query::{CycleError, DepNodeIndex, QueryContext, QueryState};
14
15pub type HashResult<V> = Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>;
16
17pub trait QueryConfig<Qcx: QueryContext>: Copy {
18 fn name(self) -> &'static str;
19
20 type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Copy + Debug;
23 type Value: Copy;
24
25 type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
26
27 fn format_value(self) -> fn(&Self::Value) -> String;
28
29 fn query_state<'a>(self, tcx: Qcx) -> &'a QueryState<Self::Key>
31 where
32 Qcx: 'a;
33
34 fn query_cache<'a>(self, tcx: Qcx) -> &'a Self::Cache
36 where
37 Qcx: 'a;
38
39 fn cache_on_disk(self, tcx: Qcx::DepContext, key: &Self::Key) -> bool;
40
41 fn execute_query(self, tcx: Qcx::DepContext, k: Self::Key) -> Self::Value;
43
44 fn compute(self, tcx: Qcx, key: Self::Key) -> Self::Value;
45
46 fn try_load_from_disk(
47 self,
48 tcx: Qcx,
49 key: &Self::Key,
50 prev_index: SerializedDepNodeIndex,
51 index: DepNodeIndex,
52 ) -> Option<Self::Value>;
53
54 fn loadable_from_disk(self, qcx: Qcx, key: &Self::Key, idx: SerializedDepNodeIndex) -> bool;
55
56 fn value_from_cycle_error(
58 self,
59 tcx: Qcx::DepContext,
60 cycle_error: &CycleError,
61 guar: ErrorGuaranteed,
62 ) -> Self::Value;
63
64 fn anon(self) -> bool;
65 fn eval_always(self) -> bool;
66 fn depth_limit(self) -> bool;
67 fn feedable(self) -> bool;
68
69 fn dep_kind(self) -> DepKind;
70 fn handle_cycle_error(self) -> HandleCycleError;
71 fn hash_result(self) -> HashResult<Self::Value>;
72
73 fn construct_dep_node(self, tcx: Qcx::DepContext, key: &Self::Key) -> DepNode {
75 DepNode::construct(tcx, self.dep_kind(), key)
76 }
77}