Skip to content

Commit

Permalink
Auto merge of #60730 - matthewjasper:optimize-false-edges, r=pnkfelix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 16, 2019
2 parents 374c63e + 89ea69a commit 6865502
Show file tree
Hide file tree
Showing 40 changed files with 856 additions and 738 deletions.
23 changes: 10 additions & 13 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,9 @@ pub enum TerminatorKind<'tcx> {
FalseEdges {
/// The target normal control flow will take
real_target: BasicBlock,
/// The list of blocks control flow could conceptually take, but won't
/// in practice
imaginary_targets: Vec<BasicBlock>,
/// A block control flow could conceptually jump to, but won't in
/// practice
imaginary_target: BasicBlock,
},
/// A terminator for blocks that only take one path in reality, but where we
/// reserve the right to unwind in borrowck, even if it won't happen in practice.
Expand Down Expand Up @@ -1335,8 +1335,8 @@ impl<'tcx> TerminatorKind<'tcx> {
SwitchInt { ref targets, .. } => None.into_iter().chain(&targets[..]),
FalseEdges {
ref real_target,
ref imaginary_targets,
} => Some(real_target).into_iter().chain(&imaginary_targets[..]),
ref imaginary_target,
} => Some(real_target).into_iter().chain(slice::from_ref(imaginary_target)),
}
}

Expand Down Expand Up @@ -1422,10 +1422,10 @@ impl<'tcx> TerminatorKind<'tcx> {
} => None.into_iter().chain(&mut targets[..]),
FalseEdges {
ref mut real_target,
ref mut imaginary_targets,
ref mut imaginary_target,
} => Some(real_target)
.into_iter()
.chain(&mut imaginary_targets[..]),
.chain(slice::from_mut(imaginary_target)),
}
}

Expand Down Expand Up @@ -1722,12 +1722,9 @@ impl<'tcx> TerminatorKind<'tcx> {
Assert { cleanup: None, .. } => vec!["".into()],
Assert { .. } => vec!["success".into(), "unwind".into()],
FalseEdges {
ref imaginary_targets,
..
} => {
let mut l = vec!["real".into()];
l.resize(imaginary_targets.len() + 1, "imaginary".into());
l
vec!["real".into(), "imaginary".into()]
}
FalseUnwind {
unwind: Some(_), ..
Expand Down Expand Up @@ -3356,10 +3353,10 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
Unreachable => Unreachable,
FalseEdges {
real_target,
ref imaginary_targets,
imaginary_target,
} => FalseEdges {
real_target,
imaginary_targets: imaginary_targets.clone(),
imaginary_target,
},
FalseUnwind {
real_target,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
| TerminatorKind::Unreachable
| TerminatorKind::FalseEdges {
real_target: _,
imaginary_targets: _,
imaginary_target: _,
}
| TerminatorKind::FalseUnwind {
real_target: _,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
| TerminatorKind::Unreachable
| TerminatorKind::FalseEdges {
real_target: _,
imaginary_targets: _,
imaginary_target: _,
}
| TerminatorKind::FalseUnwind {
real_target: _,
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1792,12 +1792,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
TerminatorKind::FalseEdges {
real_target,
ref imaginary_targets,
imaginary_target,
} => {
self.assert_iscleanup(body, block_data, real_target, is_cleanup);
for target in imaginary_targets {
self.assert_iscleanup(body, block_data, *target, is_cleanup);
}
self.assert_iscleanup(body, block_data, imaginary_target, is_cleanup);
}
TerminatorKind::FalseUnwind {
real_target,
Expand Down
Loading

0 comments on commit 6865502

Please sign in to comment.