]>
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::hir
::def_id
::{CrateNum, DefId}
;
5 use crate::ty
::query
::queries
;
6 use crate::ty
::query
::{Query, QueryName}
;
7 use crate::ty
::query
::QueryCache
;
8 use crate::ty
::query
::plumbing
::CycleError
;
9 use crate::util
::profiling
::ProfileCategory
;
14 use rustc_data_structures
::sharded
::Sharded
;
15 use rustc_data_structures
::fingerprint
::Fingerprint
;
16 use crate::ich
::StableHashingContext
;
18 // Query configuration and description traits.
20 // FIXME(eddyb) false positive, the lifetime parameter is used for `Key`/`Value`.
21 #[allow(unused_lifetimes)]
22 pub trait QueryConfig
<'tcx
> {
23 const NAME
: QueryName
;
24 const CATEGORY
: ProfileCategory
;
26 type Key
: Eq
+ Hash
+ Clone
+ Debug
;
30 pub(crate) trait QueryAccessors
<'tcx
>: QueryConfig
<'tcx
> {
32 const EVAL_ALWAYS
: bool
;
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_cache
<'a
>(tcx
: TyCtxt
<'tcx
>) -> &'a Sharded
<QueryCache
<'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
;
47 hcx
: &mut StableHashingContext
<'_
>,
49 ) -> Option
<Fingerprint
>;
51 fn handle_cycle_error(tcx
: TyCtxt
<'tcx
>, error
: CycleError
<'tcx
>) -> Self::Value
;
54 pub(crate) trait QueryDescription
<'tcx
>: QueryAccessors
<'tcx
> {
55 fn describe(tcx
: TyCtxt
<'_
>, key
: Self::Key
) -> Cow
<'
static, str>;
58 fn cache_on_disk(_
: TyCtxt
<'tcx
>, _
: Self::Key
, _
: Option
<&Self::Value
>) -> bool
{
62 fn try_load_from_disk(_
: TyCtxt
<'tcx
>, _
: SerializedDepNodeIndex
) -> Option
<Self::Value
> {
63 bug
!("QueryDescription::load_from_disk() called for an unsupported query.")
67 impl<'tcx
, M
: QueryAccessors
<'tcx
, Key
= DefId
>> QueryDescription
<'tcx
> for M
{
68 default fn describe(tcx
: TyCtxt
<'_
>, def_id
: DefId
) -> Cow
<'
static, str> {
69 if !tcx
.sess
.verbose() {
70 format
!("processing `{}`", tcx
.def_path_str(def_id
)).into()
72 let name
= ::std
::any
::type_name
::<M
>();
73 format
!("processing {:?} with query `{}`", def_id
, name
).into()
77 default fn cache_on_disk(_
: TyCtxt
<'tcx
>, _
: Self::Key
, _
: Option
<&Self::Value
>) -> bool
{
81 default fn try_load_from_disk(
83 _
: SerializedDepNodeIndex
,
84 ) -> Option
<Self::Value
> {
85 bug
!("QueryDescription::load_from_disk() called for an unsupported query.")
89 impl<'tcx
> QueryDescription
<'tcx
> for queries
::analysis
<'tcx
> {
90 fn describe(_tcx
: TyCtxt
<'_
>, _
: CrateNum
) -> Cow
<'
static, str> {
91 "running analysis passes on this crate".into()