mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Make QueryAccessor argument a type.
This commit is contained in:
parent
8c1c90bb5c
commit
f74fd03999
@ -23,7 +23,7 @@ pub(crate) trait QueryCache: Default {
|
||||
/// to compute it.
|
||||
fn lookup<'tcx, R, GetCache, OnHit, OnMiss>(
|
||||
&self,
|
||||
state: &'tcx QueryState<'tcx, Self>,
|
||||
state: &'tcx QueryState<TyCtxt<'tcx>, Self>,
|
||||
get_cache: GetCache,
|
||||
key: Self::Key,
|
||||
// `on_hit` can be called while holding a lock to the query state shard.
|
||||
@ -32,10 +32,10 @@ pub(crate) trait QueryCache: Default {
|
||||
) -> R
|
||||
where
|
||||
GetCache: for<'a> Fn(
|
||||
&'a mut QueryStateShard<'tcx, Self::Key, Self::Sharded>,
|
||||
&'a mut QueryStateShard<TyCtxt<'tcx>, Self::Key, Self::Sharded>,
|
||||
) -> &'a mut Self::Sharded,
|
||||
OnHit: FnOnce(&Self::Value, DepNodeIndex) -> R,
|
||||
OnMiss: FnOnce(Self::Key, QueryLookup<'tcx, Self::Key, Self::Sharded>) -> R;
|
||||
OnMiss: FnOnce(Self::Key, QueryLookup<'tcx, TyCtxt<'tcx>, Self::Key, Self::Sharded>) -> R;
|
||||
|
||||
fn complete(
|
||||
&self,
|
||||
@ -78,17 +78,18 @@ impl<K: Eq + Hash, V: Clone> QueryCache for DefaultCache<K, V> {
|
||||
#[inline(always)]
|
||||
fn lookup<'tcx, R, GetCache, OnHit, OnMiss>(
|
||||
&self,
|
||||
state: &'tcx QueryState<'tcx, Self>,
|
||||
state: &'tcx QueryState<TyCtxt<'tcx>, Self>,
|
||||
get_cache: GetCache,
|
||||
key: K,
|
||||
on_hit: OnHit,
|
||||
on_miss: OnMiss,
|
||||
) -> R
|
||||
where
|
||||
GetCache:
|
||||
for<'a> Fn(&'a mut QueryStateShard<'tcx, K, Self::Sharded>) -> &'a mut Self::Sharded,
|
||||
GetCache: for<'a> Fn(
|
||||
&'a mut QueryStateShard<TyCtxt<'tcx>, K, Self::Sharded>,
|
||||
) -> &'a mut Self::Sharded,
|
||||
OnHit: FnOnce(&V, DepNodeIndex) -> R,
|
||||
OnMiss: FnOnce(K, QueryLookup<'tcx, K, Self::Sharded>) -> R,
|
||||
OnMiss: FnOnce(K, QueryLookup<'tcx, TyCtxt<'tcx>, K, Self::Sharded>) -> R,
|
||||
{
|
||||
let mut lookup = state.get_lookup(&key);
|
||||
let lock = &mut *lookup.lock;
|
||||
|
@ -23,7 +23,11 @@ pub trait QueryConfig<CTX> {
|
||||
type Value: Clone;
|
||||
}
|
||||
|
||||
pub(crate) trait QueryAccessors<'tcx>: QueryConfig<TyCtxt<'tcx>> {
|
||||
pub trait QueryContext: Copy {
|
||||
type Query;
|
||||
}
|
||||
|
||||
pub(crate) trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
|
||||
const ANON: bool;
|
||||
const EVAL_ALWAYS: bool;
|
||||
const DEP_KIND: DepKind;
|
||||
@ -31,20 +35,20 @@ pub(crate) trait QueryAccessors<'tcx>: QueryConfig<TyCtxt<'tcx>> {
|
||||
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
|
||||
|
||||
// Don't use this method to access query results, instead use the methods on TyCtxt
|
||||
fn query_state<'a>(tcx: TyCtxt<'tcx>) -> &'a QueryState<'tcx, Self::Cache>;
|
||||
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
|
||||
|
||||
fn to_dep_node(tcx: TyCtxt<'tcx>, key: &Self::Key) -> DepNode;
|
||||
fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode;
|
||||
|
||||
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
||||
fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value;
|
||||
fn compute(tcx: CTX, key: Self::Key) -> Self::Value;
|
||||
|
||||
fn hash_result(hcx: &mut StableHashingContext<'_>, result: &Self::Value)
|
||||
-> Option<Fingerprint>;
|
||||
|
||||
fn handle_cycle_error(tcx: TyCtxt<'tcx>, error: CycleError<'tcx>) -> Self::Value;
|
||||
fn handle_cycle_error(tcx: CTX, error: CycleError<CTX>) -> Self::Value;
|
||||
}
|
||||
|
||||
pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
|
||||
pub(crate) trait QueryDescription<'tcx>: QueryAccessors<TyCtxt<'tcx>> {
|
||||
fn describe(tcx: TyCtxt<'_>, key: Self::Key) -> Cow<'static, str>;
|
||||
|
||||
#[inline]
|
||||
@ -57,7 +61,11 @@ pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, M: QueryAccessors<'tcx, Key = DefId>> QueryDescription<'tcx> for M {
|
||||
impl<'tcx, M> QueryDescription<'tcx> for M
|
||||
where
|
||||
M: QueryAccessors<TyCtxt<'tcx>, Key = DefId>,
|
||||
//M::Cache: QueryCache<DefId, M::Value>,
|
||||
{
|
||||
default fn describe(tcx: TyCtxt<'_>, def_id: DefId) -> Cow<'static, str> {
|
||||
if !tcx.sess.verbose() {
|
||||
format!("processing `{}`", tcx.def_path_str(def_id)).into()
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::dep_graph::DepKind;
|
||||
use crate::ty::context::TyCtxt;
|
||||
use crate::ty::query::config::QueryContext;
|
||||
use crate::ty::query::plumbing::CycleError;
|
||||
use crate::ty::query::Query;
|
||||
use crate::ty::tls;
|
||||
@ -27,13 +28,13 @@ use {
|
||||
|
||||
/// Represents a span and a query key.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct QueryInfo<'tcx> {
|
||||
pub struct QueryInfo<CTX: QueryContext> {
|
||||
/// The span corresponding to the reason for which this query was required.
|
||||
pub span: Span,
|
||||
pub query: Query<'tcx>,
|
||||
pub query: CTX::Query,
|
||||
}
|
||||
|
||||
type QueryMap<'tcx> = FxHashMap<QueryJobId, QueryJobInfo<'tcx>>;
|
||||
type QueryMap<'tcx> = FxHashMap<QueryJobId, QueryJobInfo<TyCtxt<'tcx>>>;
|
||||
|
||||
/// A value uniquely identifiying an active query job within a shard in the query cache.
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||
@ -72,19 +73,19 @@ impl QueryJobId {
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
fn latch<'a, 'tcx>(self, map: &'a QueryMap<'tcx>) -> Option<&'a QueryLatch<'tcx>> {
|
||||
fn latch<'a, 'tcx>(self, map: &'a QueryMap<'tcx>) -> Option<&'a QueryLatch<TyCtxt<'tcx>>> {
|
||||
map.get(&self).unwrap().job.latch.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct QueryJobInfo<'tcx> {
|
||||
pub info: QueryInfo<'tcx>,
|
||||
pub job: QueryJob<'tcx>,
|
||||
pub struct QueryJobInfo<CTX: QueryContext> {
|
||||
pub info: QueryInfo<CTX>,
|
||||
pub job: QueryJob<CTX>,
|
||||
}
|
||||
|
||||
/// Represents an active query job.
|
||||
#[derive(Clone)]
|
||||
pub struct QueryJob<'tcx> {
|
||||
pub struct QueryJob<CTX: QueryContext> {
|
||||
pub id: QueryShardJobId,
|
||||
|
||||
/// The span corresponding to the reason for which this query was required.
|
||||
@ -95,12 +96,12 @@ pub struct QueryJob<'tcx> {
|
||||
|
||||
/// The latch that is used to wait on this job.
|
||||
#[cfg(parallel_compiler)]
|
||||
latch: Option<QueryLatch<'tcx>>,
|
||||
latch: Option<QueryLatch<CTX>>,
|
||||
|
||||
dummy: PhantomData<QueryLatch<'tcx>>,
|
||||
dummy: PhantomData<QueryLatch<CTX>>,
|
||||
}
|
||||
|
||||
impl<'tcx> QueryJob<'tcx> {
|
||||
impl<CTX: QueryContext> QueryJob<CTX> {
|
||||
/// Creates a new query job.
|
||||
pub fn new(id: QueryShardJobId, span: Span, parent: Option<QueryJobId>) -> Self {
|
||||
QueryJob {
|
||||
@ -114,7 +115,7 @@ impl<'tcx> QueryJob<'tcx> {
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
pub(super) fn latch(&mut self, _id: QueryJobId) -> QueryLatch<'tcx> {
|
||||
pub(super) fn latch(&mut self, _id: QueryJobId) -> QueryLatch<CTX> {
|
||||
if self.latch.is_none() {
|
||||
self.latch = Some(QueryLatch::new());
|
||||
}
|
||||
@ -122,7 +123,7 @@ impl<'tcx> QueryJob<'tcx> {
|
||||
}
|
||||
|
||||
#[cfg(not(parallel_compiler))]
|
||||
pub(super) fn latch(&mut self, id: QueryJobId) -> QueryLatch<'tcx> {
|
||||
pub(super) fn latch(&mut self, id: QueryJobId) -> QueryLatch<CTX> {
|
||||
QueryLatch { id, dummy: PhantomData }
|
||||
}
|
||||
|
||||
@ -138,14 +139,18 @@ impl<'tcx> QueryJob<'tcx> {
|
||||
|
||||
#[cfg(not(parallel_compiler))]
|
||||
#[derive(Clone)]
|
||||
pub(super) struct QueryLatch<'tcx> {
|
||||
pub(super) struct QueryLatch<CTX> {
|
||||
id: QueryJobId,
|
||||
dummy: PhantomData<&'tcx ()>,
|
||||
dummy: PhantomData<CTX>,
|
||||
}
|
||||
|
||||
#[cfg(not(parallel_compiler))]
|
||||
impl<'tcx> QueryLatch<'tcx> {
|
||||
pub(super) fn find_cycle_in_stack(&self, tcx: TyCtxt<'tcx>, span: Span) -> CycleError<'tcx> {
|
||||
impl<'tcx> QueryLatch<TyCtxt<'tcx>> {
|
||||
pub(super) fn find_cycle_in_stack(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
span: Span,
|
||||
) -> CycleError<TyCtxt<'tcx>> {
|
||||
let query_map = tcx.queries.try_collect_active_jobs().unwrap();
|
||||
|
||||
// Get the current executing query (waiter) and find the waitee amongst its parents
|
||||
@ -181,15 +186,15 @@ impl<'tcx> QueryLatch<'tcx> {
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
struct QueryWaiter<'tcx> {
|
||||
struct QueryWaiter<CTX: QueryContext> {
|
||||
query: Option<QueryJobId>,
|
||||
condvar: Condvar,
|
||||
span: Span,
|
||||
cycle: Lock<Option<CycleError<'tcx>>>,
|
||||
cycle: Lock<Option<CycleError<CTX>>>,
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
impl<'tcx> QueryWaiter<'tcx> {
|
||||
impl<CTX: QueryContext> QueryWaiter<CTX> {
|
||||
fn notify(&self, registry: &rayon_core::Registry) {
|
||||
rayon_core::mark_unblocked(registry);
|
||||
self.condvar.notify_one();
|
||||
@ -197,28 +202,34 @@ impl<'tcx> QueryWaiter<'tcx> {
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
struct QueryLatchInfo<'tcx> {
|
||||
struct QueryLatchInfo<CTX: QueryContext> {
|
||||
complete: bool,
|
||||
waiters: Vec<Lrc<QueryWaiter<'tcx>>>,
|
||||
waiters: Vec<Lrc<QueryWaiter<CTX>>>,
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
#[derive(Clone)]
|
||||
pub(super) struct QueryLatch<'tcx> {
|
||||
info: Lrc<Mutex<QueryLatchInfo<'tcx>>>,
|
||||
pub(super) struct QueryLatch<CTX: QueryContext> {
|
||||
info: Lrc<Mutex<QueryLatchInfo<CTX>>>,
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
impl<'tcx> QueryLatch<'tcx> {
|
||||
impl<CTX: QueryContext> QueryLatch<CTX> {
|
||||
fn new() -> Self {
|
||||
QueryLatch {
|
||||
info: Lrc::new(Mutex::new(QueryLatchInfo { complete: false, waiters: Vec::new() })),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
impl<'tcx> QueryLatch<TyCtxt<'tcx>> {
|
||||
/// Awaits for the query job to complete.
|
||||
#[cfg(parallel_compiler)]
|
||||
pub(super) fn wait_on(&self, tcx: TyCtxt<'tcx>, span: Span) -> Result<(), CycleError<'tcx>> {
|
||||
pub(super) fn wait_on(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
span: Span,
|
||||
) -> Result<(), CycleError<TyCtxt<'tcx>>> {
|
||||
tls::with_related_context(tcx, move |icx| {
|
||||
let waiter = Lrc::new(QueryWaiter {
|
||||
query: icx.query,
|
||||
@ -237,9 +248,12 @@ impl<'tcx> QueryLatch<'tcx> {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
impl<CTX: QueryContext> QueryLatch<CTX> {
|
||||
/// Awaits the caller on this latch by blocking the current thread.
|
||||
fn wait_on_inner(&self, waiter: &Lrc<QueryWaiter<'tcx>>) {
|
||||
fn wait_on_inner(&self, waiter: &Lrc<QueryWaiter<CTX>>) {
|
||||
let mut info = self.info.lock();
|
||||
if !info.complete {
|
||||
// We push the waiter on to the `waiters` list. It can be accessed inside
|
||||
@ -273,7 +287,7 @@ impl<'tcx> QueryLatch<'tcx> {
|
||||
|
||||
/// Removes a single waiter from the list of waiters.
|
||||
/// This is used to break query cycles.
|
||||
fn extract_waiter(&self, waiter: usize) -> Lrc<QueryWaiter<'tcx>> {
|
||||
fn extract_waiter(&self, waiter: usize) -> Lrc<QueryWaiter<CTX>> {
|
||||
let mut info = self.info.lock();
|
||||
debug_assert!(!info.complete);
|
||||
// Remove the waiter from the list of waiters
|
||||
@ -427,7 +441,7 @@ fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, QueryJobId)>(
|
||||
fn remove_cycle<'tcx>(
|
||||
query_map: &QueryMap<'tcx>,
|
||||
jobs: &mut Vec<QueryJobId>,
|
||||
wakelist: &mut Vec<Lrc<QueryWaiter<'tcx>>>,
|
||||
wakelist: &mut Vec<Lrc<QueryWaiter<TyCtxt<'tcx>>>>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> bool {
|
||||
let mut visited = FxHashSet::default();
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
|
||||
use crate::ty::query::caches::QueryCache;
|
||||
use crate::ty::query::config::QueryDescription;
|
||||
use crate::ty::query::config::{QueryContext, QueryDescription};
|
||||
use crate::ty::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
|
||||
use crate::ty::query::Query;
|
||||
use crate::ty::tls;
|
||||
@ -29,38 +29,38 @@ use std::ptr;
|
||||
#[cfg(debug_assertions)]
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
pub(crate) struct QueryStateShard<'tcx, K, C> {
|
||||
pub(crate) struct QueryStateShard<CTX: QueryContext, K, C> {
|
||||
cache: C,
|
||||
active: FxHashMap<K, QueryResult<'tcx>>,
|
||||
active: FxHashMap<K, QueryResult<CTX>>,
|
||||
|
||||
/// Used to generate unique ids for active jobs.
|
||||
jobs: u32,
|
||||
}
|
||||
|
||||
impl<'tcx, K, C> QueryStateShard<'tcx, K, C> {
|
||||
impl<CTX: QueryContext, K, C> QueryStateShard<CTX, K, C> {
|
||||
fn get_cache(&mut self) -> &mut C {
|
||||
&mut self.cache
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, K, C: Default> Default for QueryStateShard<'tcx, K, C> {
|
||||
fn default() -> QueryStateShard<'tcx, K, C> {
|
||||
impl<CTX: QueryContext, K, C: Default> Default for QueryStateShard<CTX, K, C> {
|
||||
fn default() -> QueryStateShard<CTX, K, C> {
|
||||
QueryStateShard { cache: Default::default(), active: Default::default(), jobs: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct QueryState<'tcx, C: QueryCache> {
|
||||
pub(crate) struct QueryState<CTX: QueryContext, C: QueryCache> {
|
||||
cache: C,
|
||||
shards: Sharded<QueryStateShard<'tcx, C::Key, C::Sharded>>,
|
||||
shards: Sharded<QueryStateShard<CTX, C::Key, C::Sharded>>,
|
||||
#[cfg(debug_assertions)]
|
||||
pub(super) cache_hits: AtomicUsize,
|
||||
}
|
||||
|
||||
impl<'tcx, C: QueryCache> QueryState<'tcx, C> {
|
||||
impl<CTX: QueryContext, C: QueryCache> QueryState<CTX, C> {
|
||||
pub(super) fn get_lookup<K2: Hash>(
|
||||
&'tcx self,
|
||||
key: &K2,
|
||||
) -> QueryLookup<'tcx, C::Key, C::Sharded> {
|
||||
) -> QueryLookup<'tcx, CTX, C::Key, C::Sharded> {
|
||||
// We compute the key's hash once and then use it for both the
|
||||
// shard lookup and the hashmap lookup. This relies on the fact
|
||||
// that both of them use `FxHasher`.
|
||||
@ -75,16 +75,16 @@ impl<'tcx, C: QueryCache> QueryState<'tcx, C> {
|
||||
}
|
||||
|
||||
/// Indicates the state of a query for a given key in a query map.
|
||||
enum QueryResult<'tcx> {
|
||||
enum QueryResult<CTX: QueryContext> {
|
||||
/// An already executing query. The query job can be used to await for its completion.
|
||||
Started(QueryJob<'tcx>),
|
||||
Started(QueryJob<CTX>),
|
||||
|
||||
/// The query panicked. Queries trying to wait on this will raise a fatal error which will
|
||||
/// silently panic.
|
||||
Poisoned,
|
||||
}
|
||||
|
||||
impl<'tcx, C: QueryCache> QueryState<'tcx, C> {
|
||||
impl<CTX: QueryContext, C: QueryCache> QueryState<CTX, C> {
|
||||
pub(super) fn iter_results<R>(
|
||||
&self,
|
||||
f: impl for<'a> FnOnce(
|
||||
@ -101,8 +101,8 @@ impl<'tcx, C: QueryCache> QueryState<'tcx, C> {
|
||||
pub(super) fn try_collect_active_jobs(
|
||||
&self,
|
||||
kind: DepKind,
|
||||
make_query: fn(C::Key) -> Query<'tcx>,
|
||||
jobs: &mut FxHashMap<QueryJobId, QueryJobInfo<'tcx>>,
|
||||
make_query: fn(C::Key) -> CTX::Query,
|
||||
jobs: &mut FxHashMap<QueryJobId, QueryJobInfo<CTX>>,
|
||||
) -> Option<()>
|
||||
where
|
||||
C::Key: Clone,
|
||||
@ -128,8 +128,8 @@ impl<'tcx, C: QueryCache> QueryState<'tcx, C> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, C: QueryCache> Default for QueryState<'tcx, C> {
|
||||
fn default() -> QueryState<'tcx, C> {
|
||||
impl<CTX: QueryContext, C: QueryCache> Default for QueryState<CTX, C> {
|
||||
fn default() -> QueryState<CTX, C> {
|
||||
QueryState {
|
||||
cache: C::default(),
|
||||
shards: Default::default(),
|
||||
@ -140,26 +140,26 @@ impl<'tcx, C: QueryCache> Default for QueryState<'tcx, C> {
|
||||
}
|
||||
|
||||
/// Values used when checking a query cache which can be reused on a cache-miss to execute the query.
|
||||
pub(crate) struct QueryLookup<'tcx, K, C> {
|
||||
pub(crate) struct QueryLookup<'tcx, CTX: QueryContext, K, C> {
|
||||
pub(super) key_hash: u64,
|
||||
shard: usize,
|
||||
pub(super) lock: LockGuard<'tcx, QueryStateShard<'tcx, K, C>>,
|
||||
pub(super) lock: LockGuard<'tcx, QueryStateShard<CTX, K, C>>,
|
||||
}
|
||||
|
||||
/// A type representing the responsibility to execute the job in the `job` field.
|
||||
/// This will poison the relevant query if dropped.
|
||||
struct JobOwner<'tcx, C>
|
||||
struct JobOwner<'tcx, CTX: QueryContext, C>
|
||||
where
|
||||
C: QueryCache,
|
||||
C::Key: Eq + Hash + Clone + Debug,
|
||||
C::Value: Clone,
|
||||
{
|
||||
state: &'tcx QueryState<'tcx, C>,
|
||||
state: &'tcx QueryState<CTX, C>,
|
||||
key: C::Key,
|
||||
id: QueryJobId,
|
||||
}
|
||||
|
||||
impl<'tcx, C: QueryCache> JobOwner<'tcx, C>
|
||||
impl<'tcx, C: QueryCache> JobOwner<'tcx, TyCtxt<'tcx>, C>
|
||||
where
|
||||
C: QueryCache,
|
||||
C::Key: Eq + Hash + Clone + Debug,
|
||||
@ -178,7 +178,7 @@ where
|
||||
tcx: TyCtxt<'tcx>,
|
||||
span: Span,
|
||||
key: &C::Key,
|
||||
mut lookup: QueryLookup<'tcx, C::Key, C::Sharded>,
|
||||
mut lookup: QueryLookup<'tcx, TyCtxt<'tcx>, C::Key, C::Sharded>,
|
||||
) -> TryGetJob<'tcx, C>
|
||||
where
|
||||
Q: QueryDescription<'tcx, Key = C::Key, Value = C::Value, Cache = C>,
|
||||
@ -258,7 +258,14 @@ where
|
||||
return TryGetJob::JobCompleted(cached);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, CTX: QueryContext, C: QueryCache> JobOwner<'tcx, CTX, C>
|
||||
where
|
||||
C: QueryCache,
|
||||
C::Key: Eq + Hash + Clone + Debug,
|
||||
C::Value: Clone,
|
||||
{
|
||||
/// Completes the query by updating the query cache with the `result`,
|
||||
/// signals the waiter and forgets the JobOwner, so it won't poison the query
|
||||
#[inline(always)]
|
||||
@ -295,7 +302,7 @@ where
|
||||
(result, diagnostics.into_inner())
|
||||
}
|
||||
|
||||
impl<'tcx, C: QueryCache> Drop for JobOwner<'tcx, C>
|
||||
impl<'tcx, CTX: QueryContext, C: QueryCache> Drop for JobOwner<'tcx, CTX, C>
|
||||
where
|
||||
C::Key: Eq + Hash + Clone + Debug,
|
||||
C::Value: Clone,
|
||||
@ -322,10 +329,10 @@ where
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct CycleError<'tcx> {
|
||||
pub(crate) struct CycleError<CTX: QueryContext> {
|
||||
/// The query and related span that uses the cycle.
|
||||
pub(super) usage: Option<(Span, Query<'tcx>)>,
|
||||
pub(super) cycle: Vec<QueryInfo<'tcx>>,
|
||||
pub(super) usage: Option<(Span, CTX::Query)>,
|
||||
pub(super) cycle: Vec<QueryInfo<CTX>>,
|
||||
}
|
||||
|
||||
/// The result of `try_start`.
|
||||
@ -335,7 +342,7 @@ where
|
||||
C::Value: Clone,
|
||||
{
|
||||
/// The query is not yet started. Contains a guard to the cache eventually used to start it.
|
||||
NotYetStarted(JobOwner<'tcx, C>),
|
||||
NotYetStarted(JobOwner<'tcx, TyCtxt<'tcx>, C>),
|
||||
|
||||
/// The query was already completed.
|
||||
/// Returns the result of the query and its dep-node index
|
||||
@ -347,6 +354,10 @@ where
|
||||
Cycle(C::Value),
|
||||
}
|
||||
|
||||
impl QueryContext for TyCtxt<'tcx> {
|
||||
type Query = Query<'tcx>;
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Executes a job by changing the `ImplicitCtxt` to point to the
|
||||
/// new query job while it executes. It returns the diagnostics
|
||||
@ -383,7 +394,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
#[cold]
|
||||
pub(super) fn report_cycle(
|
||||
self,
|
||||
CycleError { usage, cycle: stack }: CycleError<'tcx>,
|
||||
CycleError { usage, cycle: stack }: CycleError<TyCtxt<'tcx>>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
assert!(!stack.is_empty());
|
||||
|
||||
@ -476,7 +487,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
#[inline(always)]
|
||||
fn try_get_cached<C, R, OnHit, OnMiss>(
|
||||
self,
|
||||
state: &'tcx QueryState<'tcx, C>,
|
||||
state: &'tcx QueryState<TyCtxt<'tcx>, C>,
|
||||
key: C::Key,
|
||||
// `on_hit` can be called while holding a lock to the query cache
|
||||
on_hit: OnHit,
|
||||
@ -485,11 +496,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
where
|
||||
C: QueryCache,
|
||||
OnHit: FnOnce(&C::Value, DepNodeIndex) -> R,
|
||||
OnMiss: FnOnce(C::Key, QueryLookup<'tcx, C::Key, C::Sharded>) -> R,
|
||||
OnMiss: FnOnce(C::Key, QueryLookup<'tcx, TyCtxt<'tcx>, C::Key, C::Sharded>) -> R,
|
||||
{
|
||||
state.cache.lookup(
|
||||
state,
|
||||
QueryStateShard::<C::Key, C::Sharded>::get_cache,
|
||||
QueryStateShard::<TyCtxt<'tcx>, C::Key, C::Sharded>::get_cache,
|
||||
key,
|
||||
|value, index| {
|
||||
if unlikely!(self.prof.enabled()) {
|
||||
@ -529,7 +540,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
self,
|
||||
span: Span,
|
||||
key: Q::Key,
|
||||
lookup: QueryLookup<'tcx, Q::Key, <Q::Cache as QueryCache>::Sharded>,
|
||||
lookup: QueryLookup<'tcx, TyCtxt<'tcx>, Q::Key, <Q::Cache as QueryCache>::Sharded>,
|
||||
) -> Q::Value {
|
||||
let job = match JobOwner::try_start::<Q>(self, span, &key, lookup) {
|
||||
TryGetJob::NotYetStarted(job) => job,
|
||||
@ -690,7 +701,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
fn force_query_with_job<Q: QueryDescription<'tcx> + 'tcx>(
|
||||
self,
|
||||
key: Q::Key,
|
||||
job: JobOwner<'tcx, Q::Cache>,
|
||||
job: JobOwner<'tcx, TyCtxt<'tcx>, Q::Cache>,
|
||||
dep_node: DepNode,
|
||||
) -> (Q::Value, DepNodeIndex) {
|
||||
// If the following assertion triggers, it can have two reasons:
|
||||
@ -963,7 +974,7 @@ macro_rules! define_queries_inner {
|
||||
const CATEGORY: ProfileCategory = $category;
|
||||
}
|
||||
|
||||
impl<$tcx> QueryAccessors<$tcx> for queries::$name<$tcx> {
|
||||
impl<$tcx> QueryAccessors<TyCtxt<$tcx>> for queries::$name<$tcx> {
|
||||
const ANON: bool = is_anon!([$($modifiers)*]);
|
||||
const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]);
|
||||
const DEP_KIND: dep_graph::DepKind = dep_graph::DepKind::$node;
|
||||
@ -971,7 +982,7 @@ macro_rules! define_queries_inner {
|
||||
type Cache = query_storage!([$($modifiers)*][$K, $V]);
|
||||
|
||||
#[inline(always)]
|
||||
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<$tcx, Self::Cache> {
|
||||
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<TyCtxt<$tcx>, Self::Cache> {
|
||||
&tcx.queries.$name
|
||||
}
|
||||
|
||||
@ -1002,7 +1013,7 @@ macro_rules! define_queries_inner {
|
||||
|
||||
fn handle_cycle_error(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
error: CycleError<'tcx>
|
||||
error: CycleError<TyCtxt<'tcx>>
|
||||
) -> Self::Value {
|
||||
handle_cycle_error!([$($modifiers)*][tcx, error])
|
||||
}
|
||||
@ -1124,8 +1135,8 @@ macro_rules! define_queries_struct {
|
||||
fallback_extern_providers: Box<Providers<$tcx>>,
|
||||
|
||||
$($(#[$attr])* $name: QueryState<
|
||||
$tcx,
|
||||
<queries::$name<$tcx> as QueryAccessors<'tcx>>::Cache,
|
||||
TyCtxt<$tcx>,
|
||||
<queries::$name<$tcx> as QueryAccessors<TyCtxt<'tcx>>>::Cache,
|
||||
>,)*
|
||||
}
|
||||
|
||||
@ -1145,12 +1156,12 @@ macro_rules! define_queries_struct {
|
||||
|
||||
pub(crate) fn try_collect_active_jobs(
|
||||
&self
|
||||
) -> Option<FxHashMap<QueryJobId, QueryJobInfo<'tcx>>> {
|
||||
) -> Option<FxHashMap<QueryJobId, QueryJobInfo<TyCtxt<'tcx>>>> {
|
||||
let mut jobs = FxHashMap::default();
|
||||
|
||||
$(
|
||||
self.$name.try_collect_active_jobs(
|
||||
<queries::$name<'tcx> as QueryAccessors<'tcx>>::DEP_KIND,
|
||||
<queries::$name<'tcx> as QueryAccessors<TyCtxt<'tcx>>>::DEP_KIND,
|
||||
Query::$name,
|
||||
&mut jobs,
|
||||
)?;
|
||||
|
@ -160,7 +160,7 @@ where
|
||||
pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
query_name: &'static str,
|
||||
query_state: &QueryState<'tcx, C>,
|
||||
query_state: &QueryState<TyCtxt<'tcx>, C>,
|
||||
string_cache: &mut QueryKeyStringCache,
|
||||
) where
|
||||
C: QueryCache,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::ty::query::caches::QueryCache;
|
||||
use crate::ty::query::config::QueryAccessors;
|
||||
use crate::ty::query::config::{QueryAccessors, QueryContext};
|
||||
use crate::ty::query::plumbing::QueryState;
|
||||
use crate::ty::query::queries;
|
||||
use crate::ty::TyCtxt;
|
||||
@ -38,7 +38,10 @@ struct QueryStats {
|
||||
local_def_id_keys: Option<usize>,
|
||||
}
|
||||
|
||||
fn stats<'tcx, C: QueryCache>(name: &'static str, map: &QueryState<'tcx, C>) -> QueryStats {
|
||||
fn stats<CTX: QueryContext, C: QueryCache>(
|
||||
name: &'static str,
|
||||
map: &QueryState<CTX, C>,
|
||||
) -> QueryStats {
|
||||
let mut stats = QueryStats {
|
||||
name,
|
||||
#[cfg(debug_assertions)]
|
||||
@ -124,7 +127,8 @@ macro_rules! print_stats {
|
||||
|
||||
$($(
|
||||
queries.push(stats::<
|
||||
<queries::$name<'_> as QueryAccessors<'_>>::Cache,
|
||||
TyCtxt<'_>,
|
||||
<queries::$name<'_> as QueryAccessors<TyCtxt<'_>>>::Cache,
|
||||
>(
|
||||
stringify!($name),
|
||||
&tcx.queries.$name,
|
||||
|
Loading…
Reference in New Issue
Block a user