1
Fork 0

Merge QueryDescription into QueryConfig

`QueryDescription` has gone through a lot of refactoring and doesn't
make sense anymore.
This commit is contained in:
Nilstrieb 2022-11-05 16:04:43 +01:00
parent 452cf4f710
commit 36be251a35
No known key found for this signature in database
6 changed files with 42 additions and 45 deletions

View file

@ -11,12 +11,32 @@ use rustc_data_structures::fingerprint::Fingerprint;
use std::fmt::Debug;
use std::hash::Hash;
pub trait QueryConfig {
pub trait QueryConfig<CTX: QueryContext> {
const NAME: &'static str;
type Key: Eq + Hash + Clone + Debug;
type Value;
type Stored: Clone;
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(tcx: CTX) -> &'a QueryState<Self::Key>
where
CTX: 'a;
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_cache<'a>(tcx: CTX) -> &'a Self::Cache
where
CTX: 'a;
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn make_vtable(tcx: CTX, key: &Self::Key) -> QueryVTable<CTX, Self::Key, Self::Value>;
fn cache_on_disk(tcx: CTX::DepContext, key: &Self::Key) -> bool;
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn execute_query(tcx: CTX::DepContext, k: Self::Key) -> Self::Stored;
}
#[derive(Copy, Clone)]
@ -45,25 +65,3 @@ impl<CTX: QueryContext, K, V> QueryVTable<CTX, K, V> {
(self.compute)(tcx, key)
}
}
pub trait QueryDescription<CTX: QueryContext>: QueryConfig {
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(tcx: CTX) -> &'a QueryState<Self::Key>
where
CTX: 'a;
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_cache<'a>(tcx: CTX) -> &'a Self::Cache
where
CTX: 'a;
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn make_vtable(tcx: CTX, key: &Self::Key) -> QueryVTable<CTX, Self::Key, Self::Value>;
fn cache_on_disk(tcx: CTX::DepContext, key: &Self::Key) -> bool;
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn execute_query(tcx: CTX::DepContext, k: Self::Key) -> Self::Stored;
}

View file

@ -12,7 +12,7 @@ pub use self::caches::{
};
mod config;
pub use self::config::{QueryConfig, QueryDescription, QueryVTable};
pub use self::config::{QueryConfig, QueryVTable};
use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
use rustc_data_structures::sync::Lock;

View file

@ -4,7 +4,7 @@
use crate::dep_graph::{DepContext, DepNode, DepNodeIndex, DepNodeParams};
use crate::query::caches::QueryCache;
use crate::query::config::{QueryDescription, QueryVTable};
use crate::query::config::QueryVTable;
use crate::query::job::{report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo};
use crate::query::{QueryContext, QueryMap, QuerySideEffects, QueryStackFrame};
use crate::values::Value;
@ -27,6 +27,8 @@ use std::mem;
use std::ptr;
use thin_vec::ThinVec;
use super::QueryConfig;
pub struct QueryState<K> {
#[cfg(parallel_compiler)]
active: Sharded<FxHashMap<K, QueryResult>>,
@ -715,7 +717,7 @@ pub enum QueryMode {
pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key, mode: QueryMode) -> Option<Q::Stored>
where
Q: QueryDescription<CTX>,
Q: QueryConfig<CTX>,
Q::Key: DepNodeParams<CTX::DepContext>,
Q::Value: Value<CTX::DepContext>,
CTX: QueryContext,
@ -748,7 +750,7 @@ where
pub fn force_query<Q, CTX>(tcx: CTX, key: Q::Key, dep_node: DepNode<CTX::DepKind>)
where
Q: QueryDescription<CTX>,
Q: QueryConfig<CTX>,
Q::Key: DepNodeParams<CTX::DepContext>,
Q::Value: Value<CTX::DepContext>,
CTX: QueryContext,