Skip to content

Commit 18218cc

Browse files
Auto merge of #142540 - cjgillot:renumber-cfg, r=<try>
Pre-compute MIR CFG caches for borrowck and other analyses I was puzzled that #142390 introduces additional computations of CFG traversals: borrowck computes them, right? It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses. This PR: - forces the computation of all caches in `mir_promoted` query; - modifies region renumbering to avoid dropping that cache. <!-- homu-ignore:start --> <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> <!-- homu-ignore:end -->
2 parents 75e7cf5 + e7e8f6d commit 18218cc

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

compiler/rustc_borrowck/src/renumber.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub(crate) fn renumber_mir<'tcx>(
2121
let mut renumberer = RegionRenumberer { infcx };
2222

2323
for body in promoted.iter_mut() {
24-
renumberer.visit_body(body);
24+
renumberer.visit_body_preserves_cfg(body);
2525
}
2626

27-
renumberer.visit_body(body);
27+
renumberer.visit_body_preserves_cfg(body);
2828
}
2929

3030
// The fields are used only for debugging output in `sccs_info`.

compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ impl<'tcx> BasicBlocks<'tcx> {
5252
BasicBlocks { basic_blocks, cache: Cache::default() }
5353
}
5454

55+
/// Force caching of traversals.
56+
pub fn cache_traversals(&self) {
57+
let _ = self.predecessors();
58+
let _ = self.switch_sources();
59+
let _ = self.reverse_postorder();
60+
let _ = self.dominators();
61+
}
62+
63+
#[inline]
5564
pub fn dominators(&self) -> &Dominators<BasicBlock> {
5665
self.cache.dominators.get_or_init(|| dominators(self))
5766
}

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ fn mir_promoted(
446446
pm::Optimizations::Allowed,
447447
);
448448

449+
// The returned MIR will be used for analyses. Make sure that the traversals are computed
450+
// early, so we don't have to re-run them.
451+
body.basic_blocks.cache_traversals();
452+
449453
lint_tail_expr_drop_order::run_lint(tcx, def, &body);
450454

451455
let promoted = promote_pass.promoted_fragments.into_inner();

0 commit comments

Comments
 (0)