Skip to content

Commit 60d1db6

Browse files
committed
Clean up and fix a bug in query plumbing
1 parent d22fa2d commit 60d1db6

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/librustc/ty/query/plumbing.rs

+21-20
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
393393
// expensive for some DepKinds.
394394
if !self.dep_graph.is_fully_enabled() {
395395
let null_dep_node = DepNode::new_no_params(::dep_graph::DepKind::Null);
396-
return self.force_query_with_job::<Q>(key, job, null_dep_node).map(|(v, _)| v);
396+
return Ok(self.force_query_with_job::<Q>(key, job, null_dep_node).0);
397397
}
398398

399399
let dep_node = Q::to_dep_node(self, &key);
@@ -424,20 +424,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
424424

425425
if !dep_node.kind.is_input() {
426426
if let Some(dep_node_index) = self.try_mark_green_and_read(&dep_node) {
427-
return self.load_from_disk_and_cache_in_memory::<Q>(key,
428-
job,
429-
dep_node_index,
430-
&dep_node)
427+
return Ok(self.load_from_disk_and_cache_in_memory::<Q>(
428+
key,
429+
job,
430+
dep_node_index,
431+
&dep_node
432+
))
431433
}
432434
}
433435

434-
match self.force_query_with_job::<Q>(key, job, dep_node) {
435-
Ok((result, dep_node_index)) => {
436-
self.dep_graph.read_index(dep_node_index);
437-
Ok(result)
438-
}
439-
Err(e) => Err(e)
440-
}
436+
let (result, dep_node_index) = self.force_query_with_job::<Q>(key, job, dep_node);
437+
self.dep_graph.read_index(dep_node_index);
438+
Ok(result)
441439
}
442440

443441
fn load_from_disk_and_cache_in_memory<Q: QueryDescription<'gcx>>(
@@ -446,7 +444,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
446444
job: JobOwner<'a, 'gcx, Q>,
447445
dep_node_index: DepNodeIndex,
448446
dep_node: &DepNode
449-
) -> Result<Q::Value, Box<CycleError<'gcx>>>
447+
) -> Q::Value
450448
{
451449
// Note this function can be called concurrently from the same query
452450
// We must ensure that this is handled correctly
@@ -511,7 +509,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
511509

512510
job.complete(&result, dep_node_index);
513511

514-
Ok(result)
512+
result
515513
}
516514

517515
#[inline(never)]
@@ -551,7 +549,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
551549
key: Q::Key,
552550
job: JobOwner<'_, 'gcx, Q>,
553551
dep_node: DepNode)
554-
-> Result<(Q::Value, DepNodeIndex), Box<CycleError<'gcx>>> {
552+
-> (Q::Value, DepNodeIndex) {
555553
// If the following assertion triggers, it can have two reasons:
556554
// 1. Something is wrong with DepNode creation, either here or
557555
// in DepGraph::try_mark_green()
@@ -596,7 +594,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
596594

597595
job.complete(&result, dep_node_index);
598596

599-
Ok((result, dep_node_index))
597+
(result, dep_node_index)
600598
}
601599

602600
/// Ensure that either this query has all green inputs or been executed.
@@ -643,11 +641,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
643641
// Ensure that only one of them runs the query
644642
let job = match JobOwner::try_get(self, span, &key) {
645643
TryGetJob::NotYetStarted(job) => job,
646-
TryGetJob::JobCompleted(_) => return,
644+
TryGetJob::JobCompleted(result) => {
645+
if let Err(e) = result {
646+
self.report_cycle(e).emit();
647+
}
648+
return
649+
}
647650
};
648-
if let Err(e) = self.force_query_with_job::<Q>(key, job, dep_node) {
649-
self.report_cycle(e).emit();
650-
}
651+
self.force_query_with_job::<Q>(key, job, dep_node);
651652
}
652653

653654
pub(super) fn try_get_query<Q: QueryDescription<'gcx>>(

0 commit comments

Comments
 (0)