Skip to content

Commit 3f66069

Browse files
committed
Remove {get,force}_query_impl.
1 parent 3e23b76 commit 3f66069

File tree

1 file changed

+54
-79
lines changed

1 file changed

+54
-79
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 54 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_data_structures::cold_path;
1414
use rustc_data_structures::fingerprint::Fingerprint;
1515
use rustc_data_structures::fx::{FxHashMap, FxHasher};
1616
use rustc_data_structures::sharded::Sharded;
17+
use rustc_data_structures::stable_hasher::HashStable;
1718
use rustc_data_structures::sync::{Lock, LockGuard};
1819
use rustc_data_structures::thin_vec::ThinVec;
1920
use rustc_errors::{Diagnostic, FatalError};
@@ -157,7 +158,7 @@ where
157158

158159
impl<'tcx, D, Q, C> JobOwner<'tcx, D, Q, C>
159160
where
160-
D: Copy + Clone + Eq + Hash,
161+
D: Copy + Clone + Eq + Hash + DepKind,
161162
Q: Clone,
162163
C: QueryCache,
163164
{
@@ -179,7 +180,8 @@ where
179180
query: &QueryVtable<CTX, C::Key, C::Value>,
180181
) -> TryGetJob<'b, CTX::DepKind, CTX::Query, C>
181182
where
182-
CTX: QueryContext,
183+
CTX: QueryContext<DepKind = D, Query = Q>,
184+
Q: HashStable<CTX::StableHashingContext>,
183185
{
184186
let lock = &mut *lookup.lock;
185187

@@ -622,31 +624,6 @@ where
622624
(result, dep_node_index)
623625
}
624626

625-
#[inline(never)]
626-
fn get_query_impl<CTX, C>(
627-
tcx: CTX,
628-
state: &QueryState<CTX::DepKind, CTX::Query, C>,
629-
span: Span,
630-
key: C::Key,
631-
query: &QueryVtable<CTX, C::Key, C::Value>,
632-
) -> C::Stored
633-
where
634-
CTX: QueryContext,
635-
C: QueryCache,
636-
C::Key: crate::dep_graph::DepNodeParams<CTX>,
637-
{
638-
try_get_cached(
639-
tcx,
640-
state,
641-
key,
642-
|value, index| {
643-
tcx.dep_graph().read_index(index);
644-
value.clone()
645-
},
646-
|key, lookup| try_execute_query(tcx, state, span, key, lookup, query),
647-
)
648-
}
649-
650627
/// Ensure that either this query has all green inputs or been executed.
651628
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
652629
///
@@ -686,43 +663,6 @@ where
686663
}
687664
}
688665

689-
#[inline(never)]
690-
fn force_query_impl<CTX, C>(
691-
tcx: CTX,
692-
state: &QueryState<CTX::DepKind, CTX::Query, C>,
693-
key: C::Key,
694-
span: Span,
695-
dep_node: DepNode<CTX::DepKind>,
696-
query: &QueryVtable<CTX, C::Key, C::Value>,
697-
) where
698-
C: QueryCache,
699-
C::Key: crate::dep_graph::DepNodeParams<CTX>,
700-
CTX: QueryContext,
701-
{
702-
// We may be concurrently trying both execute and force a query.
703-
// Ensure that only one of them runs the query.
704-
705-
try_get_cached(
706-
tcx,
707-
state,
708-
key,
709-
|_, _| {
710-
// Cache hit, do nothing
711-
},
712-
|key, lookup| {
713-
let job = match JobOwner::<'_, CTX::DepKind, CTX::Query, C>::try_start(
714-
tcx, state, span, &key, lookup, query,
715-
) {
716-
TryGetJob::NotYetStarted(job) => job,
717-
TryGetJob::Cycle(_) => return,
718-
#[cfg(parallel_compiler)]
719-
TryGetJob::JobCompleted(_) => return,
720-
};
721-
force_query_with_job(tcx, key, job, dep_node, query);
722-
},
723-
);
724-
}
725-
726666
pub enum QueryCaller<DK> {
727667
Ensure,
728668
Get,
@@ -744,23 +684,58 @@ where
744684
C::Stored: Clone,
745685
CTX: QueryContext,
746686
{
747-
match caller {
748-
QueryCaller::Ensure => {
749-
if ensure_query_impl(tcx, &key, query) {
750-
return None;
751-
}
752-
let _ = get_query_impl(tcx, state, span, key, query);
753-
None
754-
}
755-
QueryCaller::Get => {
756-
let ret = get_query_impl(tcx, state, span, key, query);
757-
Some(ret)
758-
}
759-
QueryCaller::Force(dep_node) => {
760-
force_query_impl(tcx, state, key, span, dep_node, query);
761-
None
687+
if let QueryCaller::Ensure = caller {
688+
if ensure_query_impl(tcx, &key, query) {
689+
return None;
762690
}
763691
}
692+
693+
try_get_cached(
694+
tcx,
695+
state,
696+
key,
697+
|value, index| {
698+
match &caller {
699+
QueryCaller::Ensure => {
700+
tcx.dep_graph().read_index(index);
701+
None
702+
}
703+
QueryCaller::Get => {
704+
tcx.dep_graph().read_index(index);
705+
Some(value.clone())
706+
}
707+
QueryCaller::Force(_) => {
708+
// Cache hit, do nothing
709+
None
710+
}
711+
}
712+
},
713+
|key, lookup| {
714+
match &caller {
715+
QueryCaller::Ensure => {
716+
try_execute_query(tcx, state, span, key, lookup, query);
717+
None
718+
}
719+
QueryCaller::Get => {
720+
let value = try_execute_query(tcx, state, span, key, lookup, query);
721+
Some(value)
722+
}
723+
QueryCaller::Force(dep_node) => {
724+
// We may be concurrently trying both execute and force a query.
725+
// Ensure that only one of them runs the query.
726+
727+
let job = match JobOwner::try_start(tcx, state, span, &key, lookup, query) {
728+
TryGetJob::NotYetStarted(job) => job,
729+
TryGetJob::Cycle(_) => return None,
730+
#[cfg(parallel_compiler)]
731+
TryGetJob::JobCompleted(_) => return None,
732+
};
733+
force_query_with_job(tcx, key, job, *dep_node, query);
734+
None
735+
}
736+
}
737+
},
738+
)
764739
}
765740

766741
#[inline(always)]

0 commit comments

Comments
 (0)