Skip to content

Commit 1c4c089

Browse files
authored
Rollup merge of rust-lang#129929 - nnethercote:rustc_mir_transform-cleanups-2, r=cjgillot
`rustc_mir_transform` cleanups, round 2 More cleanups in the style of rust-lang#129738. r? `@cjgillot`
2 parents 59fe4e9 + 5445953 commit 1c4c089

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+277
-311
lines changed

compiler/rustc_mir_transform/src/abort_unwinding_calls.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_target::spec::PanicStrategy;
2020
/// This forces all unwinds, in panic=abort mode happening in foreign code, to
2121
/// trigger a process abort.
2222
#[derive(PartialEq)]
23-
pub struct AbortUnwindingCalls;
23+
pub(super) struct AbortUnwindingCalls;
2424

2525
impl<'tcx> crate::MirPass<'tcx> for AbortUnwindingCalls {
2626
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@@ -50,9 +50,7 @@ impl<'tcx> crate::MirPass<'tcx> for AbortUnwindingCalls {
5050
// with a function call, and whose function we're calling may unwind.
5151
// This will filter to functions with `extern "C-unwind"` ABIs, for
5252
// example.
53-
let mut calls_to_terminate = Vec::new();
54-
let mut cleanups_to_remove = Vec::new();
55-
for (id, block) in body.basic_blocks.iter_enumerated() {
53+
for block in body.basic_blocks.as_mut() {
5654
if block.is_cleanup {
5755
continue;
5856
}
@@ -61,7 +59,7 @@ impl<'tcx> crate::MirPass<'tcx> for AbortUnwindingCalls {
6159

6260
let call_can_unwind = match &terminator.kind {
6361
TerminatorKind::Call { func, .. } => {
64-
let ty = func.ty(body, tcx);
62+
let ty = func.ty(&body.local_decls, tcx);
6563
let sig = ty.fn_sig(tcx);
6664
let fn_def_id = match ty.kind() {
6765
ty::FnPtr(..) => None,
@@ -86,33 +84,22 @@ impl<'tcx> crate::MirPass<'tcx> for AbortUnwindingCalls {
8684
_ => continue,
8785
};
8886

89-
// If this function call can't unwind, then there's no need for it
90-
// to have a landing pad. This means that we can remove any cleanup
91-
// registered for it.
9287
if !call_can_unwind {
93-
cleanups_to_remove.push(id);
94-
continue;
95-
}
96-
97-
// Otherwise if this function can unwind, then if the outer function
98-
// can also unwind there's nothing to do. If the outer function
99-
// can't unwind, however, we need to change the landing pad for this
100-
// function call to one that aborts.
101-
if !body_can_unwind {
102-
calls_to_terminate.push(id);
88+
// If this function call can't unwind, then there's no need for it
89+
// to have a landing pad. This means that we can remove any cleanup
90+
// registered for it.
91+
let cleanup = block.terminator_mut().unwind_mut().unwrap();
92+
*cleanup = UnwindAction::Unreachable;
93+
} else if !body_can_unwind {
94+
// Otherwise if this function can unwind, then if the outer function
95+
// can also unwind there's nothing to do. If the outer function
96+
// can't unwind, however, we need to change the landing pad for this
97+
// function call to one that aborts.
98+
let cleanup = block.terminator_mut().unwind_mut().unwrap();
99+
*cleanup = UnwindAction::Terminate(UnwindTerminateReason::Abi);
103100
}
104101
}
105102

106-
for id in calls_to_terminate {
107-
let cleanup = body.basic_blocks_mut()[id].terminator_mut().unwind_mut().unwrap();
108-
*cleanup = UnwindAction::Terminate(UnwindTerminateReason::Abi);
109-
}
110-
111-
for id in cleanups_to_remove {
112-
let cleanup = body.basic_blocks_mut()[id].terminator_mut().unwind_mut().unwrap();
113-
*cleanup = UnwindAction::Unreachable;
114-
}
115-
116103
// We may have invalidated some `cleanup` blocks so clean those up now.
117104
super::simplify::remove_dead_blocks(body);
118105
}

compiler/rustc_mir_transform/src/add_call_guards.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use rustc_middle::ty::TyCtxt;
44
use tracing::debug;
55

66
#[derive(PartialEq)]
7-
pub enum AddCallGuards {
7+
pub(super) enum AddCallGuards {
88
AllCallEdges,
99
CriticalCallEdges,
1010
}
11-
pub use self::AddCallGuards::*;
11+
pub(super) use self::AddCallGuards::*;
1212

1313
/**
1414
* Breaks outgoing critical edges for call terminators in the MIR.
@@ -37,7 +37,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
3737
}
3838

3939
impl AddCallGuards {
40-
pub fn add_call_guards(&self, body: &mut Body<'_>) {
40+
pub(super) fn add_call_guards(&self, body: &mut Body<'_>) {
4141
let mut pred_count: IndexVec<_, _> =
4242
body.basic_blocks.predecessors().iter().map(|ps| ps.len()).collect();
4343
pred_count[START_BLOCK] += 1;

compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::util;
3535
///
3636
/// The storage instructions are required to avoid stack space
3737
/// blowup.
38-
pub struct AddMovesForPackedDrops;
38+
pub(super) struct AddMovesForPackedDrops;
3939

4040
impl<'tcx> crate::MirPass<'tcx> for AddMovesForPackedDrops {
4141
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@@ -44,7 +44,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddMovesForPackedDrops {
4444
}
4545
}
4646

47-
pub fn add_moves_for_packed_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
47+
fn add_moves_for_packed_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4848
let patch = add_moves_for_packed_drops_patch(tcx, body);
4949
patch.apply(body);
5050
}

compiler/rustc_mir_transform/src/add_retag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::LangItem;
88
use rustc_middle::mir::*;
99
use rustc_middle::ty::{self, Ty, TyCtxt};
1010

11-
pub struct AddRetag;
11+
pub(super) struct AddRetag;
1212

1313
/// Determine whether this type may contain a reference (or box), and thus needs retagging.
1414
/// We will only recurse `depth` times into Tuples/ADTs to bound the cost of this.

compiler/rustc_mir_transform/src/add_subtyping_projections.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
use rustc_index::IndexVec;
21
use rustc_middle::mir::patch::MirPatch;
32
use rustc_middle::mir::visit::MutVisitor;
43
use rustc_middle::mir::*;
54
use rustc_middle::ty::TyCtxt;
65

7-
pub struct Subtyper;
6+
pub(super) struct Subtyper;
87

9-
pub struct SubTypeChecker<'a, 'tcx> {
8+
struct SubTypeChecker<'a, 'tcx> {
109
tcx: TyCtxt<'tcx>,
1110
patcher: MirPatch<'tcx>,
12-
local_decls: &'a IndexVec<Local, LocalDecl<'tcx>>,
11+
local_decls: &'a LocalDecls<'tcx>,
1312
}
1413

1514
impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
@@ -52,7 +51,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
5251
// // gets transformed to
5352
// let temp: rval_ty = rval;
5453
// let place: place_ty = temp as place_ty;
55-
pub fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
54+
fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
5655
let patch = MirPatch::new(body);
5756
let mut checker = SubTypeChecker { tcx, patcher: patch, local_decls: &body.local_decls };
5857

compiler/rustc_mir_transform/src/check_alignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
77
use rustc_session::Session;
88
use tracing::{debug, trace};
99

10-
pub struct CheckAlignment;
10+
pub(super) struct CheckAlignment;
1111

1212
impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
1313
fn is_enabled(&self, sess: &Session) -> bool {

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::Span;
88

99
use crate::errors;
1010

11-
pub struct CheckConstItemMutation;
11+
pub(super) struct CheckConstItemMutation;
1212

1313
impl<'tcx> crate::MirLint<'tcx> for CheckConstItemMutation {
1414
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {

compiler/rustc_mir_transform/src/check_packed_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::ty::{self, TyCtxt};
55

66
use crate::{errors, util};
77

8-
pub struct CheckPackedRef;
8+
pub(super) struct CheckPackedRef;
99

1010
impl<'tcx> crate::MirLint<'tcx> for CheckPackedRef {
1111
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {

compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::mir::{Body, BorrowKind, CastKind, Rvalue, StatementKind, Termi
2121
use rustc_middle::ty::adjustment::PointerCoercion;
2222
use rustc_middle::ty::TyCtxt;
2323

24-
pub struct CleanupPostBorrowck;
24+
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>) {

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::ssa::SsaLocals;
1717
/// where each of the locals is only assigned once.
1818
///
1919
/// We want to replace all those locals by `_a`, either copied or moved.
20-
pub struct CopyProp;
20+
pub(super) struct CopyProp;
2121

2222
impl<'tcx> crate::MirPass<'tcx> for CopyProp {
2323
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {

0 commit comments

Comments
 (0)