Skip to content

Commit d3946c3

Browse files
committed
Auto merge of #60730 - matthewjasper:optimize-false-edges, r=<try>
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 2268d99 + 2f57a82 commit d3946c3

40 files changed

+856
-740
lines changed

src/librustc/mir/mod.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -1185,9 +1185,9 @@ pub enum TerminatorKind<'tcx> {
11851185
FalseEdges {
11861186
/// The target normal control flow will take
11871187
real_target: BasicBlock,
1188-
/// The list of blocks control flow could conceptually take, but won't
1189-
/// in practice
1190-
imaginary_targets: Vec<BasicBlock>,
1188+
/// A block control flow could conceptually jump to, but won't in
1189+
/// practice
1190+
imaginary_target: BasicBlock,
11911191
},
11921192
/// A terminator for blocks that only take one path in reality, but where we
11931193
/// reserve the right to unwind in borrowck, even if it won't happen in practice.
@@ -1324,8 +1324,8 @@ impl<'tcx> TerminatorKind<'tcx> {
13241324
SwitchInt { ref targets, .. } => None.into_iter().chain(&targets[..]),
13251325
FalseEdges {
13261326
ref real_target,
1327-
ref imaginary_targets,
1328-
} => Some(real_target).into_iter().chain(&imaginary_targets[..]),
1327+
ref imaginary_target,
1328+
} => Some(real_target).into_iter().chain(slice::from_ref(imaginary_target)),
13291329
}
13301330
}
13311331

@@ -1411,10 +1411,10 @@ impl<'tcx> TerminatorKind<'tcx> {
14111411
} => None.into_iter().chain(&mut targets[..]),
14121412
FalseEdges {
14131413
ref mut real_target,
1414-
ref mut imaginary_targets,
1414+
ref mut imaginary_target,
14151415
} => Some(real_target)
14161416
.into_iter()
1417-
.chain(&mut imaginary_targets[..]),
1417+
.chain(slice::from_mut(imaginary_target)),
14181418
}
14191419
}
14201420

@@ -1714,12 +1714,9 @@ impl<'tcx> TerminatorKind<'tcx> {
17141714
Assert { cleanup: None, .. } => vec!["".into()],
17151715
Assert { .. } => vec!["success".into(), "unwind".into()],
17161716
FalseEdges {
1717-
ref imaginary_targets,
17181717
..
17191718
} => {
1720-
let mut l = vec!["real".into()];
1721-
l.resize(imaginary_targets.len() + 1, "imaginary".into());
1722-
l
1719+
vec!["real".into(), "imaginary".into()]
17231720
}
17241721
FalseUnwind {
17251722
unwind: Some(_), ..
@@ -3342,10 +3339,10 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
33423339
Unreachable => Unreachable,
33433340
FalseEdges {
33443341
real_target,
3345-
ref imaginary_targets,
3342+
imaginary_target,
33463343
} => FalseEdges {
33473344
real_target,
3348-
imaginary_targets: imaginary_targets.clone(),
3345+
imaginary_target,
33493346
},
33503347
FalseUnwind {
33513348
real_target,

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
806806
| TerminatorKind::Unreachable
807807
| TerminatorKind::FalseEdges {
808808
real_target: _,
809-
imaginary_targets: _,
809+
imaginary_target: _,
810810
}
811811
| TerminatorKind::FalseUnwind {
812812
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, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
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, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
17921792
}
17931793
TerminatorKind::FalseEdges {
17941794
real_target,
1795-
ref imaginary_targets,
1795+
imaginary_target,
17961796
} => {
17971797
self.assert_iscleanup(mir, block_data, real_target, is_cleanup);
1798-
for target in imaginary_targets {
1799-
self.assert_iscleanup(mir, block_data, *target, is_cleanup);
1800-
}
1798+
self.assert_iscleanup(mir, block_data, imaginary_target, is_cleanup);
18011799
}
18021800
TerminatorKind::FalseUnwind {
18031801
real_target,

0 commit comments

Comments
 (0)