1
1
//! Query configuration and description traits.
2
2
3
- use crate::dep_graph::DepNode;
4
- use crate::dep_graph::SerializedDepNodeIndex;
3
+ use crate::dep_graph::{DepNode, DepNodeParams, SerializedDepNodeIndex};
5
4
use crate::error::HandleCycleError;
6
5
use crate::ich::StableHashingContext;
7
6
use crate::query::caches::QueryCache;
@@ -11,10 +10,16 @@ use rustc_data_structures::fingerprint::Fingerprint;
11
10
use std::fmt::Debug;
12
11
use std::hash::Hash;
13
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
+
14
19
pub trait QueryConfig<Qcx: QueryContext> {
15
20
const NAME: &'static str;
16
21
17
- type Key: Eq + Hash + Clone + Debug;
22
+ type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Clone + Debug;
18
23
type Value: Debug;
19
24
type Stored: Debug + Clone + std::borrow::Borrow<Self::Value>;
20
25
@@ -30,39 +35,27 @@ pub trait QueryConfig<Qcx: QueryContext> {
30
35
where
31
36
Qcx: 'a;
32
37
33
- // Don't use this method to compute query results, instead use the methods on TyCtxt
34
- fn make_vtable(tcx: Qcx, key: &Self::Key) -> QueryVTable<Qcx, Self::Key, Self::Value>;
35
-
36
38
fn cache_on_disk(tcx: Qcx::DepContext, key: &Self::Key) -> bool;
37
39
38
40
// Don't use this method to compute query results, instead use the methods on TyCtxt
39
41
fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Stored;
40
- }
41
42
42
- #[derive(Copy, Clone)]
43
- pub struct QueryVTable<Qcx: QueryContext, K, V> {
44
- pub anon: bool,
45
- pub dep_kind: Qcx::DepKind,
46
- pub eval_always: bool,
47
- pub depth_limit: bool,
48
- pub feedable: bool,
49
-
50
- pub compute: fn(Qcx::DepContext, K) -> V,
51
- pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
52
- pub handle_cycle_error: HandleCycleError,
53
- // NOTE: this is also `None` if `cache_on_disk()` returns false, not just if it's unsupported by the query
54
- pub try_load_from_disk: Option<fn(Qcx, SerializedDepNodeIndex) -> Option<V>>,
55
- }
43
+ fn compute(tcx: Qcx, key: &Self::Key) -> fn(Qcx::DepContext, Self::Key) -> Self::Value;
56
44
57
- impl<Qcx: QueryContext, K, V> QueryVTable<Qcx, K, V> {
58
- pub(crate) fn to_dep_node(&self, tcx: Qcx::DepContext, key: &K) -> DepNode<Qcx::DepKind>
59
- where
60
- K: crate::dep_graph::DepNodeParams<Qcx::DepContext>,
61
- {
62
- DepNode::construct(tcx, self.dep_kind, key)
63
- }
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>;
64
56
65
- pub(crate) fn compute(&self, tcx: Qcx::DepContext, key: K) -> V {
66
- (self.compute)(tcx, key)
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)
67
60
}
68
61
}
0 commit comments