Skip to content

Commit cd1cb34

Browse files
committed
Simplify control flow.
1 parent 0edc775 commit cd1cb34

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ where
528528
debug_assert!(tcx.dep_context().dep_graph().is_green(dep_node));
529529

530530
// First we try to load the result from the on-disk cache.
531-
let result = if query.cache_on_disk(tcx, key, None) {
531+
// Some things are never cached on disk.
532+
if query.cache_on_disk(tcx, key, None) {
532533
let prof_timer = tcx.dep_context().profiler().incr_cache_loading();
533534
let result = query.try_load_from_disk(tcx, prev_dep_node_index);
534535
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
@@ -540,44 +541,38 @@ where
540541
"missing on-disk cache entry for {:?}",
541542
dep_node
542543
);
543-
result
544-
} else {
545-
// Some things are never cached on disk.
546-
None
547-
};
548544

549-
let result = if let Some(result) = result {
550-
// If `-Zincremental-verify-ich` is specified, re-hash results from
551-
// the cache and make sure that they have the expected fingerprint.
552-
if unlikely!(tcx.dep_context().sess().opts.debugging_opts.incremental_verify_ich) {
553-
incremental_verify_ich(*tcx.dep_context(), &result, dep_node, query);
554-
}
545+
if let Some(result) = result {
546+
// If `-Zincremental-verify-ich` is specified, re-hash results from
547+
// the cache and make sure that they have the expected fingerprint.
548+
if unlikely!(tcx.dep_context().sess().opts.debugging_opts.incremental_verify_ich) {
549+
incremental_verify_ich(*tcx.dep_context(), &result, dep_node, query);
550+
}
555551

556-
result
557-
} else {
558-
// We could not load a result from the on-disk cache, so
559-
// recompute.
560-
let prof_timer = tcx.dep_context().profiler().query_provider();
552+
return Some((result, dep_node_index));
553+
}
554+
}
561555

562-
// The dep-graph for this computation is already in-place.
563-
let result =
564-
tcx.dep_context().dep_graph().with_ignore(|| compute(*tcx.dep_context(), key.clone()));
556+
// We could not load a result from the on-disk cache, so
557+
// recompute.
558+
let prof_timer = tcx.dep_context().profiler().query_provider();
565559

566-
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
560+
// The dep-graph for this computation is already in-place.
561+
let result =
562+
tcx.dep_context().dep_graph().with_ignore(|| compute(*tcx.dep_context(), key.clone()));
567563

568-
// Verify that re-running the query produced a result with the expected hash
569-
// This catches bugs in query implementations, turning them into ICEs.
570-
// For example, a query might sort its result by `DefId` - since `DefId`s are
571-
// not stable across compilation sessions, the result could get up getting sorted
572-
// in a different order when the query is re-run, even though all of the inputs
573-
// (e.g. `DefPathHash` values) were green.
574-
//
575-
// See issue #82920 for an example of a miscompilation that would get turned into
576-
// an ICE by this check
577-
incremental_verify_ich(*tcx.dep_context(), &result, dep_node, query);
564+
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
578565

579-
result
580-
};
566+
// Verify that re-running the query produced a result with the expected hash
567+
// This catches bugs in query implementations, turning them into ICEs.
568+
// For example, a query might sort its result by `DefId` - since `DefId`s are
569+
// not stable across compilation sessions, the result could get up getting sorted
570+
// in a different order when the query is re-run, even though all of the inputs
571+
// (e.g. `DefPathHash` values) were green.
572+
//
573+
// See issue #82920 for an example of a miscompilation that would get turned into
574+
// an ICE by this check
575+
incremental_verify_ich(*tcx.dep_context(), &result, dep_node, query);
581576

582577
Some((result, dep_node_index))
583578
}

0 commit comments

Comments
 (0)