@@ -19,16 +19,16 @@ pub trait QueryConfig {
19
19
type Stored : Clone ;
20
20
}
21
21
22
- pub ( crate ) struct QueryVtable < CTX : QueryContext , K , V > {
22
+ pub struct QueryVtable < CTX : QueryContext , K , V > {
23
23
pub anon : bool ,
24
24
pub dep_kind : CTX :: DepKind ,
25
25
pub eval_always : bool ,
26
+ pub cache_on_disk : bool ,
26
27
27
28
pub compute : fn ( CTX :: DepContext , K ) -> V ,
28
29
pub hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & V ) -> Fingerprint > ,
29
30
pub handle_cycle_error : fn ( CTX , DiagnosticBuilder < ' _ > ) -> V ,
30
- pub cache_on_disk : fn ( CTX , & K ) -> bool ,
31
- pub try_load_from_disk : fn ( CTX , SerializedDepNodeIndex ) -> Option < V > ,
31
+ pub try_load_from_disk : Option < fn ( CTX , SerializedDepNodeIndex ) -> Option < V > > ,
32
32
}
33
33
34
34
impl < CTX : QueryContext , K , V > QueryVtable < CTX , K , V > {
@@ -43,25 +43,21 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
43
43
( self . compute ) ( tcx, key)
44
44
}
45
45
46
- pub ( crate ) fn cache_on_disk ( & self , tcx : CTX , key : & K ) -> bool {
47
- ( self . cache_on_disk ) ( tcx, key)
48
- }
49
-
50
46
pub ( crate ) fn try_load_from_disk ( & self , tcx : CTX , index : SerializedDepNodeIndex ) -> Option < V > {
51
- ( self . try_load_from_disk ) ( tcx, index)
47
+ self . try_load_from_disk
48
+ . expect ( "QueryDescription::load_from_disk() called for an unsupported query." ) (
49
+ tcx, index,
50
+ )
52
51
}
53
52
}
54
53
55
- pub trait QueryAccessors < CTX : QueryContext > : QueryConfig {
56
- const ANON : bool ;
57
- const EVAL_ALWAYS : bool ;
58
- const DEP_KIND : CTX :: DepKind ;
59
- const HASH_RESULT : Option <
60
- fn ( hcx : & mut StableHashingContext < ' _ > , result : & Self :: Value ) -> Fingerprint ,
61
- > ;
54
+ pub trait QueryDescription < CTX : QueryContext > : QueryConfig {
55
+ const TRY_LOAD_FROM_DISK : Option < fn ( CTX , SerializedDepNodeIndex ) -> Option < Self :: Value > > ;
62
56
63
57
type Cache : QueryCache < Key = Self :: Key , Stored = Self :: Stored , Value = Self :: Value > ;
64
58
59
+ fn describe ( tcx : CTX , key : Self :: Key ) -> String ;
60
+
65
61
// Don't use this method to access query results, instead use the methods on TyCtxt
66
62
fn query_state < ' a > ( tcx : CTX ) -> & ' a QueryState < CTX :: DepKind , Self :: Key >
67
63
where
@@ -73,43 +69,7 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
73
69
CTX : ' a ;
74
70
75
71
// Don't use this method to compute query results, instead use the methods on TyCtxt
76
- fn compute_fn ( tcx : CTX , key : & Self :: Key ) -> fn ( CTX :: DepContext , Self :: Key ) -> Self :: Value ;
77
-
78
- fn handle_cycle_error ( tcx : CTX , diag : DiagnosticBuilder < ' _ > ) -> Self :: Value ;
79
- }
80
-
81
- pub trait QueryDescription < CTX : QueryContext > : QueryAccessors < CTX > {
82
- fn describe ( tcx : CTX , key : Self :: Key ) -> String ;
72
+ fn make_vtable ( tcx : CTX , key : & Self :: Key ) -> QueryVtable < CTX , Self :: Key , Self :: Value > ;
83
73
84
- #[ inline]
85
- fn cache_on_disk ( _: CTX , _: & Self :: Key ) -> bool {
86
- false
87
- }
88
-
89
- fn try_load_from_disk ( _: CTX , _: SerializedDepNodeIndex ) -> Option < Self :: Value > {
90
- panic ! ( "QueryDescription::load_from_disk() called for an unsupported query." )
91
- }
92
- }
93
-
94
- pub ( crate ) trait QueryVtableExt < CTX : QueryContext , K , V > {
95
- fn make_vtable ( tcx : CTX , key : & K ) -> QueryVtable < CTX , K , V > ;
96
- }
97
-
98
- impl < CTX , Q > QueryVtableExt < CTX , Q :: Key , Q :: Value > for Q
99
- where
100
- CTX : QueryContext ,
101
- Q : QueryDescription < CTX > ,
102
- {
103
- fn make_vtable ( tcx : CTX , key : & Q :: Key ) -> QueryVtable < CTX , Q :: Key , Q :: Value > {
104
- QueryVtable {
105
- anon : Q :: ANON ,
106
- dep_kind : Q :: DEP_KIND ,
107
- eval_always : Q :: EVAL_ALWAYS ,
108
- hash_result : Q :: HASH_RESULT ,
109
- compute : Q :: compute_fn ( tcx, key) ,
110
- handle_cycle_error : Q :: handle_cycle_error,
111
- cache_on_disk : Q :: cache_on_disk,
112
- try_load_from_disk : Q :: try_load_from_disk,
113
- }
114
- }
74
+ fn cache_on_disk ( tcx : CTX :: DepContext , key : & Self :: Key ) -> bool ;
115
75
}
0 commit comments