]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_query_system/src/query/config.rs
Run the tools builder on all PRs
[rust.git] / compiler / rustc_query_system / src / query / config.rs
1 //! Query configuration and description traits.
2
3 use crate::dep_graph::{DepNode, DepNodeParams, SerializedDepNodeIndex};
4 use crate::error::HandleCycleError;
5 use crate::ich::StableHashingContext;
6 use crate::query::caches::QueryCache;
7 use crate::query::{QueryContext, QueryState};
8
9 use rustc_data_structures::fingerprint::Fingerprint;
10 use std::fmt::Debug;
11 use std::hash::Hash;
12
13 pub type HashResult<Qcx, Q> =
14     Option<fn(&mut StableHashingContext<'_>, &<Q as QueryConfig<Qcx>>::Value) -> Fingerprint>;
15
16 pub type TryLoadFromDisk<Qcx, Q> =
17     Option<fn(Qcx, SerializedDepNodeIndex) -> Option<<Q as QueryConfig<Qcx>>::Value>>;
18
19 pub trait QueryConfig<Qcx: QueryContext> {
20     const NAME: &'static str;
21
22     type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Clone + Debug;
23     type Value: Debug;
24     type Stored: Debug + Clone + std::borrow::Borrow<Self::Value>;
25
26     type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
27
28     // Don't use this method to access query results, instead use the methods on TyCtxt
29     fn query_state<'a>(tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::DepKind>
30     where
31         Qcx: 'a;
32
33     // Don't use this method to access query results, instead use the methods on TyCtxt
34     fn query_cache<'a>(tcx: Qcx) -> &'a Self::Cache
35     where
36         Qcx: 'a;
37
38     fn cache_on_disk(tcx: Qcx::DepContext, key: &Self::Key) -> bool;
39
40     // Don't use this method to compute query results, instead use the methods on TyCtxt
41     fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Stored;
42
43     fn compute(tcx: Qcx, key: &Self::Key) -> fn(Qcx::DepContext, Self::Key) -> Self::Value;
44
45     fn try_load_from_disk(qcx: Qcx, idx: &Self::Key) -> TryLoadFromDisk<Qcx, Self>;
46
47     const ANON: bool;
48     const EVAL_ALWAYS: bool;
49     const DEPTH_LIMIT: bool;
50     const FEEDABLE: bool;
51
52     const DEP_KIND: Qcx::DepKind;
53     const HANDLE_CYCLE_ERROR: HandleCycleError;
54
55     const HASH_RESULT: HashResult<Qcx, Self>;
56
57     // Just here for convernience and checking that the key matches the kind, don't override this.
58     fn construct_dep_node(tcx: Qcx::DepContext, key: &Self::Key) -> DepNode<Qcx::DepKind> {
59         DepNode::construct(tcx, Self::DEP_KIND, key)
60     }
61 }