@@ -19,16 +19,16 @@ pub trait QueryConfig {
1919 type Stored : Clone ;
2020}
2121
22- pub ( crate ) struct QueryVtable < CTX : QueryContext , K , V > {
22+ pub struct QueryVtable < CTX : QueryContext , K , V > {
2323 pub anon : bool ,
2424 pub dep_kind : CTX :: DepKind ,
2525 pub eval_always : bool ,
26+ pub cache_on_disk : bool ,
2627
2728 pub compute : fn ( CTX :: DepContext , K ) -> V ,
2829 pub hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & V ) -> Fingerprint > ,
2930 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 > > ,
3232}
3333
3434impl < CTX : QueryContext , K , V > QueryVtable < CTX , K , V > {
@@ -43,25 +43,21 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
4343 ( self . compute ) ( tcx, key)
4444 }
4545
46- pub ( crate ) fn cache_on_disk ( & self , tcx : CTX , key : & K ) -> bool {
47- ( self . cache_on_disk ) ( tcx, key)
48- }
49-
5046 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+ )
5251 }
5352}
5453
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 > > ;
6256
6357 type Cache : QueryCache < Key = Self :: Key , Stored = Self :: Stored , Value = Self :: Value > ;
6458
59+ fn describe ( tcx : CTX , key : Self :: Key ) -> String ;
60+
6561 // Don't use this method to access query results, instead use the methods on TyCtxt
6662 fn query_state < ' a > ( tcx : CTX ) -> & ' a QueryState < CTX :: DepKind , Self :: Key >
6763 where
@@ -73,43 +69,7 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
7369 CTX : ' a ;
7470
7571 // 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 > ;
8373
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 ;
11575}
0 commit comments