let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, noop);
- let lookup = match cached {
+ match cached {
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);
})*
}
let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, copy);
- let lookup = match cached {
+ match cached {
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()
})*
}
tcx: TyCtxt<$tcx>,
span: Span,
key: query_keys::$name<$tcx>,
- lookup: QueryLookup,
mode: QueryMode,
) -> Option<query_stored::$name<$tcx>>;)*
}
tcx: TyCtxt<$tcx>,
span: Span,
key: query_keys::$name<$tcx>,
- lookup: QueryLookup,
mode: QueryMode,
) -> Option<query_stored::$name<$tcx>> {
opt_remap_env_constness!([$($modifiers)*][key]);
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)
})*
}
};
use crate::dep_graph::DepNodeIndex;
-use crate::query::plumbing::QueryLookup;
use rustc_arena::TypedArena;
use rustc_data_structures::fx::FxHashMap;
key: &Self::Key,
// `on_hit` can be called while holding a lock to the query state shard.
on_hit: OnHit,
- ) -> Result<R, QueryLookup>
+ ) -> Result<R, ()>
where
OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R;
type Key = K;
#[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
OnHit: FnOnce(&V, DepNodeIndex) -> R,
{
let key_hash = sharded::make_hash(key);
let shard = sharded::get_shard_index_by_hash(key_hash);
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(lookup.key_hash, key);
+ let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
if let Some((_, value)) = result {
let hit_result = on_hit(&value.0, value.1);
Ok(hit_result)
} else {
- Err(lookup)
+ Err(())
}
}
type Key = K;
#[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
OnHit: FnOnce(&&'tcx V, DepNodeIndex) -> R,
{
let key_hash = sharded::make_hash(key);
let shard = sharded::get_shard_index_by_hash(key_hash);
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(lookup.key_hash, key);
+ let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
if let Some((_, value)) = result {
let hit_result = on_hit(&&value.0, value.1);
Ok(hit_result)
} else {
- Err(lookup)
+ Err(())
}
}
use std::mem;
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
// shard lookup and the hashmap lookup. This relies on the fact
// that both of them use `FxHasher`.
state: &'b QueryState<K>,
span: Span,
key: K,
- lookup: QueryLookup,
) -> TryGetJob<'b, K>
where
CTX: QueryContext,
{
- let shard = lookup.shard;
- let mut state_lock = state.shards.get_shard_by_index(shard).lock();
+ let mut state_lock = state.shards.get_shard_by_value(&key).lock();
let lock = &mut *state_lock;
match lock.active.entry(key) {
key: &C::Key,
// `on_hit` can be called while holding a lock to the query cache
on_hit: OnHit,
-) -> Result<R, QueryLookup>
+) -> Result<R, ()>
where
C: QueryCache,
CTX: DepContext,
cache: &C,
span: Span,
key: C::Key,
- lookup: QueryLookup,
dep_node: Option<DepNode<CTX::DepKind>>,
query: &QueryVtable<CTX, C::Key, C::Value>,
) -> (C::Stored, Option<DepNodeIndex>)
C::Key: Clone + DepNodeParams<CTX::DepContext>,
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) => {
let (result, dep_node_index) = execute_job(tcx, key, dep_node, query, job.id);
let result = job.complete(cache, result, dep_node_index);
Ensure,
}
-pub fn get_query<Q, CTX>(
- tcx: CTX,
- span: Span,
- key: Q::Key,
- lookup: QueryLookup,
- mode: QueryMode,
-) -> Option<Q::Stored>
+pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key, mode: QueryMode) -> Option<Q::Stored>
where
Q: QueryDescription<CTX>,
Q::Key: DepNodeParams<CTX::DepContext>,
Q::query_cache(tcx),
span,
key,
- lookup,
dep_node,
&query,
);
}
});
- let lookup = match cached {
+ match cached {
Ok(()) => return,
- Err(lookup) => lookup,
- };
+ Err(()) => {}
+ }
let query = Q::make_vtable(tcx, &key);
let state = Q::query_state(tcx);
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);
}