Remove GenKillAnalysis.

It's now functionally identical to `Analysis`.
This commit is contained in:
Nicholas Nethercote 2024-10-10 09:49:33 +11:00
parent 525f655866
commit 4dc1b4d0b1
7 changed files with 82 additions and 266 deletions

View File

@ -513,14 +513,8 @@ fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) {
/// region stops containing the CFG points reachable from the issuing location. /// region stops containing the CFG points reachable from the issuing location.
/// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of /// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
/// `a.b.c` when `a` is overwritten. /// `a.b.c` when `a` is overwritten.
impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> { impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
type Idx = BorrowIndex; fn apply_before_statement_effect(
fn domain_size(&self, _: &mir::Body<'tcx>) -> usize {
self.borrow_set.len()
}
fn before_statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_statement: &mir::Statement<'tcx>, _statement: &mir::Statement<'tcx>,
@ -529,7 +523,7 @@ fn before_statement_effect(
self.kill_loans_out_of_scope_at_location(trans, location); self.kill_loans_out_of_scope_at_location(trans, location);
} }
fn statement_effect( fn apply_statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
stmt: &mir::Statement<'tcx>, stmt: &mir::Statement<'tcx>,
@ -577,7 +571,7 @@ fn statement_effect(
} }
} }
fn before_terminator_effect( fn apply_before_terminator_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_terminator: &mir::Terminator<'tcx>, _terminator: &mir::Terminator<'tcx>,
@ -586,7 +580,7 @@ fn before_terminator_effect(
self.kill_loans_out_of_scope_at_location(trans, location); self.kill_loans_out_of_scope_at_location(trans, location);
} }
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>, terminator: &'mir mir::Terminator<'tcx>,
@ -604,7 +598,7 @@ fn terminator_effect<'mir>(
terminator.edges() terminator.edges()
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
_trans: &mut Self::Domain, _trans: &mut Self::Domain,
_block: mir::BasicBlock, _block: mir::BasicBlock,

View File

@ -1,9 +1,11 @@
//! A framework that can express both [gen-kill] and generic dataflow problems. //! A framework that can express both [gen-kill] and generic dataflow problems.
//! //!
//! To use this framework, implement either the [`Analysis`] or the //! To use this framework, implement the [`Analysis`] trait. There used to be a `GenKillAnalysis`
//! [`GenKillAnalysis`] trait. If your transfer function can be expressed with only gen/kill //! alternative trait for gen-kill analyses that would pre-compute the transfer function for each
//! operations, prefer `GenKillAnalysis` since it will run faster while iterating to fixpoint. The //! block. It was intended as an optimization, but it ended up not being any faster than
//! `impls` module contains several examples of gen/kill dataflow analyses. //! `Analysis`.
//!
//! The `impls` module contains several examples of dataflow analyses.
//! //!
//! Create an `Engine` for your analysis using the `into_engine` method on the `Analysis` trait, //! Create an `Engine` for your analysis using the `into_engine` method on the `Analysis` trait,
//! then call `iterate_to_fixpoint`. From there, you can use a `ResultsCursor` to inspect the //! then call `iterate_to_fixpoint`. From there, you can use a `ResultsCursor` to inspect the
@ -122,9 +124,9 @@ pub trait AnalysisDomain<'tcx> {
/// ///
/// # Convergence /// # Convergence
/// ///
/// When implementing this trait directly (not via [`GenKillAnalysis`]), it's possible to choose a /// When implementing this trait it's possible to choose a transfer function such that the analysis
/// transfer function such that the analysis does not reach fixpoint. To guarantee convergence, /// does not reach fixpoint. To guarantee convergence, your transfer functions must maintain the
/// your transfer functions must maintain the following invariant: /// following invariant:
/// ///
/// > If the dataflow state **before** some point in the program changes to be greater /// > If the dataflow state **before** some point in the program changes to be greater
/// than the prior state **before** that point, the dataflow state **after** that point must /// than the prior state **before** that point, the dataflow state **after** that point must
@ -223,9 +225,7 @@ fn apply_switch_int_edge_effects(
/// Creates an `Engine` to find the fixpoint for this dataflow problem. /// Creates an `Engine` to find the fixpoint for this dataflow problem.
/// ///
/// You shouldn't need to override this outside this module, since the combination of the /// You shouldn't need to override this. Its purpose is to enable method chaining like so:
/// default impl and the one for all `A: GenKillAnalysis` will do the right thing.
/// Its purpose is to enable method chaining like so:
/// ///
/// ```ignore (cross-crate-imports) /// ```ignore (cross-crate-imports)
/// let results = MyAnalysis::new(tcx, body) /// let results = MyAnalysis::new(tcx, body)
@ -246,146 +246,7 @@ fn into_engine<'mir>(
} }
} }
/// A gen/kill dataflow problem.
///
/// Each method in this trait has a corresponding one in `Analysis`. However, the first two methods
/// here only allow modification of the dataflow state via "gen" and "kill" operations. By defining
/// transfer functions for each statement in this way, the transfer function for an entire basic
/// block can be computed efficiently. The remaining methods match up with `Analysis` exactly.
///
/// `Analysis` is automatically implemented for all implementers of `GenKillAnalysis` via a blanket
/// impl below.
pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
type Idx: Idx;
fn domain_size(&self, body: &mir::Body<'tcx>) -> usize;
/// See `Analysis::apply_statement_effect`.
fn statement_effect(
&mut self,
trans: &mut Self::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
);
/// See `Analysis::apply_before_statement_effect`.
fn before_statement_effect(
&mut self,
_trans: &mut Self::Domain,
_statement: &mir::Statement<'tcx>,
_location: Location,
) {
}
/// See `Analysis::apply_terminator_effect`.
fn terminator_effect<'mir>(
&mut self,
trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdges<'mir, 'tcx>;
/// See `Analysis::apply_before_terminator_effect`.
fn before_terminator_effect(
&mut self,
_trans: &mut Self::Domain,
_terminator: &mir::Terminator<'tcx>,
_location: Location,
) {
}
/* Edge-specific effects */
/// See `Analysis::apply_call_return_effect`.
fn call_return_effect(
&mut self,
trans: &mut Self::Domain,
block: BasicBlock,
return_places: CallReturnPlaces<'_, 'tcx>,
);
/// See `Analysis::apply_switch_int_edge_effects`.
fn switch_int_edge_effects(
&mut self,
_block: BasicBlock,
_discr: &mir::Operand<'tcx>,
_edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,
) {
}
}
// Blanket impl: any impl of `GenKillAnalysis` automatically impls `Analysis`.
impl<'tcx, A> Analysis<'tcx> for A
where
A: GenKillAnalysis<'tcx>,
A::Domain: GenKill<A::Idx> + BitSetExt<A::Idx>,
{
fn apply_statement_effect(
&mut self,
state: &mut A::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
) {
self.statement_effect(state, statement, location);
}
fn apply_before_statement_effect(
&mut self,
state: &mut A::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
) {
self.before_statement_effect(state, statement, location);
}
fn apply_terminator_effect<'mir>(
&mut self,
state: &mut A::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdges<'mir, 'tcx> {
self.terminator_effect(state, terminator, location)
}
fn apply_before_terminator_effect(
&mut self,
state: &mut A::Domain,
terminator: &mir::Terminator<'tcx>,
location: Location,
) {
self.before_terminator_effect(state, terminator, location);
}
/* Edge-specific effects */
fn apply_call_return_effect(
&mut self,
state: &mut A::Domain,
block: BasicBlock,
return_places: CallReturnPlaces<'_, 'tcx>,
) {
self.call_return_effect(state, block, return_places);
}
fn apply_switch_int_edge_effects(
&mut self,
block: BasicBlock,
discr: &mir::Operand<'tcx>,
edge_effects: &mut impl SwitchIntEdgeEffects<A::Domain>,
) {
self.switch_int_edge_effects(block, discr, edge_effects);
}
}
/// The legal operations for a transfer function in a gen/kill problem. /// The legal operations for a transfer function in a gen/kill problem.
///
/// This abstraction exists because there are two different contexts in which we call the methods in
/// `GenKillAnalysis`. Sometimes we need to store a single transfer function that can be efficiently
/// applied multiple times, such as when computing the cumulative transfer function for each block.
/// These cases require a `GenKillSet`, which in turn requires two `BitSet`s of storage. Oftentimes,
/// however, we only need to apply an effect once. In *these* cases, it is more efficient to pass the
/// `BitSet` representing the state vector directly into the `*_effect` methods as opposed to
/// building up a `GenKillSet` and then throwing it away.
pub trait GenKill<T> { pub trait GenKill<T> {
/// Inserts `elem` into the state vector. /// Inserts `elem` into the state vector.
fn gen_(&mut self, elem: T); fn gen_(&mut self, elem: T);

View File

@ -2,7 +2,7 @@
use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use crate::{AnalysisDomain, GenKill, GenKillAnalysis}; use crate::{Analysis, AnalysisDomain, GenKill};
/// A dataflow analysis that tracks whether a pointer or reference could possibly exist that points /// A dataflow analysis that tracks whether a pointer or reference could possibly exist that points
/// to a given local. This analysis ignores fake borrows, so it should not be used by /// to a given local. This analysis ignores fake borrows, so it should not be used by
@ -34,14 +34,8 @@ fn initialize_start_block(&self, _: &Body<'tcx>, _: &mut Self::Domain) {
} }
} }
impl<'tcx> GenKillAnalysis<'tcx> for MaybeBorrowedLocals { impl<'tcx> Analysis<'tcx> for MaybeBorrowedLocals {
type Idx = Local; fn apply_statement_effect(
fn domain_size(&self, body: &Body<'tcx>) -> usize {
body.local_decls.len()
}
fn statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
statement: &Statement<'tcx>, statement: &Statement<'tcx>,
@ -50,7 +44,7 @@ fn statement_effect(
self.transfer_function(trans).visit_statement(statement, location); self.transfer_function(trans).visit_statement(statement, location);
} }
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>, terminator: &'mir Terminator<'tcx>,
@ -60,7 +54,7 @@ fn terminator_effect<'mir>(
terminator.edges() terminator.edges()
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
_trans: &mut Self::Domain, _trans: &mut Self::Domain,
_block: BasicBlock, _block: BasicBlock,

View File

@ -11,7 +11,7 @@
use crate::framework::SwitchIntEdgeEffects; use crate::framework::SwitchIntEdgeEffects;
use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex}; use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
use crate::{ use crate::{
AnalysisDomain, GenKill, GenKillAnalysis, MaybeReachable, drop_flag_effects, Analysis, AnalysisDomain, GenKill, MaybeReachable, drop_flag_effects,
drop_flag_effects_for_function_entry, drop_flag_effects_for_location, lattice, drop_flag_effects_for_function_entry, drop_flag_effects_for_location, lattice,
on_all_children_bits, on_lookup_result_bits, on_all_children_bits, on_lookup_result_bits,
}; };
@ -329,14 +329,8 @@ fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain)
} }
} }
impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
type Idx = MovePathIndex; fn apply_statement_effect(
fn domain_size(&self, _: &Body<'tcx>) -> usize {
self.move_data().move_paths.len()
}
fn statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
statement: &mir::Statement<'tcx>, statement: &mir::Statement<'tcx>,
@ -360,7 +354,7 @@ fn statement_effect(
} }
} }
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
state: &mut Self::Domain, state: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>, terminator: &'mir mir::Terminator<'tcx>,
@ -380,7 +374,7 @@ fn terminator_effect<'mir>(
edges edges
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_block: mir::BasicBlock, _block: mir::BasicBlock,
@ -399,7 +393,7 @@ fn call_return_effect(
}); });
} }
fn switch_int_edge_effects( fn apply_switch_int_edge_effects(
&mut self, &mut self,
block: mir::BasicBlock, block: mir::BasicBlock,
discr: &mir::Operand<'tcx>, discr: &mir::Operand<'tcx>,
@ -466,14 +460,8 @@ fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain)
} }
} }
impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
type Idx = MovePathIndex; fn apply_statement_effect(
fn domain_size(&self, _: &Body<'tcx>) -> usize {
self.move_data().move_paths.len()
}
fn statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_statement: &mir::Statement<'tcx>, _statement: &mir::Statement<'tcx>,
@ -487,7 +475,7 @@ fn statement_effect(
// mutable borrow occurs. Places cannot become uninitialized through a mutable reference. // mutable borrow occurs. Places cannot become uninitialized through a mutable reference.
} }
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>, terminator: &'mir mir::Terminator<'tcx>,
@ -505,7 +493,7 @@ fn terminator_effect<'mir>(
} }
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_block: mir::BasicBlock, _block: mir::BasicBlock,
@ -524,7 +512,7 @@ fn call_return_effect(
}); });
} }
fn switch_int_edge_effects( fn apply_switch_int_edge_effects(
&mut self, &mut self,
block: mir::BasicBlock, block: mir::BasicBlock,
discr: &mir::Operand<'tcx>, discr: &mir::Operand<'tcx>,
@ -593,14 +581,8 @@ fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain)
} }
} }
impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> { impl<'tcx> Analysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
type Idx = MovePathIndex; fn apply_statement_effect(
fn domain_size(&self, _: &Body<'tcx>) -> usize {
self.move_data().move_paths.len()
}
fn statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_statement: &mir::Statement<'tcx>, _statement: &mir::Statement<'tcx>,
@ -611,7 +593,7 @@ fn statement_effect(
}) })
} }
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>, terminator: &'mir mir::Terminator<'tcx>,
@ -623,7 +605,7 @@ fn terminator_effect<'mir>(
terminator.edges() terminator.edges()
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_block: mir::BasicBlock, _block: mir::BasicBlock,
@ -662,15 +644,9 @@ fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domai
} }
} }
impl<'tcx> GenKillAnalysis<'tcx> for EverInitializedPlaces<'_, 'tcx> { impl<'tcx> Analysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
type Idx = InitIndex;
fn domain_size(&self, _: &Body<'tcx>) -> usize {
self.move_data().inits.len()
}
#[instrument(skip(self, trans), level = "debug")] #[instrument(skip(self, trans), level = "debug")]
fn statement_effect( fn apply_statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
stmt: &mir::Statement<'tcx>, stmt: &mir::Statement<'tcx>,
@ -698,7 +674,7 @@ fn statement_effect(
} }
#[instrument(skip(self, trans, terminator), level = "debug")] #[instrument(skip(self, trans, terminator), level = "debug")]
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>, terminator: &'mir mir::Terminator<'tcx>,
@ -720,7 +696,7 @@ fn terminator_effect<'mir>(
terminator.edges() terminator.edges()
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
block: mir::BasicBlock, block: mir::BasicBlock,

View File

@ -4,7 +4,7 @@
self, CallReturnPlaces, Local, Location, Place, StatementKind, TerminatorEdges, self, CallReturnPlaces, Local, Location, Place, StatementKind, TerminatorEdges,
}; };
use crate::{Analysis, AnalysisDomain, Backward, GenKill, GenKillAnalysis}; use crate::{Analysis, AnalysisDomain, Backward, GenKill};
/// A [live-variable dataflow analysis][liveness]. /// A [live-variable dataflow analysis][liveness].
/// ///
@ -41,14 +41,8 @@ fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) {
} }
} }
impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals { impl<'tcx> Analysis<'tcx> for MaybeLiveLocals {
type Idx = Local; fn apply_statement_effect(
fn domain_size(&self, body: &mir::Body<'tcx>) -> usize {
body.local_decls.len()
}
fn statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
statement: &mir::Statement<'tcx>, statement: &mir::Statement<'tcx>,
@ -57,7 +51,7 @@ fn statement_effect(
TransferFunction(trans).visit_statement(statement, location); TransferFunction(trans).visit_statement(statement, location);
} }
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>, terminator: &'mir mir::Terminator<'tcx>,
@ -67,7 +61,7 @@ fn terminator_effect<'mir>(
terminator.edges() terminator.edges()
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_block: mir::BasicBlock, _block: mir::BasicBlock,

View File

@ -5,7 +5,7 @@
use rustc_middle::mir::*; use rustc_middle::mir::*;
use super::MaybeBorrowedLocals; use super::MaybeBorrowedLocals;
use crate::{AnalysisDomain, GenKill, ResultsCursor}; use crate::{Analysis, AnalysisDomain, GenKill, ResultsCursor};
pub struct MaybeStorageLive<'a> { pub struct MaybeStorageLive<'a> {
always_live_locals: Cow<'a, BitSet<Local>>, always_live_locals: Cow<'a, BitSet<Local>>,
@ -17,7 +17,7 @@ pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
} }
} }
impl<'a, 'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageLive<'a> { impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeStorageLive<'a> {
type Domain = BitSet<Local>; type Domain = BitSet<Local>;
const NAME: &'static str = "maybe_storage_live"; const NAME: &'static str = "maybe_storage_live";
@ -39,14 +39,13 @@ fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain)
} }
} }
impl<'a, 'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> { impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageLive<'a> {
type Idx = Local; fn apply_statement_effect(
&mut self,
fn domain_size(&self, body: &Body<'tcx>) -> usize { trans: &mut Self::Domain,
body.local_decls.len() stmt: &Statement<'tcx>,
} _: Location,
) {
fn statement_effect(&mut self, trans: &mut Self::Domain, stmt: &Statement<'tcx>, _: Location) {
match stmt.kind { match stmt.kind {
StatementKind::StorageLive(l) => trans.gen_(l), StatementKind::StorageLive(l) => trans.gen_(l),
StatementKind::StorageDead(l) => trans.kill(l), StatementKind::StorageDead(l) => trans.kill(l),
@ -54,7 +53,7 @@ fn statement_effect(&mut self, trans: &mut Self::Domain, stmt: &Statement<'tcx>,
} }
} }
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
_trans: &mut Self::Domain, _trans: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>, terminator: &'mir Terminator<'tcx>,
@ -64,7 +63,7 @@ fn terminator_effect<'mir>(
terminator.edges() terminator.edges()
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
_trans: &mut Self::Domain, _trans: &mut Self::Domain,
_block: BasicBlock, _block: BasicBlock,
@ -84,7 +83,7 @@ pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
} }
} }
impl<'a, 'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageDead<'a> { impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeStorageDead<'a> {
type Domain = BitSet<Local>; type Domain = BitSet<Local>;
const NAME: &'static str = "maybe_storage_dead"; const NAME: &'static str = "maybe_storage_dead";
@ -105,14 +104,13 @@ fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain)
} }
} }
impl<'a, 'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageDead<'a> { impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageDead<'a> {
type Idx = Local; fn apply_statement_effect(
&mut self,
fn domain_size(&self, body: &Body<'tcx>) -> usize { trans: &mut Self::Domain,
body.local_decls.len() stmt: &Statement<'tcx>,
} _: Location,
) {
fn statement_effect(&mut self, trans: &mut Self::Domain, stmt: &Statement<'tcx>, _: Location) {
match stmt.kind { match stmt.kind {
StatementKind::StorageLive(l) => trans.kill(l), StatementKind::StorageLive(l) => trans.kill(l),
StatementKind::StorageDead(l) => trans.gen_(l), StatementKind::StorageDead(l) => trans.gen_(l),
@ -120,7 +118,7 @@ fn statement_effect(&mut self, trans: &mut Self::Domain, stmt: &Statement<'tcx>,
} }
} }
fn terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
_: &mut Self::Domain, _: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>, terminator: &'mir Terminator<'tcx>,
@ -130,7 +128,7 @@ fn terminator_effect<'mir>(
terminator.edges() terminator.edges()
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
_trans: &mut Self::Domain, _trans: &mut Self::Domain,
_block: BasicBlock, _block: BasicBlock,
@ -154,7 +152,7 @@ pub fn new(borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>) -> Self {
} }
} }
impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeRequiresStorage<'_, 'tcx> { impl<'tcx> AnalysisDomain<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
type Domain = BitSet<Local>; type Domain = BitSet<Local>;
const NAME: &'static str = "requires_storage"; const NAME: &'static str = "requires_storage";
@ -173,21 +171,15 @@ fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain)
} }
} }
impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> { impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
type Idx = Local; fn apply_before_statement_effect(
fn domain_size(&self, body: &Body<'tcx>) -> usize {
body.local_decls.len()
}
fn before_statement_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
stmt: &Statement<'tcx>, stmt: &Statement<'tcx>,
loc: Location, loc: Location,
) { ) {
// If a place is borrowed in a statement, it needs storage for that statement. // If a place is borrowed in a statement, it needs storage for that statement.
self.borrowed_locals.mut_analysis().statement_effect(trans, stmt, loc); self.borrowed_locals.mut_analysis().apply_statement_effect(trans, stmt, loc);
match &stmt.kind { match &stmt.kind {
StatementKind::StorageDead(l) => trans.kill(*l), StatementKind::StorageDead(l) => trans.kill(*l),
@ -213,13 +205,18 @@ fn before_statement_effect(
} }
} }
fn statement_effect(&mut self, trans: &mut Self::Domain, _: &Statement<'tcx>, loc: Location) { fn apply_statement_effect(
&mut self,
trans: &mut Self::Domain,
_: &Statement<'tcx>,
loc: Location,
) {
// If we move from a place then it only stops needing storage *after* // If we move from a place then it only stops needing storage *after*
// that statement. // that statement.
self.check_for_move(trans, loc); self.check_for_move(trans, loc);
} }
fn before_terminator_effect( fn apply_before_terminator_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
terminator: &Terminator<'tcx>, terminator: &Terminator<'tcx>,
@ -277,7 +274,7 @@ fn before_terminator_effect(
} }
} }
fn terminator_effect<'t>( fn apply_terminator_effect<'t>(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
terminator: &'t Terminator<'tcx>, terminator: &'t Terminator<'tcx>,
@ -318,7 +315,7 @@ fn terminator_effect<'t>(
terminator.edges() terminator.edges()
} }
fn call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
trans: &mut Self::Domain, trans: &mut Self::Domain,
_block: BasicBlock, _block: BasicBlock,

View File

@ -18,9 +18,9 @@
move_path_children_matching, on_all_children_bits, on_lookup_result_bits, move_path_children_matching, on_all_children_bits, on_lookup_result_bits,
}; };
pub use self::framework::{ pub use self::framework::{
Analysis, AnalysisDomain, Backward, Direction, Engine, Forward, GenKill, GenKillAnalysis, Analysis, AnalysisDomain, Backward, Direction, Engine, Forward, GenKill, JoinSemiLattice,
JoinSemiLattice, MaybeReachable, Results, ResultsCursor, ResultsVisitable, ResultsVisitor, MaybeReachable, Results, ResultsCursor, ResultsVisitable, ResultsVisitor, SwitchIntEdgeEffects,
SwitchIntEdgeEffects, fmt, graphviz, lattice, visit_results, fmt, graphviz, lattice, visit_results,
}; };
use self::move_paths::MoveData; use self::move_paths::MoveData;