Skip to content

Commit c986f6d

Browse files
committed
Refactor logic into try_execute_query.
1 parent 3f66069 commit c986f6d

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,34 @@ fn try_execute_query<CTX, C>(
401401
span: Span,
402402
key: C::Key,
403403
lookup: QueryLookup<'_, CTX::DepKind, CTX::Query, C::Key, C::Sharded>,
404+
caller: &QueryCaller<CTX::DepKind>,
404405
query: &QueryVtable<CTX, C::Key, C::Value>,
405406
) -> C::Stored
406407
where
407408
C: QueryCache,
408409
C::Key: crate::dep_graph::DepNodeParams<CTX>,
409410
CTX: QueryContext,
410411
{
411-
let job = match JobOwner::<'_, CTX::DepKind, CTX::Query, C>::try_start(
412+
let job = JobOwner::<'_, CTX::DepKind, CTX::Query, C>::try_start(
412413
tcx, state, span, &key, lookup, query,
413-
) {
414+
);
415+
416+
if let QueryCaller::Force(dep_node) = caller {
417+
// We may be concurrently trying both execute and force a query.
418+
// Ensure that only one of them runs the query.
419+
420+
let job = match job {
421+
TryGetJob::NotYetStarted(job) => job,
422+
TryGetJob::Cycle(result) => return result,
423+
#[cfg(parallel_compiler)]
424+
TryGetJob::JobCompleted((v, _)) => {
425+
return v;
426+
}
427+
};
428+
return force_query_with_job(tcx, key, job, *dep_node, query).0;
429+
};
430+
431+
let job = match job {
414432
TryGetJob::NotYetStarted(job) => job,
415433
TryGetJob::Cycle(result) => return result,
416434
#[cfg(parallel_compiler)]
@@ -710,31 +728,7 @@ where
710728
}
711729
}
712730
},
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-
},
731+
|key, lookup| Some(try_execute_query(tcx, state, span, key, lookup, &caller, query)),
738732
)
739733
}
740734

0 commit comments

Comments
 (0)