Do not compute the dep_node twice.
This commit is contained in:
parent
283a8e1445
commit
13d4eb92b8
1 changed files with 21 additions and 33 deletions
|
@ -685,30 +685,6 @@ where
|
||||||
(result, dep_node_index)
|
(result, dep_node_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn get_query_impl<CTX, C>(
|
|
||||||
tcx: CTX,
|
|
||||||
state: &QueryState<CTX::DepKind, C::Key>,
|
|
||||||
cache: &QueryCacheStore<C>,
|
|
||||||
span: Span,
|
|
||||||
key: C::Key,
|
|
||||||
lookup: QueryLookup,
|
|
||||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
|
||||||
compute: fn(CTX::DepContext, C::Key) -> C::Value,
|
|
||||||
) -> C::Stored
|
|
||||||
where
|
|
||||||
CTX: QueryContext,
|
|
||||||
C: QueryCache,
|
|
||||||
C::Key: DepNodeParams<CTX::DepContext>,
|
|
||||||
{
|
|
||||||
let (result, dep_node_index) =
|
|
||||||
try_execute_query(tcx, state, cache, span, key, lookup, None, query, compute);
|
|
||||||
if let Some(dep_node_index) = dep_node_index {
|
|
||||||
tcx.dep_context().dep_graph().read_index(dep_node_index)
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ensure that either this query has all green inputs or been executed.
|
/// Ensure that either this query has all green inputs or been executed.
|
||||||
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
|
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
|
||||||
/// Returns true if the query should still run.
|
/// Returns true if the query should still run.
|
||||||
|
@ -718,13 +694,17 @@ where
|
||||||
///
|
///
|
||||||
/// Note: The optimization is only available during incr. comp.
|
/// Note: The optimization is only available during incr. comp.
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn ensure_must_run<CTX, K, V>(tcx: CTX, key: &K, query: &QueryVtable<CTX, K, V>) -> bool
|
fn ensure_must_run<CTX, K, V>(
|
||||||
|
tcx: CTX,
|
||||||
|
key: &K,
|
||||||
|
query: &QueryVtable<CTX, K, V>,
|
||||||
|
) -> (bool, Option<DepNode<CTX::DepKind>>)
|
||||||
where
|
where
|
||||||
K: crate::dep_graph::DepNodeParams<CTX::DepContext>,
|
K: crate::dep_graph::DepNodeParams<CTX::DepContext>,
|
||||||
CTX: QueryContext,
|
CTX: QueryContext,
|
||||||
{
|
{
|
||||||
if query.eval_always {
|
if query.eval_always {
|
||||||
return true;
|
return (true, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensuring an anonymous query makes no sense
|
// Ensuring an anonymous query makes no sense
|
||||||
|
@ -741,12 +721,12 @@ where
|
||||||
// DepNodeIndex. We must invoke the query itself. The performance cost
|
// DepNodeIndex. We must invoke the query itself. The performance cost
|
||||||
// this introduces should be negligible as we'll immediately hit the
|
// this introduces should be negligible as we'll immediately hit the
|
||||||
// in-memory cache, or another query down the line will.
|
// in-memory cache, or another query down the line will.
|
||||||
true
|
(true, Some(dep_node))
|
||||||
}
|
}
|
||||||
Some((_, dep_node_index)) => {
|
Some((_, dep_node_index)) => {
|
||||||
dep_graph.read_index(dep_node_index);
|
dep_graph.read_index(dep_node_index);
|
||||||
tcx.dep_context().profiler().query_cache_hit(dep_node_index.into());
|
tcx.dep_context().profiler().query_cache_hit(dep_node_index.into());
|
||||||
false
|
(false, None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -808,25 +788,33 @@ where
|
||||||
CTX: QueryContext,
|
CTX: QueryContext,
|
||||||
{
|
{
|
||||||
let query = &Q::VTABLE;
|
let query = &Q::VTABLE;
|
||||||
if let QueryMode::Ensure = mode {
|
let dep_node = if let QueryMode::Ensure = mode {
|
||||||
if !ensure_must_run(tcx, &key, query) {
|
let (must_run, dep_node) = ensure_must_run(tcx, &key, query);
|
||||||
|
if !must_run {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
dep_node
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
|
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
|
||||||
let compute = Q::compute_fn(tcx, &key);
|
let compute = Q::compute_fn(tcx, &key);
|
||||||
let value = get_query_impl(
|
let (result, dep_node_index) = try_execute_query(
|
||||||
tcx,
|
tcx,
|
||||||
Q::query_state(tcx),
|
Q::query_state(tcx),
|
||||||
Q::query_cache(tcx),
|
Q::query_cache(tcx),
|
||||||
span,
|
span,
|
||||||
key,
|
key,
|
||||||
lookup,
|
lookup,
|
||||||
|
dep_node,
|
||||||
query,
|
query,
|
||||||
compute,
|
compute,
|
||||||
);
|
);
|
||||||
Some(value)
|
if let Some(dep_node_index) = dep_node_index {
|
||||||
|
tcx.dep_context().dep_graph().read_index(dep_node_index)
|
||||||
|
}
|
||||||
|
Some(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn force_query<Q, CTX>(tcx: CTX, dep_node: &DepNode<CTX::DepKind>) -> bool
|
pub fn force_query<Q, CTX>(tcx: CTX, dep_node: &DepNode<CTX::DepKind>) -> bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue