Skip to content

Commit 2237f02

Browse files
committed
mir: require is_cleanup when creating BasicBlockData
1 parent 5874663 commit 2237f02

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
@@ -1337,8 +1337,8 @@ pub struct BasicBlockData<'tcx> {
13371337
}
13381338

13391339
impl<'tcx> BasicBlockData<'tcx> {
1340-
pub fn new(terminator: Option<Terminator<'tcx>>) -> BasicBlockData<'tcx> {
1341-
BasicBlockData { statements: vec![], terminator, is_cleanup: false }
1340+
pub fn new(terminator: Option<Terminator<'tcx>>, is_cleanup: bool) -> BasicBlockData<'tcx> {
1341+
BasicBlockData { statements: vec![], terminator, is_cleanup }
13421342
}
13431343

13441344
/// Accessor for terminator.

compiler/rustc_mir_build/src/build/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/build/custom/mod.rs

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

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

compiler/rustc_mir_build/src/build/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
@@ -183,15 +183,17 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
183183
let eq_targets = SwitchTargets::new(eq_new_targets, parent_targets.otherwise());
184184

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

196198
let eq_bb = patch.new_block(eq_switch);
197199

compiler/rustc_mir_transform/src/inline.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,13 @@ impl<'tcx> Inliner<'tcx> {
595595
let return_block = if let Some(block) = target {
596596
// Prepare a new block for code that should execute when call returns. We don't use
597597
// target block directly since it might have other predecessors.
598-
let mut data = BasicBlockData::new(Some(Terminator {
599-
source_info: terminator.source_info,
600-
kind: TerminatorKind::Goto { target: block },
601-
}));
602-
data.is_cleanup = caller_body[block].is_cleanup;
598+
let data = BasicBlockData::new(
599+
Some(Terminator {
600+
source_info: terminator.source_info,
601+
kind: TerminatorKind::Goto { target: block },
602+
}),
603+
caller_body[block].is_cleanup,
604+
);
603605
Some(caller_body.basic_blocks_mut().push(data))
604606
} else {
605607
None

compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
9595
param_env,
9696

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

0 commit comments

Comments
 (0)