mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Delete QueryLookup
This was largely just caching the shard value at this point, which is not particularly useful -- in the use sites the key was being hashed nearby anyway.
This commit is contained in:
parent
9deed6f74e
commit
75ef068920
@ -222,12 +222,12 @@ macro_rules! define_callbacks {
|
|||||||
|
|
||||||
let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, noop);
|
let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, noop);
|
||||||
|
|
||||||
let lookup = match cached {
|
match cached {
|
||||||
Ok(()) => return,
|
Ok(()) => return,
|
||||||
Err(lookup) => lookup,
|
Err(()) => (),
|
||||||
};
|
}
|
||||||
|
|
||||||
self.tcx.queries.$name(self.tcx, DUMMY_SP, key, lookup, QueryMode::Ensure);
|
self.tcx.queries.$name(self.tcx, DUMMY_SP, key, QueryMode::Ensure);
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,12 +251,12 @@ macro_rules! define_callbacks {
|
|||||||
|
|
||||||
let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, copy);
|
let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, copy);
|
||||||
|
|
||||||
let lookup = match cached {
|
match cached {
|
||||||
Ok(value) => return value,
|
Ok(value) => return value,
|
||||||
Err(lookup) => lookup,
|
Err(()) => (),
|
||||||
};
|
}
|
||||||
|
|
||||||
self.tcx.queries.$name(self.tcx, self.span, key, lookup, QueryMode::Get).unwrap()
|
self.tcx.queries.$name(self.tcx, self.span, key, QueryMode::Get).unwrap()
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +314,6 @@ macro_rules! define_callbacks {
|
|||||||
tcx: TyCtxt<$tcx>,
|
tcx: TyCtxt<$tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
key: query_keys::$name<$tcx>,
|
key: query_keys::$name<$tcx>,
|
||||||
lookup: QueryLookup,
|
|
||||||
mode: QueryMode,
|
mode: QueryMode,
|
||||||
) -> Option<query_stored::$name<$tcx>>;)*
|
) -> Option<query_stored::$name<$tcx>>;)*
|
||||||
}
|
}
|
||||||
|
@ -538,12 +538,11 @@ macro_rules! define_queries_struct {
|
|||||||
tcx: TyCtxt<$tcx>,
|
tcx: TyCtxt<$tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
key: query_keys::$name<$tcx>,
|
key: query_keys::$name<$tcx>,
|
||||||
lookup: QueryLookup,
|
|
||||||
mode: QueryMode,
|
mode: QueryMode,
|
||||||
) -> Option<query_stored::$name<$tcx>> {
|
) -> Option<query_stored::$name<$tcx>> {
|
||||||
opt_remap_env_constness!([$($modifiers)*][key]);
|
opt_remap_env_constness!([$($modifiers)*][key]);
|
||||||
let qcx = QueryCtxt { tcx, queries: self };
|
let qcx = QueryCtxt { tcx, queries: self };
|
||||||
get_query::<queries::$name<$tcx>, _>(qcx, span, key, lookup, mode)
|
get_query::<queries::$name<$tcx>, _>(qcx, span, key, mode)
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use crate::dep_graph::DepNodeIndex;
|
use crate::dep_graph::DepNodeIndex;
|
||||||
use crate::query::plumbing::QueryLookup;
|
|
||||||
|
|
||||||
use rustc_arena::TypedArena;
|
use rustc_arena::TypedArena;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
@ -35,7 +34,7 @@ pub trait QueryCache: QueryStorage + Sized {
|
|||||||
key: &Self::Key,
|
key: &Self::Key,
|
||||||
// `on_hit` can be called while holding a lock to the query state shard.
|
// `on_hit` can be called while holding a lock to the query state shard.
|
||||||
on_hit: OnHit,
|
on_hit: OnHit,
|
||||||
) -> Result<R, QueryLookup>
|
) -> Result<R, ()>
|
||||||
where
|
where
|
||||||
OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R;
|
OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R;
|
||||||
|
|
||||||
@ -79,21 +78,20 @@ where
|
|||||||
type Key = K;
|
type Key = K;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, QueryLookup>
|
fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, ()>
|
||||||
where
|
where
|
||||||
OnHit: FnOnce(&V, DepNodeIndex) -> R,
|
OnHit: FnOnce(&V, DepNodeIndex) -> R,
|
||||||
{
|
{
|
||||||
let key_hash = sharded::make_hash(key);
|
let key_hash = sharded::make_hash(key);
|
||||||
let shard = sharded::get_shard_index_by_hash(key_hash);
|
let shard = sharded::get_shard_index_by_hash(key_hash);
|
||||||
let lock = self.shards.get_shard_by_index(shard).lock();
|
let lock = self.shards.get_shard_by_index(shard).lock();
|
||||||
let lookup = QueryLookup { key_hash, shard };
|
let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
|
||||||
let result = lock.raw_entry().from_key_hashed_nocheck(lookup.key_hash, key);
|
|
||||||
|
|
||||||
if let Some((_, value)) = result {
|
if let Some((_, value)) = result {
|
||||||
let hit_result = on_hit(&value.0, value.1);
|
let hit_result = on_hit(&value.0, value.1);
|
||||||
Ok(hit_result)
|
Ok(hit_result)
|
||||||
} else {
|
} else {
|
||||||
Err(lookup)
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,21 +151,20 @@ where
|
|||||||
type Key = K;
|
type Key = K;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, QueryLookup>
|
fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, ()>
|
||||||
where
|
where
|
||||||
OnHit: FnOnce(&&'tcx V, DepNodeIndex) -> R,
|
OnHit: FnOnce(&&'tcx V, DepNodeIndex) -> R,
|
||||||
{
|
{
|
||||||
let key_hash = sharded::make_hash(key);
|
let key_hash = sharded::make_hash(key);
|
||||||
let shard = sharded::get_shard_index_by_hash(key_hash);
|
let shard = sharded::get_shard_index_by_hash(key_hash);
|
||||||
let lock = self.shards.get_shard_by_index(shard).lock();
|
let lock = self.shards.get_shard_by_index(shard).lock();
|
||||||
let lookup = QueryLookup { key_hash, shard };
|
let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
|
||||||
let result = lock.raw_entry().from_key_hashed_nocheck(lookup.key_hash, key);
|
|
||||||
|
|
||||||
if let Some((_, value)) = result {
|
if let Some((_, value)) = result {
|
||||||
let hit_result = on_hit(&&value.0, value.1);
|
let hit_result = on_hit(&&value.0, value.1);
|
||||||
Ok(hit_result)
|
Ok(hit_result)
|
||||||
} else {
|
} else {
|
||||||
Err(lookup)
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,12 +24,6 @@ use std::hash::{Hash, Hasher};
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
/// Values used when checking a query cache which can be reused on a cache-miss to execute the query.
|
|
||||||
pub struct QueryLookup {
|
|
||||||
pub(super) key_hash: u64,
|
|
||||||
pub(super) shard: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
// We compute the key's hash once and then use it for both the
|
// 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
|
// shard lookup and the hashmap lookup. This relies on the fact
|
||||||
// that both of them use `FxHasher`.
|
// that both of them use `FxHasher`.
|
||||||
@ -147,13 +141,11 @@ where
|
|||||||
state: &'b QueryState<K>,
|
state: &'b QueryState<K>,
|
||||||
span: Span,
|
span: Span,
|
||||||
key: K,
|
key: K,
|
||||||
lookup: QueryLookup,
|
|
||||||
) -> TryGetJob<'b, K>
|
) -> TryGetJob<'b, K>
|
||||||
where
|
where
|
||||||
CTX: QueryContext,
|
CTX: QueryContext,
|
||||||
{
|
{
|
||||||
let shard = lookup.shard;
|
let mut state_lock = state.shards.get_shard_by_value(&key).lock();
|
||||||
let mut state_lock = state.shards.get_shard_by_index(shard).lock();
|
|
||||||
let lock = &mut *state_lock;
|
let lock = &mut *state_lock;
|
||||||
|
|
||||||
match lock.active.entry(key) {
|
match lock.active.entry(key) {
|
||||||
@ -303,7 +295,7 @@ pub fn try_get_cached<'a, CTX, C, R, OnHit>(
|
|||||||
key: &C::Key,
|
key: &C::Key,
|
||||||
// `on_hit` can be called while holding a lock to the query cache
|
// `on_hit` can be called while holding a lock to the query cache
|
||||||
on_hit: OnHit,
|
on_hit: OnHit,
|
||||||
) -> Result<R, QueryLookup>
|
) -> Result<R, ()>
|
||||||
where
|
where
|
||||||
C: QueryCache,
|
C: QueryCache,
|
||||||
CTX: DepContext,
|
CTX: DepContext,
|
||||||
@ -324,7 +316,6 @@ fn try_execute_query<CTX, C>(
|
|||||||
cache: &C,
|
cache: &C,
|
||||||
span: Span,
|
span: Span,
|
||||||
key: C::Key,
|
key: C::Key,
|
||||||
lookup: QueryLookup,
|
|
||||||
dep_node: Option<DepNode<CTX::DepKind>>,
|
dep_node: Option<DepNode<CTX::DepKind>>,
|
||||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||||
) -> (C::Stored, Option<DepNodeIndex>)
|
) -> (C::Stored, Option<DepNodeIndex>)
|
||||||
@ -333,7 +324,7 @@ where
|
|||||||
C::Key: Clone + DepNodeParams<CTX::DepContext>,
|
C::Key: Clone + DepNodeParams<CTX::DepContext>,
|
||||||
CTX: QueryContext,
|
CTX: QueryContext,
|
||||||
{
|
{
|
||||||
match JobOwner::<'_, C::Key>::try_start(&tcx, state, span, key.clone(), lookup) {
|
match JobOwner::<'_, C::Key>::try_start(&tcx, state, span, key.clone()) {
|
||||||
TryGetJob::NotYetStarted(job) => {
|
TryGetJob::NotYetStarted(job) => {
|
||||||
let (result, dep_node_index) = execute_job(tcx, key, dep_node, query, job.id);
|
let (result, dep_node_index) = execute_job(tcx, key, dep_node, query, job.id);
|
||||||
let result = job.complete(cache, result, dep_node_index);
|
let result = job.complete(cache, result, dep_node_index);
|
||||||
@ -675,13 +666,7 @@ pub enum QueryMode {
|
|||||||
Ensure,
|
Ensure,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_query<Q, CTX>(
|
pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key, mode: QueryMode) -> Option<Q::Stored>
|
||||||
tcx: CTX,
|
|
||||||
span: Span,
|
|
||||||
key: Q::Key,
|
|
||||||
lookup: QueryLookup,
|
|
||||||
mode: QueryMode,
|
|
||||||
) -> Option<Q::Stored>
|
|
||||||
where
|
where
|
||||||
Q: QueryDescription<CTX>,
|
Q: QueryDescription<CTX>,
|
||||||
Q::Key: DepNodeParams<CTX::DepContext>,
|
Q::Key: DepNodeParams<CTX::DepContext>,
|
||||||
@ -705,7 +690,6 @@ where
|
|||||||
Q::query_cache(tcx),
|
Q::query_cache(tcx),
|
||||||
span,
|
span,
|
||||||
key,
|
key,
|
||||||
lookup,
|
|
||||||
dep_node,
|
dep_node,
|
||||||
&query,
|
&query,
|
||||||
);
|
);
|
||||||
@ -730,14 +714,14 @@ where
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let lookup = match cached {
|
match cached {
|
||||||
Ok(()) => return,
|
Ok(()) => return,
|
||||||
Err(lookup) => lookup,
|
Err(()) => {}
|
||||||
};
|
}
|
||||||
|
|
||||||
let query = Q::make_vtable(tcx, &key);
|
let query = Q::make_vtable(tcx, &key);
|
||||||
let state = Q::query_state(tcx);
|
let state = Q::query_state(tcx);
|
||||||
debug_assert!(!query.anon);
|
debug_assert!(!query.anon);
|
||||||
|
|
||||||
try_execute_query(tcx, state, cache, DUMMY_SP, key, lookup, Some(dep_node), &query);
|
try_execute_query(tcx, state, cache, DUMMY_SP, key, Some(dep_node), &query);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user