qualify_consts: extract remove_drop_and_storage_dead_on_promoted_locals.
This commit is contained in:
parent
8af33b3253
commit
2f733aad5a
1 changed files with 34 additions and 29 deletions
|
|
@ -1656,35 +1656,7 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
|
|||
Mode::Const => tcx.mir_const_qualif(def_id).1,
|
||||
_ => Checker::new(tcx, def_id, body, mode).check_const().1,
|
||||
};
|
||||
|
||||
// In `const` and `static` everything without `StorageDead`
|
||||
// is `'static`, we don't have to create promoted MIR fragments,
|
||||
// just remove `Drop` and `StorageDead` on "promoted" locals.
|
||||
debug!("run_pass: promoted_temps={:?}", promoted_temps);
|
||||
for block in body.basic_blocks_mut() {
|
||||
block.statements.retain(|statement| {
|
||||
match statement.kind {
|
||||
StatementKind::StorageDead(index) => {
|
||||
!promoted_temps.contains(index)
|
||||
}
|
||||
_ => true
|
||||
}
|
||||
});
|
||||
let terminator = block.terminator_mut();
|
||||
match terminator.kind {
|
||||
TerminatorKind::Drop {
|
||||
location: Place {
|
||||
base: PlaceBase::Local(index),
|
||||
projection: None,
|
||||
},
|
||||
target,
|
||||
..
|
||||
} if promoted_temps.contains(index) => {
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
remove_drop_and_storage_dead_on_promoted_locals(body, promoted_temps);
|
||||
}
|
||||
|
||||
if let Mode::Static = mode {
|
||||
|
|
@ -1738,6 +1710,39 @@ fn check_short_circuiting_in_const_local(tcx: TyCtxt<'_>, body: &mut Body<'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
/// In `const` and `static` everything without `StorageDead`
|
||||
/// is `'static`, we don't have to create promoted MIR fragments,
|
||||
/// just remove `Drop` and `StorageDead` on "promoted" locals.
|
||||
fn remove_drop_and_storage_dead_on_promoted_locals(
|
||||
body: &mut Body<'tcx>,
|
||||
promoted_temps: &BitSet<Local>,
|
||||
) {
|
||||
debug!("run_pass: promoted_temps={:?}", promoted_temps);
|
||||
|
||||
for block in body.basic_blocks_mut() {
|
||||
block.statements.retain(|statement| {
|
||||
match statement.kind {
|
||||
StatementKind::StorageDead(index) => !promoted_temps.contains(index),
|
||||
_ => true
|
||||
}
|
||||
});
|
||||
let terminator = block.terminator_mut();
|
||||
match terminator.kind {
|
||||
TerminatorKind::Drop {
|
||||
location: Place {
|
||||
base: PlaceBase::Local(index),
|
||||
projection: None,
|
||||
},
|
||||
target,
|
||||
..
|
||||
} if promoted_temps.contains(index) => {
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_non_thread_local_static_is_sync(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &mut Body<'tcx>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue