Skip to content

Commit bb3b209

Browse files
committed
Refactor logic into try_execute_query.
1 parent 2bcd0e2 commit bb3b209

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,32 @@ fn try_execute_query<CTX, C>(
389389
span: Span,
390390
key: C::Key,
391391
lookup: QueryLookup<'_, CTX, C::Key, C::Sharded>,
392+
caller: &QueryCaller<CTX::DepKind>,
392393
query: &QueryVtable<CTX, C::Key, C::Value>,
393394
) -> C::Stored
394395
where
395396
C: QueryCache,
396397
C::Key: Eq + Clone + Debug + crate::dep_graph::DepNodeParams<CTX>,
397398
CTX: QueryContext,
398399
{
399-
let job = match JobOwner::try_start(tcx, state, span, &key, lookup, query) {
400+
let job = JobOwner::try_start(tcx, state, span, &key, lookup, query);
401+
402+
if let QueryCaller::Force(dep_node) = caller {
403+
// We may be concurrently trying both execute and force a query.
404+
// Ensure that only one of them runs the query.
405+
406+
let job = match job {
407+
TryGetJob::NotYetStarted(job) => job,
408+
TryGetJob::Cycle(result) => return result,
409+
#[cfg(parallel_compiler)]
410+
TryGetJob::JobCompleted((v, _)) => {
411+
return v;
412+
}
413+
};
414+
return force_query_with_job(tcx, key, job, *dep_node, query).0;
415+
};
416+
417+
let job = match job {
400418
TryGetJob::NotYetStarted(job) => job,
401419
TryGetJob::Cycle(result) => return result,
402420
#[cfg(parallel_compiler)]
@@ -698,31 +716,7 @@ where
698716
}
699717
}
700718
},
701-
|key, lookup| {
702-
match &caller {
703-
QueryCaller::Ensure => {
704-
try_execute_query(tcx, state, span, key, lookup, query);
705-
None
706-
}
707-
QueryCaller::Get => {
708-
let value = try_execute_query(tcx, state, span, key, lookup, query);
709-
Some(value)
710-
}
711-
QueryCaller::Force(dep_node) => {
712-
// We may be concurrently trying both execute and force a query.
713-
// Ensure that only one of them runs the query.
714-
715-
let job = match JobOwner::try_start(tcx, state, span, &key, lookup, query) {
716-
TryGetJob::NotYetStarted(job) => job,
717-
TryGetJob::Cycle(_) => return None,
718-
#[cfg(parallel_compiler)]
719-
TryGetJob::JobCompleted(_) => return None,
720-
};
721-
force_query_with_job(tcx, key, job, *dep_node, query);
722-
None
723-
}
724-
}
725-
},
719+
|key, lookup| Some(try_execute_query(tcx, state, span, key, lookup, &caller, query)),
726720
)
727721
}
728722

0 commit comments

Comments
 (0)