1
Fork 0

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::{query_keys, query_storage, query_stored, query_val
use rustc_middle::ty::query::{Providers, QueryEngine}; use rustc_middle::ty::query::{Providers, QueryEngine};
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_serialize::opaque; use rustc_serialize::opaque;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::Span;
#[macro_use] #[macro_use]
mod plumbing; mod plumbing;

View file

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