Skip to content

Commit 93aea1d

Browse files
committed
mir: require is_cleanup when creating BasicBlockData
1 parent 15fa788 commit 93aea1d

File tree

7 files changed

+30
-25
lines changed

7 files changed

+30
-25
lines changed

compiler/rustc_middle/src/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1348,8 +1348,8 @@ pub struct BasicBlockData<'tcx> {
13481348
}
13491349

13501350
impl<'tcx> BasicBlockData<'tcx> {
1351-
pub fn new(terminator: Option<Terminator<'tcx>>) -> BasicBlockData<'tcx> {
1352-
BasicBlockData { statements: vec![], terminator, is_cleanup: false }
1351+
pub fn new(terminator: Option<Terminator<'tcx>>, is_cleanup: bool) -> BasicBlockData<'tcx> {
1352+
BasicBlockData { statements: vec![], terminator, is_cleanup }
13531353
}
13541354

13551355
/// Accessor for terminator.

compiler/rustc_mir_build/src/builder/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'tcx> CFG<'tcx> {
1919
// it as #[inline(never)] to keep rustc's stack use in check.
2020
#[inline(never)]
2121
pub(crate) fn start_new_block(&mut self) -> BasicBlock {
22-
self.basic_blocks.push(BasicBlockData::new(None))
22+
self.basic_blocks.push(BasicBlockData::new(None, false))
2323
}
2424

2525
pub(crate) fn start_new_cleanup_block(&mut self) -> BasicBlock {

compiler/rustc_mir_build/src/builder/custom/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(super) fn build_custom_mir<'tcx>(
6464
};
6565

6666
body.local_decls.push(LocalDecl::new(return_ty, return_ty_span));
67-
body.basic_blocks_mut().push(BasicBlockData::new(None));
67+
body.basic_blocks_mut().push(BasicBlockData::new(None, false));
6868
body.source_scopes.push(SourceScopeData {
6969
span,
7070
parent_scope: None,

compiler/rustc_mir_build/src/builder/custom/parse.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
199199
match &self.thir[stmt].kind {
200200
StmtKind::Let { pattern, initializer: Some(initializer), .. } => {
201201
let (var, ..) = self.parse_var(pattern)?;
202-
let mut data = BasicBlockData::new(None);
203-
data.is_cleanup = parse_by_kind!(self, *initializer, _, "basic block declaration",
204-
@variant(mir_basic_block, Normal) => false,
205-
@variant(mir_basic_block, Cleanup) => true,
202+
let data = BasicBlockData::new(
203+
None,
204+
parse_by_kind!(self, *initializer, _, "basic block declaration",
205+
@variant(mir_basic_block, Normal) => false,
206+
@variant(mir_basic_block, Cleanup) => true,
207+
),
206208
);
207209
let block = self.body.basic_blocks_mut().push(data);
208210
self.block_map.insert(var, block);
@@ -308,8 +310,7 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
308310
ExprKind::Block { block } => &self.thir[*block],
309311
);
310312

311-
let mut data = BasicBlockData::new(None);
312-
data.is_cleanup = is_cleanup;
313+
let mut data = BasicBlockData::new(None, is_cleanup);
313314
for stmt_id in &*block.stmts {
314315
let stmt = self.statement_as_expr(*stmt_id)?;
315316
let span = self.thir[stmt].span;

compiler/rustc_mir_transform/src/early_otherwise_branch.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
179179
let eq_targets = SwitchTargets::new(eq_new_targets, parent_targets.otherwise());
180180

181181
// Create `bbEq` in example above
182-
let mut eq_switch = BasicBlockData::new(Some(Terminator {
183-
source_info: bbs[parent].terminator().source_info,
184-
kind: TerminatorKind::SwitchInt {
185-
// switch on the first discriminant, so we can mark the second one as dead
186-
discr: parent_op,
187-
targets: eq_targets,
188-
},
189-
}));
190-
eq_switch.is_cleanup = bbs[parent].is_cleanup;
182+
let eq_switch = BasicBlockData::new(
183+
Some(Terminator {
184+
source_info: bbs[parent].terminator().source_info,
185+
kind: TerminatorKind::SwitchInt {
186+
// switch on the first discriminant, so we can mark the second one as dead
187+
discr: parent_op,
188+
targets: eq_targets,
189+
},
190+
}),
191+
bbs[parent].is_cleanup,
192+
);
191193

192194
let eq_bb = patch.new_block(eq_switch);
193195

compiler/rustc_mir_transform/src/inline.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,13 @@ impl<'tcx> Inliner<'tcx> {
572572
let return_block = if let Some(block) = target {
573573
// Prepare a new block for code that should execute when call returns. We don't use
574574
// target block directly since it might have other predecessors.
575-
let mut data = BasicBlockData::new(Some(Terminator {
576-
source_info: terminator.source_info,
577-
kind: TerminatorKind::Goto { target: block },
578-
}));
579-
data.is_cleanup = caller_body[block].is_cleanup;
575+
let data = BasicBlockData::new(
576+
Some(Terminator {
577+
source_info: terminator.source_info,
578+
kind: TerminatorKind::Goto { target: block },
579+
}),
580+
caller_body[block].is_cleanup,
581+
);
580582
Some(caller_body.basic_blocks_mut().push(data))
581583
} else {
582584
None

compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
9696
typing_env,
9797

9898
stack: Vec::with_capacity(Self::MAX_STACK_LEN),
99-
last_bb: bbs.push(BasicBlockData::new(None)),
99+
last_bb: bbs.push(BasicBlockData::new(None, false)),
100100
top_cleanup_bb: match tcx.sess.panic_strategy() {
101101
PanicStrategy::Unwind => {
102102
// Don't drop input arg because it's just a pointer

0 commit comments

Comments
 (0)