Move key recovering into force_query.

This commit is contained in:
Camille GILLOT 2020-11-02 20:05:10 +01:00
parent e1ff91f439
commit c2c59ae304
3 changed files with 39 additions and 31 deletions

View File

@ -26,7 +26,7 @@
use rustc_middle::ty::query::{Providers, QueryEngine};
use rustc_middle::ty::{self, TyCtxt};
use rustc_serialize::opaque;
use rustc_span::{Span, DUMMY_SP};
use rustc_span::Span;
#[macro_use]
mod plumbing;

View File

@ -457,20 +457,7 @@ fn recover<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<query_keys::$n
}
fn force_from_dep_node(tcx: QueryCtxt<'_>, dep_node: &DepNode) -> bool {
if is_anon {
return false;
}
if !can_reconstruct_query_key() {
return false;
}
if let Some(key) = recover(*tcx, dep_node) {
force_query::<queries::$name<'_>, _>(tcx, key, DUMMY_SP, *dep_node);
return true;
}
false
force_query::<queries::$name<'_>, _>(tcx, dep_node)
}
fn try_load_from_on_disk_cache(tcx: QueryCtxt<'_>, dep_node: &DepNode) {

View File

@ -2,7 +2,7 @@
//! generate the actual methods on tcx which find and execute the provider,
//! manage the caches, and so forth.
use crate::dep_graph::{DepContext, DepKind, DepNode};
use crate::dep_graph::{DepContext, DepKind, DepNode, DepNodeParams};
use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
use crate::query::caches::QueryCache;
use crate::query::config::{QueryDescription, QueryVtable, QueryVtableExt};
@ -19,7 +19,7 @@
#[cfg(not(parallel_compiler))]
use rustc_errors::DiagnosticBuilder;
use rustc_errors::{Diagnostic, FatalError};
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};
use std::collections::hash_map::Entry;
use std::fmt::Debug;
use std::hash::{Hash, Hasher};
@ -431,7 +431,7 @@ fn try_execute_query<CTX, C>(
) -> C::Stored
where
C: QueryCache,
C::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
C::Key: DepNodeParams<CTX::DepContext>,
CTX: QueryContext,
{
let job = match JobOwner::<'_, CTX::DepKind, C>::try_start(
@ -693,7 +693,7 @@ fn get_query_impl<CTX, C>(
where
CTX: QueryContext,
C: QueryCache,
C::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
C::Key: DepNodeParams<CTX::DepContext>,
{
try_execute_query(tcx, state, cache, span, key, lookup, query)
}
@ -743,15 +743,25 @@ fn force_query_impl<CTX, C>(
tcx: CTX,
state: &QueryState<CTX::DepKind, C::Key>,
cache: &QueryCacheStore<C>,
key: C::Key,
span: Span,
dep_node: DepNode<CTX::DepKind>,
query: &QueryVtable<CTX, C::Key, C::Value>,
) where
) -> bool
where
C: QueryCache,
C::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
C::Key: DepNodeParams<CTX::DepContext>,
CTX: QueryContext,
{
debug_assert!(!query.anon);
debug_assert!(<C::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key());
let key = if let Some(key) =
<C::Key as DepNodeParams<CTX::DepContext>>::recover(*tcx.dep_context(), &dep_node)
{
key
} else {
return false;
};
// We may be concurrently trying both execute and force a query.
// Ensure that only one of them runs the query.
let cached = cache.cache.lookup(cache, &key, |_, index| {
@ -765,7 +775,7 @@ fn force_query_impl<CTX, C>(
});
let lookup = match cached {
Ok(()) => return,
Ok(()) => return true,
Err(lookup) => lookup,
};
@ -773,17 +783,20 @@ fn force_query_impl<CTX, C>(
tcx,
state,
cache,
span,
DUMMY_SP,
key.clone(),
lookup,
query,
) {
TryGetJob::NotYetStarted(job) => job,
TryGetJob::Cycle(_) => return,
TryGetJob::Cycle(_) => return true,
#[cfg(parallel_compiler)]
TryGetJob::JobCompleted(_) => return,
TryGetJob::JobCompleted(_) => return true,
};
force_query_with_job(tcx, key, job, dep_node, query);
true
}
pub enum QueryMode {
@ -800,7 +813,7 @@ pub fn get_query<Q, CTX>(
) -> Option<Q::Stored>
where
Q: QueryDescription<CTX>,
Q::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
Q::Key: DepNodeParams<CTX::DepContext>,
CTX: QueryContext,
{
let query = &Q::VTABLE;
@ -816,11 +829,19 @@ pub fn get_query<Q, CTX>(
Some(value)
}
pub fn force_query<Q, CTX>(tcx: CTX, key: Q::Key, span: Span, dep_node: DepNode<CTX::DepKind>)
pub fn force_query<Q, CTX>(tcx: CTX, dep_node: &DepNode<CTX::DepKind>) -> bool
where
Q: QueryDescription<CTX>,
Q::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
Q::Key: DepNodeParams<CTX::DepContext>,
CTX: QueryContext,
{
force_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), key, span, dep_node, &Q::VTABLE)
if Q::ANON {
return false;
}
if !<Q::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key() {
return false;
}
force_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), *dep_node, &Q::VTABLE)
}