2023-05-06 14:13:12 +00:00
|
|
|
use rustc_index::bit_set::BitSet;
|
2020-06-08 14:50:39 -07:00
|
|
|
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::mir::*;
|
2023-05-06 14:13:12 +00:00
|
|
|
|
2022-12-13 04:22:47 -08:00
|
|
|
use std::borrow::Cow;
|
2017-09-10 22:34:56 +02:00
|
|
|
|
2023-05-06 14:13:12 +00:00
|
|
|
use super::MaybeBorrowedLocals;
|
2023-11-24 11:14:00 +11:00
|
|
|
use crate::{GenKill, ResultsCursor};
|
2023-05-06 14:13:12 +00:00
|
|
|
|
2020-03-29 14:16:29 -07:00
|
|
|
#[derive(Clone)]
|
2022-12-13 04:22:47 -08:00
|
|
|
pub struct MaybeStorageLive<'a> {
|
|
|
|
|
always_live_locals: Cow<'a, BitSet<Local>>,
|
2020-03-29 14:16:29 -07:00
|
|
|
}
|
|
|
|
|
|
2022-12-13 04:22:47 -08:00
|
|
|
impl<'a> MaybeStorageLive<'a> {
|
|
|
|
|
pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
|
2020-03-29 14:16:29 -07:00
|
|
|
MaybeStorageLive { always_live_locals }
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-10 22:34:56 +02:00
|
|
|
|
2022-12-13 04:22:47 -08:00
|
|
|
impl<'tcx, 'a> crate::AnalysisDomain<'tcx> for MaybeStorageLive<'a> {
|
2020-08-28 13:26:25 -07:00
|
|
|
type Domain = BitSet<Local>;
|
2017-09-10 22:34:56 +02:00
|
|
|
|
2020-02-18 10:03:00 -08:00
|
|
|
const NAME: &'static str = "maybe_storage_live";
|
2017-09-10 22:34:56 +02:00
|
|
|
|
2023-05-06 14:13:12 +00:00
|
|
|
fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain {
|
2020-08-28 13:26:25 -07:00
|
|
|
// bottom = dead
|
|
|
|
|
BitSet::new_empty(body.local_decls.len())
|
2017-09-10 22:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-06 14:13:12 +00:00
|
|
|
fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain) {
|
2020-03-29 14:16:29 -07:00
|
|
|
assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size());
|
|
|
|
|
for local in self.always_live_locals.iter() {
|
|
|
|
|
on_entry.insert(local);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for arg in body.args_iter() {
|
2020-01-25 20:03:10 +01:00
|
|
|
on_entry.insert(arg);
|
|
|
|
|
}
|
2017-09-10 22:34:56 +02:00
|
|
|
}
|
2020-02-18 10:03:00 -08:00
|
|
|
}
|
2017-09-10 22:34:56 +02:00
|
|
|
|
2022-12-13 04:22:47 -08:00
|
|
|
impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> {
|
2020-08-28 13:26:25 -07:00
|
|
|
type Idx = Local;
|
|
|
|
|
|
2023-05-06 22:00:24 +00:00
|
|
|
fn domain_size(&self, body: &Body<'tcx>) -> usize {
|
|
|
|
|
body.local_decls.len()
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 10:03:00 -08:00
|
|
|
fn statement_effect(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2020-02-18 10:03:00 -08:00
|
|
|
trans: &mut impl GenKill<Self::Idx>,
|
2023-05-06 14:13:12 +00:00
|
|
|
stmt: &Statement<'tcx>,
|
2020-02-18 10:03:00 -08:00
|
|
|
_: Location,
|
|
|
|
|
) {
|
2017-09-10 22:34:56 +02:00
|
|
|
match stmt.kind {
|
2024-07-14 13:50:27 -04:00
|
|
|
StatementKind::StorageLive(l) => trans.gen_(l),
|
rustc_mir: don't pass `on_entry` when building transfer functions.
This commit makes `sets.on_entry` inaccessible in
`{before_,}{statement,terminator}_effect`. This field was meant to allow
implementors of `BitDenotation` to access the initial state for each
block (optionally with the effect of all previous statements applied via
`accumulates_intrablock_state`) while defining transfer functions.
However, the ability to set the initial value for the entry set of each
basic block (except for START_BLOCK) no longer exists. As a result, this
functionality is mostly useless, and when it *was* used it was used
erroneously (see #62007).
Since `on_entry` is now useless, we can also remove `BlockSets`, which
held the `gen`, `kill`, and `on_entry` bitvectors and replace it with a
`GenKill` struct. Variables of this type are called `trans` since they
represent a transfer function. `GenKill`s are stored contiguously in
`AllSets`, which reduces the number of bounds checks and may improve
cache performance: one is almost never accessed without the other.
Replacing `BlockSets` with `GenKill` allows us to define some new helper
functions which streamline dataflow iteration and the
dataflow-at-location APIs. Notably, `state_for_location` used a subtle
side-effect of the `kill`/`kill_all` setters to apply the transfer
function, and could be incorrect if a transfer function depended on
effects of previous statements in the block on `gen_set`.
2019-06-12 15:00:43 -07:00
|
|
|
StatementKind::StorageDead(l) => trans.kill(l),
|
2017-09-10 22:34:56 +02:00
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-07 10:20:43 +00:00
|
|
|
fn terminator_effect<'mir>(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2023-05-07 10:20:43 +00:00
|
|
|
_trans: &mut Self::Domain,
|
|
|
|
|
terminator: &'mir Terminator<'tcx>,
|
2020-02-18 10:03:00 -08:00
|
|
|
_: Location,
|
2023-05-27 16:27:04 +00:00
|
|
|
) -> TerminatorEdges<'mir, 'tcx> {
|
2019-05-30 13:28:31 -07:00
|
|
|
// Terminators have no effect
|
2023-05-07 10:20:43 +00:00
|
|
|
terminator.edges()
|
2017-09-10 22:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-18 10:03:00 -08:00
|
|
|
fn call_return_effect(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2023-12-08 09:35:57 +11:00
|
|
|
_trans: &mut Self::Domain,
|
2020-02-18 10:03:00 -08:00
|
|
|
_block: BasicBlock,
|
2021-08-30 01:23:33 +01:00
|
|
|
_return_places: CallReturnPlaces<'_, 'tcx>,
|
2018-12-17 17:26:24 +01:00
|
|
|
) {
|
2017-09-10 22:34:56 +02:00
|
|
|
// Nothing to do when a call returns successfully
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:26:09 +00:00
|
|
|
#[derive(Clone)]
|
2023-12-16 00:00:00 +00:00
|
|
|
pub struct MaybeStorageDead<'a> {
|
|
|
|
|
always_live_locals: Cow<'a, BitSet<Local>>,
|
2022-12-04 18:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-16 00:00:00 +00:00
|
|
|
impl<'a> MaybeStorageDead<'a> {
|
|
|
|
|
pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
|
2022-12-04 18:26:09 +00:00
|
|
|
MaybeStorageDead { always_live_locals }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-16 00:00:00 +00:00
|
|
|
impl<'tcx, 'a> crate::AnalysisDomain<'tcx> for MaybeStorageDead<'a> {
|
2022-12-04 18:26:09 +00:00
|
|
|
type Domain = BitSet<Local>;
|
|
|
|
|
|
|
|
|
|
const NAME: &'static str = "maybe_storage_dead";
|
|
|
|
|
|
2023-05-06 14:13:12 +00:00
|
|
|
fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain {
|
2022-12-04 18:26:09 +00:00
|
|
|
// bottom = live
|
|
|
|
|
BitSet::new_empty(body.local_decls.len())
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-06 14:13:12 +00:00
|
|
|
fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain) {
|
2022-12-04 18:26:09 +00:00
|
|
|
assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size());
|
2023-04-26 18:40:10 +00:00
|
|
|
// Do not iterate on return place and args, as they are trivially always live.
|
2022-12-04 18:26:09 +00:00
|
|
|
for local in body.vars_and_temps_iter() {
|
|
|
|
|
if !self.always_live_locals.contains(local) {
|
|
|
|
|
on_entry.insert(local);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-16 00:00:00 +00:00
|
|
|
impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageDead<'a> {
|
2022-12-04 18:26:09 +00:00
|
|
|
type Idx = Local;
|
|
|
|
|
|
2023-05-06 22:00:24 +00:00
|
|
|
fn domain_size(&self, body: &Body<'tcx>) -> usize {
|
|
|
|
|
body.local_decls.len()
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:26:09 +00:00
|
|
|
fn statement_effect(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2022-12-04 18:26:09 +00:00
|
|
|
trans: &mut impl GenKill<Self::Idx>,
|
2023-05-06 14:13:12 +00:00
|
|
|
stmt: &Statement<'tcx>,
|
2022-12-04 18:26:09 +00:00
|
|
|
_: Location,
|
|
|
|
|
) {
|
|
|
|
|
match stmt.kind {
|
|
|
|
|
StatementKind::StorageLive(l) => trans.kill(l),
|
2024-07-14 13:50:27 -04:00
|
|
|
StatementKind::StorageDead(l) => trans.gen_(l),
|
2022-12-04 18:26:09 +00:00
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-07 10:20:43 +00:00
|
|
|
fn terminator_effect<'mir>(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2023-05-07 10:20:43 +00:00
|
|
|
_: &mut Self::Domain,
|
|
|
|
|
terminator: &'mir Terminator<'tcx>,
|
2022-12-04 18:26:09 +00:00
|
|
|
_: Location,
|
2023-05-27 16:27:04 +00:00
|
|
|
) -> TerminatorEdges<'mir, 'tcx> {
|
2022-12-04 18:26:09 +00:00
|
|
|
// Terminators have no effect
|
2023-05-07 10:20:43 +00:00
|
|
|
terminator.edges()
|
2022-12-04 18:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn call_return_effect(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2023-12-08 09:35:57 +11:00
|
|
|
_trans: &mut Self::Domain,
|
2022-12-04 18:26:09 +00:00
|
|
|
_block: BasicBlock,
|
|
|
|
|
_return_places: CallReturnPlaces<'_, 'tcx>,
|
|
|
|
|
) {
|
|
|
|
|
// Nothing to do when a call returns successfully
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 11:14:00 +11:00
|
|
|
type BorrowedLocalsResults<'mir, 'tcx> = ResultsCursor<'mir, 'tcx, MaybeBorrowedLocals>;
|
2020-06-08 14:50:39 -07:00
|
|
|
|
|
|
|
|
/// Dataflow analysis that determines whether each local requires storage at a
|
|
|
|
|
/// given location; i.e. whether its storage can go away without being observed.
|
2023-11-24 11:14:00 +11:00
|
|
|
pub struct MaybeRequiresStorage<'mir, 'tcx> {
|
|
|
|
|
borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>,
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-24 11:14:00 +11:00
|
|
|
impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> {
|
|
|
|
|
pub fn new(borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>) -> Self {
|
2023-02-20 17:28:03 -05:00
|
|
|
MaybeRequiresStorage { borrowed_locals }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 11:14:00 +11:00
|
|
|
impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
|
2020-08-28 13:26:25 -07:00
|
|
|
type Domain = BitSet<Local>;
|
2020-06-08 14:50:39 -07:00
|
|
|
|
|
|
|
|
const NAME: &'static str = "requires_storage";
|
|
|
|
|
|
2023-05-06 14:13:12 +00:00
|
|
|
fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain {
|
2020-08-28 13:26:25 -07:00
|
|
|
// bottom = dead
|
|
|
|
|
BitSet::new_empty(body.local_decls.len())
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-06 14:13:12 +00:00
|
|
|
fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain) {
|
2020-06-08 14:50:39 -07:00
|
|
|
// The resume argument is live on function entry (we don't care about
|
|
|
|
|
// the `self` argument)
|
|
|
|
|
for arg in body.args_iter().skip(1) {
|
|
|
|
|
on_entry.insert(arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 11:14:00 +11:00
|
|
|
impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
|
2020-08-28 13:26:25 -07:00
|
|
|
type Idx = Local;
|
|
|
|
|
|
2023-05-06 22:00:24 +00:00
|
|
|
fn domain_size(&self, body: &Body<'tcx>) -> usize {
|
|
|
|
|
body.local_decls.len()
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 14:50:39 -07:00
|
|
|
fn before_statement_effect(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2020-06-08 14:50:39 -07:00
|
|
|
trans: &mut impl GenKill<Self::Idx>,
|
2023-05-06 14:13:12 +00:00
|
|
|
stmt: &Statement<'tcx>,
|
2020-06-08 14:50:39 -07:00
|
|
|
loc: Location,
|
|
|
|
|
) {
|
|
|
|
|
// If a place is borrowed in a statement, it needs storage for that statement.
|
2023-02-20 17:28:03 -05:00
|
|
|
self.borrowed_locals.mut_analysis().statement_effect(trans, stmt, loc);
|
2020-06-08 14:50:39 -07:00
|
|
|
|
|
|
|
|
match &stmt.kind {
|
|
|
|
|
StatementKind::StorageDead(l) => trans.kill(*l),
|
|
|
|
|
|
|
|
|
|
// If a place is assigned to in a statement, it needs storage for that statement.
|
|
|
|
|
StatementKind::Assign(box (place, _))
|
2022-04-05 17:14:59 -04:00
|
|
|
| StatementKind::SetDiscriminant { box place, .. }
|
|
|
|
|
| StatementKind::Deinit(box place) => {
|
2024-07-14 13:50:27 -04:00
|
|
|
trans.gen_(place.local);
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Nothing to do for these. Match exhaustively so this fails to compile when new
|
|
|
|
|
// variants are added.
|
|
|
|
|
StatementKind::AscribeUserType(..)
|
2022-09-06 18:41:01 +02:00
|
|
|
| StatementKind::PlaceMention(..)
|
2020-08-15 04:42:13 -07:00
|
|
|
| StatementKind::Coverage(..)
|
2020-06-08 14:50:39 -07:00
|
|
|
| StatementKind::FakeRead(..)
|
2022-12-20 00:51:17 +00:00
|
|
|
| StatementKind::ConstEvalCounter
|
2020-06-08 14:50:39 -07:00
|
|
|
| StatementKind::Nop
|
|
|
|
|
| StatementKind::Retag(..)
|
2022-07-12 10:05:00 +00:00
|
|
|
| StatementKind::Intrinsic(..)
|
2020-06-08 14:50:39 -07:00
|
|
|
| StatementKind::StorageLive(..) => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn statement_effect(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2020-06-08 14:50:39 -07:00
|
|
|
trans: &mut impl GenKill<Self::Idx>,
|
2023-05-06 14:13:12 +00:00
|
|
|
_: &Statement<'tcx>,
|
2020-06-08 14:50:39 -07:00
|
|
|
loc: Location,
|
|
|
|
|
) {
|
2022-07-06 13:26:26 -05:00
|
|
|
// If we move from a place then it only stops needing storage *after*
|
2020-06-08 14:50:39 -07:00
|
|
|
// that statement.
|
|
|
|
|
self.check_for_move(trans, loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn before_terminator_effect(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2023-12-08 09:35:57 +11:00
|
|
|
trans: &mut Self::Domain,
|
2023-05-06 14:13:12 +00:00
|
|
|
terminator: &Terminator<'tcx>,
|
2020-06-08 14:50:39 -07:00
|
|
|
loc: Location,
|
|
|
|
|
) {
|
|
|
|
|
// If a place is borrowed in a terminator, it needs storage for that terminator.
|
2023-05-07 10:20:43 +00:00
|
|
|
self.borrowed_locals
|
|
|
|
|
.mut_analysis()
|
|
|
|
|
.transfer_function(trans)
|
|
|
|
|
.visit_terminator(terminator, loc);
|
2020-06-08 14:50:39 -07:00
|
|
|
|
|
|
|
|
match &terminator.kind {
|
2022-04-16 09:27:54 -04:00
|
|
|
TerminatorKind::Call { destination, .. } => {
|
2024-07-14 13:50:27 -04:00
|
|
|
trans.gen_(destination.local);
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Note that we do *not* gen the `resume_arg` of `Yield` terminators. The reason for
|
|
|
|
|
// that is that a `yield` will return from the function, and `resume_arg` is written
|
2023-10-19 21:46:28 +00:00
|
|
|
// only when the coroutine is later resumed. Unlike `Call`, this doesn't require the
|
2020-06-08 14:50:39 -07:00
|
|
|
// place to have storage *before* the yield, only after.
|
|
|
|
|
TerminatorKind::Yield { .. } => {}
|
|
|
|
|
|
|
|
|
|
TerminatorKind::InlineAsm { operands, .. } => {
|
|
|
|
|
for op in operands {
|
|
|
|
|
match op {
|
|
|
|
|
InlineAsmOperand::Out { place, .. }
|
|
|
|
|
| InlineAsmOperand::InOut { out_place: place, .. } => {
|
|
|
|
|
if let Some(place) = place {
|
2024-07-14 13:50:27 -04:00
|
|
|
trans.gen_(place.local);
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
InlineAsmOperand::In { .. }
|
|
|
|
|
| InlineAsmOperand::Const { .. }
|
|
|
|
|
| InlineAsmOperand::SymFn { .. }
|
2023-12-26 16:07:35 +00:00
|
|
|
| InlineAsmOperand::SymStatic { .. }
|
|
|
|
|
| InlineAsmOperand::Label { .. } => {}
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Nothing to do for these. Match exhaustively so this fails to compile when new
|
|
|
|
|
// variants are added.
|
2023-08-21 09:57:10 +02:00
|
|
|
TerminatorKind::UnwindTerminate(_)
|
2020-06-08 14:50:39 -07:00
|
|
|
| TerminatorKind::Assert { .. }
|
|
|
|
|
| TerminatorKind::Drop { .. }
|
|
|
|
|
| TerminatorKind::FalseEdge { .. }
|
|
|
|
|
| TerminatorKind::FalseUnwind { .. }
|
2023-10-19 16:06:43 +00:00
|
|
|
| TerminatorKind::CoroutineDrop
|
2020-06-08 14:50:39 -07:00
|
|
|
| TerminatorKind::Goto { .. }
|
2023-08-19 13:10:25 +02:00
|
|
|
| TerminatorKind::UnwindResume
|
2020-06-08 14:50:39 -07:00
|
|
|
| TerminatorKind::Return
|
2024-02-15 19:54:37 +00:00
|
|
|
| TerminatorKind::TailCall { .. }
|
2020-06-08 14:50:39 -07:00
|
|
|
| TerminatorKind::SwitchInt { .. }
|
|
|
|
|
| TerminatorKind::Unreachable => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-07 10:20:43 +00:00
|
|
|
fn terminator_effect<'t>(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2023-05-07 10:20:43 +00:00
|
|
|
trans: &mut Self::Domain,
|
|
|
|
|
terminator: &'t Terminator<'tcx>,
|
2020-06-08 14:50:39 -07:00
|
|
|
loc: Location,
|
2023-05-27 16:27:04 +00:00
|
|
|
) -> TerminatorEdges<'t, 'tcx> {
|
2021-08-30 01:23:33 +01:00
|
|
|
match terminator.kind {
|
2020-06-08 14:50:39 -07:00
|
|
|
// For call terminators the destination requires storage for the call
|
|
|
|
|
// and after the call returns successfully, but not after a panic.
|
|
|
|
|
// Since `propagate_call_unwind` doesn't exist, we have to kill the
|
|
|
|
|
// destination here, and then gen it again in `call_return_effect`.
|
2022-04-16 09:27:54 -04:00
|
|
|
TerminatorKind::Call { destination, .. } => {
|
|
|
|
|
trans.kill(destination.local);
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-30 01:23:33 +01:00
|
|
|
// The same applies to InlineAsm outputs.
|
|
|
|
|
TerminatorKind::InlineAsm { ref operands, .. } => {
|
|
|
|
|
CallReturnPlaces::InlineAsm(operands).for_each(|place| trans.kill(place.local));
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 14:50:39 -07:00
|
|
|
// Nothing to do for these. Match exhaustively so this fails to compile when new
|
|
|
|
|
// variants are added.
|
2022-04-16 09:27:54 -04:00
|
|
|
TerminatorKind::Yield { .. }
|
2023-08-21 09:57:10 +02:00
|
|
|
| TerminatorKind::UnwindTerminate(_)
|
2020-06-08 14:50:39 -07:00
|
|
|
| TerminatorKind::Assert { .. }
|
|
|
|
|
| TerminatorKind::Drop { .. }
|
|
|
|
|
| TerminatorKind::FalseEdge { .. }
|
|
|
|
|
| TerminatorKind::FalseUnwind { .. }
|
2023-10-19 16:06:43 +00:00
|
|
|
| TerminatorKind::CoroutineDrop
|
2020-06-08 14:50:39 -07:00
|
|
|
| TerminatorKind::Goto { .. }
|
2023-08-19 13:10:25 +02:00
|
|
|
| TerminatorKind::UnwindResume
|
2020-06-08 14:50:39 -07:00
|
|
|
| TerminatorKind::Return
|
2024-02-15 19:54:37 +00:00
|
|
|
| TerminatorKind::TailCall { .. }
|
2020-06-08 14:50:39 -07:00
|
|
|
| TerminatorKind::SwitchInt { .. }
|
|
|
|
|
| TerminatorKind::Unreachable => {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.check_for_move(trans, loc);
|
2023-05-07 10:20:43 +00:00
|
|
|
terminator.edges()
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn call_return_effect(
|
2023-02-20 17:28:03 -05:00
|
|
|
&mut self,
|
2023-12-08 09:35:57 +11:00
|
|
|
trans: &mut Self::Domain,
|
2020-06-08 14:50:39 -07:00
|
|
|
_block: BasicBlock,
|
2021-08-30 01:23:33 +01:00
|
|
|
return_places: CallReturnPlaces<'_, 'tcx>,
|
2020-06-08 14:50:39 -07:00
|
|
|
) {
|
2024-07-14 13:50:27 -04:00
|
|
|
return_places.for_each(|place| trans.gen_(place.local));
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 11:14:00 +11:00
|
|
|
impl<'tcx> MaybeRequiresStorage<'_, 'tcx> {
|
2020-06-08 14:50:39 -07:00
|
|
|
/// Kill locals that are fully moved and have not been borrowed.
|
2023-02-20 17:28:03 -05:00
|
|
|
fn check_for_move(&mut self, trans: &mut impl GenKill<Local>, loc: Location) {
|
|
|
|
|
let body = self.borrowed_locals.body();
|
|
|
|
|
let mut visitor = MoveVisitor { trans, borrowed_locals: &mut self.borrowed_locals };
|
|
|
|
|
visitor.visit_location(body, loc);
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 11:14:00 +11:00
|
|
|
struct MoveVisitor<'a, 'mir, 'tcx, T> {
|
|
|
|
|
borrowed_locals: &'a mut BorrowedLocalsResults<'mir, 'tcx>,
|
2020-06-08 14:50:39 -07:00
|
|
|
trans: &'a mut T,
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 11:14:00 +11:00
|
|
|
impl<'tcx, T> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx, T>
|
2020-06-08 14:50:39 -07:00
|
|
|
where
|
|
|
|
|
T: GenKill<Local>,
|
|
|
|
|
{
|
2022-07-01 16:21:21 +02:00
|
|
|
fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) {
|
2020-06-08 14:50:39 -07:00
|
|
|
if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context {
|
2023-02-20 17:28:03 -05:00
|
|
|
self.borrowed_locals.seek_before_primary_effect(loc);
|
|
|
|
|
if !self.borrowed_locals.contains(local) {
|
2022-07-01 16:21:21 +02:00
|
|
|
self.trans.kill(local);
|
2020-06-08 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|