]>
git.proxmox.com Git - rustc.git/blob - src/librustc/ty/query/config.rs
1 use crate::dep_graph
::SerializedDepNodeIndex
;
2 use crate::dep_graph
::{DepKind, DepNode}
;
3 use crate::ty
::query
::caches
::QueryCache
;
4 use crate::ty
::query
::plumbing
::CycleError
;
5 use crate::ty
::query
::{Query, QueryState}
;
7 use rustc_data_structures
::profiling
::ProfileCategory
;
8 use rustc_hir
::def_id
::DefId
;
10 use crate::ich
::StableHashingContext
;
11 use rustc_data_structures
::fingerprint
::Fingerprint
;
16 // Query configuration and description traits.
18 // FIXME(eddyb) false positive, the lifetime parameter is used for `Key`/`Value`.
19 #[allow(unused_lifetimes)]
20 pub trait QueryConfig
<'tcx
> {
21 const NAME
: &'
static str;
22 const CATEGORY
: ProfileCategory
;
24 type Key
: Eq
+ Hash
+ Clone
+ Debug
;
28 pub(crate) trait QueryAccessors
<'tcx
>: QueryConfig
<'tcx
> {
30 const EVAL_ALWAYS
: bool
;
32 type Cache
: QueryCache
<Self::Key
, Self::Value
>;
34 fn query(key
: Self::Key
) -> Query
<'tcx
>;
36 // Don't use this method to access query results, instead use the methods on TyCtxt
37 fn query_state
<'a
>(tcx
: TyCtxt
<'tcx
>) -> &'a QueryState
<'tcx
, Self>;
39 fn to_dep_node(tcx
: TyCtxt
<'tcx
>, key
: &Self::Key
) -> DepNode
;
41 fn dep_kind() -> DepKind
;
43 // Don't use this method to compute query results, instead use the methods on TyCtxt
44 fn compute(tcx
: TyCtxt
<'tcx
>, key
: Self::Key
) -> Self::Value
;
46 fn hash_result(hcx
: &mut StableHashingContext
<'_
>, result
: &Self::Value
)
47 -> Option
<Fingerprint
>;
49 fn handle_cycle_error(tcx
: TyCtxt
<'tcx
>, error
: CycleError
<'tcx
>) -> Self::Value
;
52 pub(crate) trait QueryDescription
<'tcx
>: QueryAccessors
<'tcx
> {
53 fn describe(tcx
: TyCtxt
<'_
>, key
: Self::Key
) -> Cow
<'
static, str>;
56 fn cache_on_disk(_
: TyCtxt
<'tcx
>, _
: Self::Key
, _
: Option
<&Self::Value
>) -> bool
{
60 fn try_load_from_disk(_
: TyCtxt
<'tcx
>, _
: SerializedDepNodeIndex
) -> Option
<Self::Value
> {
61 bug
!("QueryDescription::load_from_disk() called for an unsupported query.")
65 impl<'tcx
, M
: QueryAccessors
<'tcx
, Key
= DefId
>> QueryDescription
<'tcx
> for M
67 <M
as QueryAccessors
<'tcx
>>::Cache
: QueryCache
<DefId
, <M
as QueryConfig
<'tcx
>>::Value
>,
69 default fn describe(tcx
: TyCtxt
<'_
>, def_id
: DefId
) -> Cow
<'
static, str> {
70 if !tcx
.sess
.verbose() {
71 format
!("processing `{}`", tcx
.def_path_str(def_id
)).into()
73 let name
= ::std
::any
::type_name
::<M
>();
74 format
!("processing {:?} with query `{}`", def_id
, name
).into()
78 default fn cache_on_disk(_
: TyCtxt
<'tcx
>, _
: Self::Key
, _
: Option
<&Self::Value
>) -> bool
{
82 default fn try_load_from_disk(
84 _
: SerializedDepNodeIndex
,
85 ) -> Option
<Self::Value
> {
86 bug
!("QueryDescription::load_from_disk() called for an unsupported query.")