From c2c59ae304f3a6735bce209eb206d610c903da05 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 2 Nov 2020 20:05:10 +0100 Subject: [PATCH] Move key recovering into force_query. --- compiler/rustc_query_impl/src/lib.rs | 2 +- compiler/rustc_query_impl/src/plumbing.rs | 15 +----- .../rustc_query_system/src/query/plumbing.rs | 53 +++++++++++++------ 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 00d886000faa..ac81c0261e29 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -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::{self, TyCtxt}; use rustc_serialize::opaque; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; #[macro_use] mod plumbing; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index c789aa2fa596..dbda6f304c78 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -457,20 +457,7 @@ macro_rules! define_queries { } 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::, _>(tcx, key, DUMMY_SP, *dep_node); - return true; - } - - false + force_query::, _>(tcx, dep_node) } fn try_load_from_on_disk_cache(tcx: QueryCtxt<'_>, dep_node: &DepNode) { diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 39dfdd78cc4f..d91eadb149cf 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -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 @@ use rustc_data_structures::thin_vec::ThinVec; #[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( ) -> C::Stored where C: QueryCache, - C::Key: crate::dep_graph::DepNodeParams, + C::Key: DepNodeParams, CTX: QueryContext, { let job = match JobOwner::<'_, CTX::DepKind, C>::try_start( @@ -693,7 +693,7 @@ fn get_query_impl( where CTX: QueryContext, C: QueryCache, - C::Key: crate::dep_graph::DepNodeParams, + C::Key: DepNodeParams, { try_execute_query(tcx, state, cache, span, key, lookup, query) } @@ -743,15 +743,25 @@ fn force_query_impl( tcx: CTX, state: &QueryState, cache: &QueryCacheStore, - key: C::Key, - span: Span, dep_node: DepNode, query: &QueryVtable, -) where +) -> bool +where C: QueryCache, - C::Key: crate::dep_graph::DepNodeParams, + C::Key: DepNodeParams, CTX: QueryContext, { + debug_assert!(!query.anon); + debug_assert!(>::can_reconstruct_query_key()); + + let key = if let Some(key) = + >::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( }); let lookup = match cached { - Ok(()) => return, + Ok(()) => return true, Err(lookup) => lookup, }; @@ -773,17 +783,20 @@ fn force_query_impl( 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( ) -> Option where Q: QueryDescription, - Q::Key: crate::dep_graph::DepNodeParams, + Q::Key: DepNodeParams, CTX: QueryContext, { let query = &Q::VTABLE; @@ -816,11 +829,19 @@ where Some(value) } -pub fn force_query(tcx: CTX, key: Q::Key, span: Span, dep_node: DepNode) +pub fn force_query(tcx: CTX, dep_node: &DepNode) -> bool where Q: QueryDescription, - Q::Key: crate::dep_graph::DepNodeParams, + Q::Key: DepNodeParams, 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 !>::can_reconstruct_query_key() { + return false; + } + + force_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), *dep_node, &Q::VTABLE) }