Skip to content

Commit c2c59ae

Browse files
committed
Move key recovering into force_query.
1 parent e1ff91f commit c2c59ae

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

compiler/rustc_query_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_val
2626
use rustc_middle::ty::query::{Providers, QueryEngine};
2727
use rustc_middle::ty::{self, TyCtxt};
2828
use rustc_serialize::opaque;
29-
use rustc_span::{Span, DUMMY_SP};
29+
use rustc_span::Span;
3030

3131
#[macro_use]
3232
mod plumbing;

compiler/rustc_query_impl/src/plumbing.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -457,20 +457,7 @@ macro_rules! define_queries {
457457
}
458458

459459
fn force_from_dep_node(tcx: QueryCtxt<'_>, dep_node: &DepNode) -> bool {
460-
if is_anon {
461-
return false;
462-
}
463-
464-
if !can_reconstruct_query_key() {
465-
return false;
466-
}
467-
468-
if let Some(key) = recover(*tcx, dep_node) {
469-
force_query::<queries::$name<'_>, _>(tcx, key, DUMMY_SP, *dep_node);
470-
return true;
471-
}
472-
473-
false
460+
force_query::<queries::$name<'_>, _>(tcx, dep_node)
474461
}
475462

476463
fn try_load_from_on_disk_cache(tcx: QueryCtxt<'_>, dep_node: &DepNode) {

compiler/rustc_query_system/src/query/plumbing.rs

+37-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! generate the actual methods on tcx which find and execute the provider,
33
//! manage the caches, and so forth.
44
5-
use crate::dep_graph::{DepContext, DepKind, DepNode};
5+
use crate::dep_graph::{DepContext, DepKind, DepNode, DepNodeParams};
66
use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
77
use crate::query::caches::QueryCache;
88
use crate::query::config::{QueryDescription, QueryVtable, QueryVtableExt};
@@ -19,7 +19,7 @@ use rustc_data_structures::thin_vec::ThinVec;
1919
#[cfg(not(parallel_compiler))]
2020
use rustc_errors::DiagnosticBuilder;
2121
use rustc_errors::{Diagnostic, FatalError};
22-
use rustc_span::Span;
22+
use rustc_span::{Span, DUMMY_SP};
2323
use std::collections::hash_map::Entry;
2424
use std::fmt::Debug;
2525
use std::hash::{Hash, Hasher};
@@ -431,7 +431,7 @@ fn try_execute_query<CTX, C>(
431431
) -> C::Stored
432432
where
433433
C: QueryCache,
434-
C::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
434+
C::Key: DepNodeParams<CTX::DepContext>,
435435
CTX: QueryContext,
436436
{
437437
let job = match JobOwner::<'_, CTX::DepKind, C>::try_start(
@@ -693,7 +693,7 @@ fn get_query_impl<CTX, C>(
693693
where
694694
CTX: QueryContext,
695695
C: QueryCache,
696-
C::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
696+
C::Key: DepNodeParams<CTX::DepContext>,
697697
{
698698
try_execute_query(tcx, state, cache, span, key, lookup, query)
699699
}
@@ -743,15 +743,25 @@ fn force_query_impl<CTX, C>(
743743
tcx: CTX,
744744
state: &QueryState<CTX::DepKind, C::Key>,
745745
cache: &QueryCacheStore<C>,
746-
key: C::Key,
747-
span: Span,
748746
dep_node: DepNode<CTX::DepKind>,
749747
query: &QueryVtable<CTX, C::Key, C::Value>,
750-
) where
748+
) -> bool
749+
where
751750
C: QueryCache,
752-
C::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
751+
C::Key: DepNodeParams<CTX::DepContext>,
753752
CTX: QueryContext,
754753
{
754+
debug_assert!(!query.anon);
755+
debug_assert!(<C::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key());
756+
757+
let key = if let Some(key) =
758+
<C::Key as DepNodeParams<CTX::DepContext>>::recover(*tcx.dep_context(), &dep_node)
759+
{
760+
key
761+
} else {
762+
return false;
763+
};
764+
755765
// We may be concurrently trying both execute and force a query.
756766
// Ensure that only one of them runs the query.
757767
let cached = cache.cache.lookup(cache, &key, |_, index| {
@@ -765,25 +775,28 @@ fn force_query_impl<CTX, C>(
765775
});
766776

767777
let lookup = match cached {
768-
Ok(()) => return,
778+
Ok(()) => return true,
769779
Err(lookup) => lookup,
770780
};
771781

772782
let job = match JobOwner::<'_, CTX::DepKind, C>::try_start(
773783
tcx,
774784
state,
775785
cache,
776-
span,
786+
DUMMY_SP,
777787
key.clone(),
778788
lookup,
779789
query,
780790
) {
781791
TryGetJob::NotYetStarted(job) => job,
782-
TryGetJob::Cycle(_) => return,
792+
TryGetJob::Cycle(_) => return true,
783793
#[cfg(parallel_compiler)]
784-
TryGetJob::JobCompleted(_) => return,
794+
TryGetJob::JobCompleted(_) => return true,
785795
};
796+
786797
force_query_with_job(tcx, key, job, dep_node, query);
798+
799+
true
787800
}
788801

789802
pub enum QueryMode {
@@ -800,7 +813,7 @@ pub fn get_query<Q, CTX>(
800813
) -> Option<Q::Stored>
801814
where
802815
Q: QueryDescription<CTX>,
803-
Q::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
816+
Q::Key: DepNodeParams<CTX::DepContext>,
804817
CTX: QueryContext,
805818
{
806819
let query = &Q::VTABLE;
@@ -816,11 +829,19 @@ where
816829
Some(value)
817830
}
818831

819-
pub fn force_query<Q, CTX>(tcx: CTX, key: Q::Key, span: Span, dep_node: DepNode<CTX::DepKind>)
832+
pub fn force_query<Q, CTX>(tcx: CTX, dep_node: &DepNode<CTX::DepKind>) -> bool
820833
where
821834
Q: QueryDescription<CTX>,
822-
Q::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
835+
Q::Key: DepNodeParams<CTX::DepContext>,
823836
CTX: QueryContext,
824837
{
825-
force_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), key, span, dep_node, &Q::VTABLE)
838+
if Q::ANON {
839+
return false;
840+
}
841+
842+
if !<Q::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key() {
843+
return false;
844+
}
845+
846+
force_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), *dep_node, &Q::VTABLE)
826847
}

0 commit comments

Comments
 (0)