Skip to content

Commit 63dcdf7

Browse files
committed
Auto merge of #147867 - cjgillot:invalidate-cleanup, r=tmiasko
Stop invalidating CFG caches in CleanupPostBorrowck. r? `@ghost`
2 parents c7a635f + 6abc50b commit 63dcdf7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
//! [`SpanMarker`]: rustc_middle::mir::coverage::CoverageKind::SpanMarker
1818
1919
use rustc_middle::mir::coverage::CoverageKind;
20-
use rustc_middle::mir::{Body, BorrowKind, CastKind, Rvalue, StatementKind, TerminatorKind};
20+
use rustc_middle::mir::*;
2121
use rustc_middle::ty::TyCtxt;
2222
use rustc_middle::ty::adjustment::PointerCoercion;
2323

2424
pub(super) struct CleanupPostBorrowck;
2525

2626
impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
2727
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
28-
for basic_block in body.basic_blocks.as_mut() {
28+
// Manually invalidate CFG caches if we actually change a terminator's edges.
29+
let mut invalidate_cfg = false;
30+
for basic_block in body.basic_blocks.as_mut_preserves_cfg().iter_mut() {
2931
for statement in basic_block.statements.iter_mut() {
3032
match statement.kind {
3133
StatementKind::AscribeUserType(..)
@@ -59,16 +61,23 @@ impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
5961
_ => (),
6062
}
6163
}
64+
65+
// If we change any terminator, we need to ensure that we invalidated the CFG cache.
6266
let terminator = basic_block.terminator_mut();
6367
match terminator.kind {
6468
TerminatorKind::FalseEdge { real_target, .. }
6569
| TerminatorKind::FalseUnwind { real_target, .. } => {
70+
invalidate_cfg = true;
6671
terminator.kind = TerminatorKind::Goto { target: real_target };
6772
}
6873
_ => {}
6974
}
7075
}
7176

77+
if invalidate_cfg {
78+
body.basic_blocks.invalidate_cfg_cache();
79+
}
80+
7281
body.user_type_annotations.raw.clear();
7382

7483
for decl in &mut body.local_decls {

0 commit comments

Comments
 (0)