11//! Query configuration and description traits.
22
3- use crate :: dep_graph:: DepNode ;
4- use crate :: dep_graph:: SerializedDepNodeIndex ;
3+ use crate :: dep_graph:: { DepNode , DepNodeParams , SerializedDepNodeIndex } ;
54use crate :: error:: HandleCycleError ;
65use crate :: ich:: StableHashingContext ;
76use crate :: query:: caches:: QueryCache ;
@@ -11,10 +10,16 @@ use rustc_data_structures::fingerprint::Fingerprint;
1110use std:: fmt:: Debug ;
1211use std:: hash:: Hash ;
1312
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+
1419pub trait QueryConfig < Qcx : QueryContext > {
1520 const NAME : & ' static str ;
1621
17- type Key : Eq + Hash + Clone + Debug ;
22+ type Key : DepNodeParams < Qcx :: DepContext > + Eq + Hash + Clone + Debug ;
1823 type Value : Debug ;
1924 type Stored : Debug + Clone + std:: borrow:: Borrow < Self :: Value > ;
2025
@@ -30,39 +35,27 @@ pub trait QueryConfig<Qcx: QueryContext> {
3035 where
3136 Qcx : ' a ;
3237
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-
3638 fn cache_on_disk ( tcx : Qcx :: DepContext , key : & Self :: Key ) -> bool ;
3739
3840 // Don't use this method to compute query results, instead use the methods on TyCtxt
3941 fn execute_query ( tcx : Qcx :: DepContext , k : Self :: Key ) -> Self :: Stored ;
40- }
4142
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 ;
5644
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 > ;
6456
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)
6760 }
6861}
0 commit comments