Skip to content

Commit

Permalink
Unrolled build for rust-lang#130786
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#130786 - DianQK:early_otherwise_branch_cleanup, r=oli-obk

 mir-opt: a sub-BB of a cleanup BB must also be a cleanup BB in `EarlyOtherwiseBranch`

Fixes rust-lang#130769.

r? `@cjgillot` or mir-opt
  • Loading branch information
rust-timer authored Dec 18, 2024
2 parents 057bdb3 + d08738c commit 525aeb9
Show file tree
Hide file tree
Showing 14 changed files with 739 additions and 109 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,8 +1348,8 @@ pub struct BasicBlockData<'tcx> {
}

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

/// Accessor for terminator.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/builder/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<'tcx> CFG<'tcx> {
// it as #[inline(never)] to keep rustc's stack use in check.
#[inline(never)]
pub(crate) fn start_new_block(&mut self) -> BasicBlock {
self.basic_blocks.push(BasicBlockData::new(None))
self.basic_blocks.push(BasicBlockData::new(None, false))
}

pub(crate) fn start_new_cleanup_block(&mut self) -> BasicBlock {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/builder/custom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(super) fn build_custom_mir<'tcx>(
};

body.local_decls.push(LocalDecl::new(return_ty, return_ty_span));
body.basic_blocks_mut().push(BasicBlockData::new(None));
body.basic_blocks_mut().push(BasicBlockData::new(None, false));
body.source_scopes.push(SourceScopeData {
span,
parent_scope: None,
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_mir_build/src/builder/custom/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
match &self.thir[stmt].kind {
StmtKind::Let { pattern, initializer: Some(initializer), .. } => {
let (var, ..) = self.parse_var(pattern)?;
let mut data = BasicBlockData::new(None);
data.is_cleanup = parse_by_kind!(self, *initializer, _, "basic block declaration",
@variant(mir_basic_block, Normal) => false,
@variant(mir_basic_block, Cleanup) => true,
let data = BasicBlockData::new(
None,
parse_by_kind!(self, *initializer, _, "basic block declaration",
@variant(mir_basic_block, Normal) => false,
@variant(mir_basic_block, Cleanup) => true,
),
);
let block = self.body.basic_blocks_mut().push(data);
self.block_map.insert(var, block);
Expand Down Expand Up @@ -308,8 +310,7 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
ExprKind::Block { block } => &self.thir[*block],
);

let mut data = BasicBlockData::new(None);
data.is_cleanup = is_cleanup;
let mut data = BasicBlockData::new(None, is_cleanup);
for stmt_id in &*block.stmts {
let stmt = self.statement_as_expr(*stmt_id)?;
let span = self.thir[stmt].span;
Expand Down
Loading

0 comments on commit 525aeb9

Please sign in to comment.