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::DepNodeIndex; 8 use crate::query::{QueryContext, QueryInfo, QueryState}; 9 10 use rustc_data_structures::fingerprint::Fingerprint; 11 use std::fmt::Debug; 12 use std::hash::Hash; 13 14 pub type HashResult<V> = Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>; 15 16 pub trait QueryConfig<Qcx: QueryContext>: Copy { name(self) -> &'static str17 fn name(self) -> &'static str; 18 19 // `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap, 20 // but it isn't necessary. 21 type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Copy + Debug; 22 type Value: Copy; 23 24 type Cache: QueryCache<Key = Self::Key, Value = Self::Value>; 25 format_value(self) -> fn(&Self::Value) -> String26 fn format_value(self) -> fn(&Self::Value) -> String; 27 28 // Don't use this method to access query results, instead use the methods on TyCtxt query_state<'a>(self, tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::DepKind> where Qcx: 'a29 fn query_state<'a>(self, 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 query_cache<'a>(self, tcx: Qcx) -> &'a Self::Cache where Qcx: 'a34 fn query_cache<'a>(self, tcx: Qcx) -> &'a Self::Cache 35 where 36 Qcx: 'a; 37 cache_on_disk(self, tcx: Qcx::DepContext, key: &Self::Key) -> bool38 fn cache_on_disk(self, tcx: Qcx::DepContext, key: &Self::Key) -> bool; 39 40 // Don't use this method to compute query results, instead use the methods on TyCtxt execute_query(self, tcx: Qcx::DepContext, k: Self::Key) -> Self::Value41 fn execute_query(self, tcx: Qcx::DepContext, k: Self::Key) -> Self::Value; 42 compute(self, tcx: Qcx, key: Self::Key) -> Self::Value43 fn compute(self, tcx: Qcx, key: Self::Key) -> Self::Value; 44 try_load_from_disk( self, tcx: Qcx, key: &Self::Key, prev_index: SerializedDepNodeIndex, index: DepNodeIndex, ) -> Option<Self::Value>45 fn try_load_from_disk( 46 self, 47 tcx: Qcx, 48 key: &Self::Key, 49 prev_index: SerializedDepNodeIndex, 50 index: DepNodeIndex, 51 ) -> Option<Self::Value>; 52 loadable_from_disk(self, qcx: Qcx, key: &Self::Key, idx: SerializedDepNodeIndex) -> bool53 fn loadable_from_disk(self, qcx: Qcx, key: &Self::Key, idx: SerializedDepNodeIndex) -> bool; 54 55 /// Synthesize an error value to let compilation continue after a cycle. value_from_cycle_error( self, tcx: Qcx::DepContext, cycle: &[QueryInfo<Qcx::DepKind>], ) -> Self::Value56 fn value_from_cycle_error( 57 self, 58 tcx: Qcx::DepContext, 59 cycle: &[QueryInfo<Qcx::DepKind>], 60 ) -> Self::Value; 61 anon(self) -> bool62 fn anon(self) -> bool; eval_always(self) -> bool63 fn eval_always(self) -> bool; depth_limit(self) -> bool64 fn depth_limit(self) -> bool; feedable(self) -> bool65 fn feedable(self) -> bool; 66 dep_kind(self) -> Qcx::DepKind67 fn dep_kind(self) -> Qcx::DepKind; handle_cycle_error(self) -> HandleCycleError68 fn handle_cycle_error(self) -> HandleCycleError; hash_result(self) -> HashResult<Self::Value>69 fn hash_result(self) -> HashResult<Self::Value>; 70 71 // Just here for convenience and checking that the key matches the kind, don't override this. construct_dep_node(self, tcx: Qcx::DepContext, key: &Self::Key) -> DepNode<Qcx::DepKind>72 fn construct_dep_node(self, tcx: Qcx::DepContext, key: &Self::Key) -> DepNode<Qcx::DepKind> { 73 DepNode::construct(tcx, self.dep_kind(), key) 74 } 75 } 76