Skip to content

Commit 6865502

Browse files
committed
Auto merge of #60730 - matthewjasper:optimize-false-edges, r=pnkfelix
Optimize matches Attempt to fix or improve #60571 This is breaking some diagnostics because the MIR for match arms isn't in source order any more. cc @Centril
2 parents 374c63e + 89ea69a commit 6865502

40 files changed

+856
-738
lines changed

src/librustc/mir/mod.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,9 @@ pub enum TerminatorKind<'tcx> {
11961196
FalseEdges {
11971197
/// The target normal control flow will take
11981198
real_target: BasicBlock,
1199-
/// The list of blocks control flow could conceptually take, but won't
1200-
/// in practice
1201-
imaginary_targets: Vec<BasicBlock>,
1199+
/// A block control flow could conceptually jump to, but won't in
1200+
/// practice
1201+
imaginary_target: BasicBlock,
12021202
},
12031203
/// A terminator for blocks that only take one path in reality, but where we
12041204
/// reserve the right to unwind in borrowck, even if it won't happen in practice.
@@ -1335,8 +1335,8 @@ impl<'tcx> TerminatorKind<'tcx> {
13351335
SwitchInt { ref targets, .. } => None.into_iter().chain(&targets[..]),
13361336
FalseEdges {
13371337
ref real_target,
1338-
ref imaginary_targets,
1339-
} => Some(real_target).into_iter().chain(&imaginary_targets[..]),
1338+
ref imaginary_target,
1339+
} => Some(real_target).into_iter().chain(slice::from_ref(imaginary_target)),
13401340
}
13411341
}
13421342

@@ -1422,10 +1422,10 @@ impl<'tcx> TerminatorKind<'tcx> {
14221422
} => None.into_iter().chain(&mut targets[..]),
14231423
FalseEdges {
14241424
ref mut real_target,
1425-
ref mut imaginary_targets,
1425+
ref mut imaginary_target,
14261426
} => Some(real_target)
14271427
.into_iter()
1428-
.chain(&mut imaginary_targets[..]),
1428+
.chain(slice::from_mut(imaginary_target)),
14291429
}
14301430
}
14311431

@@ -1722,12 +1722,9 @@ impl<'tcx> TerminatorKind<'tcx> {
17221722
Assert { cleanup: None, .. } => vec!["".into()],
17231723
Assert { .. } => vec!["success".into(), "unwind".into()],
17241724
FalseEdges {
1725-
ref imaginary_targets,
17261725
..
17271726
} => {
1728-
let mut l = vec!["real".into()];
1729-
l.resize(imaginary_targets.len() + 1, "imaginary".into());
1730-
l
1727+
vec!["real".into(), "imaginary".into()]
17311728
}
17321729
FalseUnwind {
17331730
unwind: Some(_), ..
@@ -3356,10 +3353,10 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
33563353
Unreachable => Unreachable,
33573354
FalseEdges {
33583355
real_target,
3359-
ref imaginary_targets,
3356+
imaginary_target,
33603357
} => FalseEdges {
33613358
real_target,
3362-
imaginary_targets: imaginary_targets.clone(),
3359+
imaginary_target,
33633360
},
33643361
FalseUnwind {
33653362
real_target,

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
780780
| TerminatorKind::Unreachable
781781
| TerminatorKind::FalseEdges {
782782
real_target: _,
783-
imaginary_targets: _,
783+
imaginary_target: _,
784784
}
785785
| TerminatorKind::FalseUnwind {
786786
real_target: _,

src/librustc_mir/borrow_check/nll/invalidation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
244244
| TerminatorKind::Unreachable
245245
| TerminatorKind::FalseEdges {
246246
real_target: _,
247-
imaginary_targets: _,
247+
imaginary_target: _,
248248
}
249249
| TerminatorKind::FalseUnwind {
250250
real_target: _,

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1792,12 +1792,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17921792
}
17931793
TerminatorKind::FalseEdges {
17941794
real_target,
1795-
ref imaginary_targets,
1795+
imaginary_target,
17961796
} => {
17971797
self.assert_iscleanup(body, block_data, real_target, is_cleanup);
1798-
for target in imaginary_targets {
1799-
self.assert_iscleanup(body, block_data, *target, is_cleanup);
1800-
}
1798+
self.assert_iscleanup(body, block_data, imaginary_target, is_cleanup);
18011799
}
18021800
TerminatorKind::FalseUnwind {
18031801
real_target,

0 commit comments

Comments
 (0)