Remove ResultsVisitable.

Now that `Results` is the only impl of `ResultsVisitable`, the trait can
be removed. This simplifies things by removining unnecessary layers of
indirection and abstraction.

- `ResultsVisitor` is simpler.
  - Its type parameter changes from `R` (an analysis result) to the
    simpler `A` (an analysis).
  - It no longer needs the `Domain` associated type, because it can use
    `A::Domain`.
  - Occurrences of `R` become `Results<'tcx, A>`, because there is now
    only one kind of analysis results.

- `save_as_intervals` also changes type parameter from `R` to `A`.

- The `results.reconstruct_*` method calls are replaced with
  `results.analysis.apply_*` method calls, which are equivalent.

- `Direction::visit_results_in_block` is simpler, with a single generic
  param (`A`) instead of two (`D` and `R`/`F`, with a bound connecting
  them). Likewise for `visit_results`.

- The `ResultsVisitor` impls for `MirBorrowCtxt` and
  `StorageConflictVisitor` are now specific about the type of the
  analysis results they work with. They both used to have a type param
  `R` but they weren't genuinely generic. In both cases there was only a
  single results type that made sense to instantiate them with.
This commit is contained in:
Nicholas Nethercote 2024-10-31 12:33:12 +11:00
parent 3350edf8fd
commit c904c6aaff
10 changed files with 91 additions and 201 deletions

View File

@ -42,7 +42,7 @@ use rustc_mir_dataflow::impls::{
use rustc_mir_dataflow::move_paths::{ use rustc_mir_dataflow::move_paths::{
InitIndex, InitLocation, LookupResult, MoveData, MoveOutIndex, MovePathIndex, InitIndex, InitLocation, LookupResult, MoveData, MoveOutIndex, MovePathIndex,
}; };
use rustc_mir_dataflow::{Analysis, EntrySets, Results}; use rustc_mir_dataflow::{Analysis, EntrySets, Results, ResultsVisitor, visit_results};
use rustc_session::lint::builtin::UNUSED_MUT; use rustc_session::lint::builtin::UNUSED_MUT;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use smallvec::SmallVec; use smallvec::SmallVec;
@ -318,7 +318,7 @@ fn do_mir_borrowck<'tcx>(
mbcx.report_region_errors(nll_errors); mbcx.report_region_errors(nll_errors);
let mut flow_results = get_flow_results(tcx, body, &move_data, &borrow_set, &regioncx); let mut flow_results = get_flow_results(tcx, body, &move_data, &borrow_set, &regioncx);
rustc_mir_dataflow::visit_results( visit_results(
body, body,
traversal::reverse_postorder(body).map(|(bb, _)| bb), traversal::reverse_postorder(body).map(|(bb, _)| bb),
&mut flow_results, &mut flow_results,
@ -607,14 +607,10 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
// 2. loans made in overlapping scopes do not conflict // 2. loans made in overlapping scopes do not conflict
// 3. assignments do not affect things loaned out as immutable // 3. assignments do not affect things loaned out as immutable
// 4. moves do not affect things loaned out in any way // 4. moves do not affect things loaned out in any way
impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R> impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> {
for MirBorrowckCtxt<'a, '_, 'tcx>
{
type Domain = BorrowckDomain<'a, 'tcx>;
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
state: &BorrowckDomain<'a, 'tcx>, state: &BorrowckDomain<'a, 'tcx>,
stmt: &'a Statement<'tcx>, stmt: &'a Statement<'tcx>,
location: Location, location: Location,
@ -686,7 +682,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
state: &BorrowckDomain<'a, 'tcx>, state: &BorrowckDomain<'a, 'tcx>,
term: &'a Terminator<'tcx>, term: &'a Terminator<'tcx>,
loc: Location, loc: Location,
@ -799,7 +795,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
fn visit_terminator_after_primary_effect( fn visit_terminator_after_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
state: &BorrowckDomain<'a, 'tcx>, state: &BorrowckDomain<'a, 'tcx>,
term: &'a Terminator<'tcx>, term: &'a Terminator<'tcx>,
loc: Location, loc: Location,

View File

@ -4,8 +4,8 @@ use rustc_middle::mir::{
self, BasicBlock, CallReturnPlaces, Location, SwitchTargets, TerminatorEdges, self, BasicBlock, CallReturnPlaces, Location, SwitchTargets, TerminatorEdges,
}; };
use super::visitor::{ResultsVisitable, ResultsVisitor}; use super::visitor::ResultsVisitor;
use super::{Analysis, Effect, EffectIndex, SwitchIntTarget}; use super::{Analysis, Effect, EffectIndex, Results, SwitchIntTarget};
pub trait Direction { pub trait Direction {
const IS_FORWARD: bool; const IS_FORWARD: bool;
@ -33,14 +33,14 @@ pub trait Direction {
where where
A: Analysis<'tcx>; A: Analysis<'tcx>;
fn visit_results_in_block<'mir, 'tcx, D, R>( fn visit_results_in_block<'mir, 'tcx, A>(
state: &mut D, state: &mut A::Domain,
block: BasicBlock, block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>, block_data: &'mir mir::BasicBlockData<'tcx>,
results: &mut R, results: &mut Results<'tcx, A>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>, vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
) where ) where
R: ResultsVisitable<'tcx, Domain = D>; A: Analysis<'tcx>;
fn join_state_into_successors_of<'tcx, A>( fn join_state_into_successors_of<'tcx, A>(
analysis: &mut A, analysis: &mut A,
@ -53,7 +53,7 @@ pub trait Direction {
A: Analysis<'tcx>; A: Analysis<'tcx>;
} }
/// Dataflow that runs from the exit of a block (the terminator), to its entry (the first statement). /// Dataflow that runs from the exit of a block (terminator), to its entry (the first statement).
pub struct Backward; pub struct Backward;
impl Direction for Backward { impl Direction for Backward {
@ -157,32 +157,32 @@ impl Direction for Backward {
analysis.apply_statement_effect(state, statement, location); analysis.apply_statement_effect(state, statement, location);
} }
fn visit_results_in_block<'mir, 'tcx, D, R>( fn visit_results_in_block<'mir, 'tcx, A>(
state: &mut D, state: &mut A::Domain,
block: BasicBlock, block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>, block_data: &'mir mir::BasicBlockData<'tcx>,
results: &mut R, results: &mut Results<'tcx, A>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>, vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
) where ) where
R: ResultsVisitable<'tcx, Domain = D>, A: Analysis<'tcx>,
{ {
results.reset_to_block_entry(state, block); state.clone_from(results.entry_set_for_block(block));
vis.visit_block_end(state); vis.visit_block_end(state);
// Terminator // Terminator
let loc = Location { block, statement_index: block_data.statements.len() }; let loc = Location { block, statement_index: block_data.statements.len() };
let term = block_data.terminator(); let term = block_data.terminator();
results.reconstruct_before_terminator_effect(state, term, loc); results.analysis.apply_before_terminator_effect(state, term, loc);
vis.visit_terminator_before_primary_effect(results, state, term, loc); vis.visit_terminator_before_primary_effect(results, state, term, loc);
results.reconstruct_terminator_effect(state, term, loc); results.analysis.apply_terminator_effect(state, term, loc);
vis.visit_terminator_after_primary_effect(results, state, term, loc); vis.visit_terminator_after_primary_effect(results, state, term, loc);
for (statement_index, stmt) in block_data.statements.iter().enumerate().rev() { for (statement_index, stmt) in block_data.statements.iter().enumerate().rev() {
let loc = Location { block, statement_index }; let loc = Location { block, statement_index };
results.reconstruct_before_statement_effect(state, stmt, loc); results.analysis.apply_before_statement_effect(state, stmt, loc);
vis.visit_statement_before_primary_effect(results, state, stmt, loc); vis.visit_statement_before_primary_effect(results, state, stmt, loc);
results.reconstruct_statement_effect(state, stmt, loc); results.analysis.apply_statement_effect(state, stmt, loc);
vis.visit_statement_after_primary_effect(results, state, stmt, loc); vis.visit_statement_after_primary_effect(results, state, stmt, loc);
} }
@ -389,32 +389,32 @@ impl Direction for Forward {
} }
} }
fn visit_results_in_block<'mir, 'tcx, F, R>( fn visit_results_in_block<'mir, 'tcx, A>(
state: &mut F, state: &mut A::Domain,
block: BasicBlock, block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>, block_data: &'mir mir::BasicBlockData<'tcx>,
results: &mut R, results: &mut Results<'tcx, A>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = F>, vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
) where ) where
R: ResultsVisitable<'tcx, Domain = F>, A: Analysis<'tcx>,
{ {
results.reset_to_block_entry(state, block); state.clone_from(results.entry_set_for_block(block));
vis.visit_block_start(state); vis.visit_block_start(state);
for (statement_index, stmt) in block_data.statements.iter().enumerate() { for (statement_index, stmt) in block_data.statements.iter().enumerate() {
let loc = Location { block, statement_index }; let loc = Location { block, statement_index };
results.reconstruct_before_statement_effect(state, stmt, loc); results.analysis.apply_before_statement_effect(state, stmt, loc);
vis.visit_statement_before_primary_effect(results, state, stmt, loc); vis.visit_statement_before_primary_effect(results, state, stmt, loc);
results.reconstruct_statement_effect(state, stmt, loc); results.analysis.apply_statement_effect(state, stmt, loc);
vis.visit_statement_after_primary_effect(results, state, stmt, loc); vis.visit_statement_after_primary_effect(results, state, stmt, loc);
} }
let loc = Location { block, statement_index: block_data.statements.len() }; let loc = Location { block, statement_index: block_data.statements.len() };
let term = block_data.terminator(); let term = block_data.terminator();
results.reconstruct_before_terminator_effect(state, term, loc); results.analysis.apply_before_terminator_effect(state, term, loc);
vis.visit_terminator_before_primary_effect(results, state, term, loc); vis.visit_terminator_before_primary_effect(results, state, term, loc);
results.reconstruct_terminator_effect(state, term, loc); results.analysis.apply_terminator_effect(state, term, loc);
vis.visit_terminator_after_primary_effect(results, state, term, loc); vis.visit_terminator_after_primary_effect(results, state, term, loc);
vis.visit_block_end(state); vis.visit_block_end(state);

View File

@ -544,20 +544,18 @@ impl<D> StateDiffCollector<D> {
} }
} }
impl<'tcx, A> ResultsVisitor<'_, 'tcx, Results<'tcx, A>> for StateDiffCollector<A::Domain> impl<'tcx, A> ResultsVisitor<'_, 'tcx, A> for StateDiffCollector<A::Domain>
where where
A: Analysis<'tcx>, A: Analysis<'tcx>,
A::Domain: DebugWithContext<A>, A::Domain: DebugWithContext<A>,
{ {
type Domain = A::Domain; fn visit_block_start(&mut self, state: &A::Domain) {
fn visit_block_start(&mut self, state: &Self::Domain) {
if A::Direction::IS_FORWARD { if A::Direction::IS_FORWARD {
self.prev_state.clone_from(state); self.prev_state.clone_from(state);
} }
} }
fn visit_block_end(&mut self, state: &Self::Domain) { fn visit_block_end(&mut self, state: &A::Domain) {
if A::Direction::IS_BACKWARD { if A::Direction::IS_BACKWARD {
self.prev_state.clone_from(state); self.prev_state.clone_from(state);
} }
@ -566,7 +564,7 @@ where
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, A>, results: &mut Results<'tcx, A>,
state: &Self::Domain, state: &A::Domain,
_statement: &mir::Statement<'tcx>, _statement: &mir::Statement<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -579,7 +577,7 @@ where
fn visit_statement_after_primary_effect( fn visit_statement_after_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, A>, results: &mut Results<'tcx, A>,
state: &Self::Domain, state: &A::Domain,
_statement: &mir::Statement<'tcx>, _statement: &mir::Statement<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -590,7 +588,7 @@ where
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, A>, results: &mut Results<'tcx, A>,
state: &Self::Domain, state: &A::Domain,
_terminator: &mir::Terminator<'tcx>, _terminator: &mir::Terminator<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -603,7 +601,7 @@ where
fn visit_terminator_after_primary_effect( fn visit_terminator_after_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, A>, results: &mut Results<'tcx, A>,
state: &Self::Domain, state: &A::Domain,
_terminator: &mir::Terminator<'tcx>, _terminator: &mir::Terminator<'tcx>,
_location: Location, _location: Location,
) { ) {

View File

@ -56,7 +56,7 @@ pub use self::cursor::ResultsCursor;
pub use self::direction::{Backward, Direction, Forward}; pub use self::direction::{Backward, Direction, Forward};
pub use self::lattice::{JoinSemiLattice, MaybeReachable}; pub use self::lattice::{JoinSemiLattice, MaybeReachable};
pub use self::results::{EntrySets, Results}; pub use self::results::{EntrySets, Results};
pub use self::visitor::{ResultsVisitable, ResultsVisitor, visit_results}; pub use self::visitor::{ResultsVisitor, visit_results};
/// Analysis domains are all bitsets of various kinds. This trait holds /// Analysis domains are all bitsets of various kinds. This trait holds
/// operations needed by all of them. /// operations needed by all of them.

View File

@ -51,7 +51,7 @@ where
&mut self, &mut self,
body: &'mir mir::Body<'tcx>, body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>, blocks: impl IntoIterator<Item = BasicBlock>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, Domain = A::Domain>, vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
) { ) {
visit_results(body, blocks, self, vis) visit_results(body, blocks, self, vis)
} }
@ -59,7 +59,7 @@ where
pub fn visit_reachable_with<'mir>( pub fn visit_reachable_with<'mir>(
&mut self, &mut self,
body: &'mir mir::Body<'tcx>, body: &'mir mir::Body<'tcx>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, Domain = A::Domain>, vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
) { ) {
let blocks = traversal::reachable(body); let blocks = traversal::reachable(body);
visit_results(body, blocks.map(|(bb, _)| bb), self, vis) visit_results(body, blocks.map(|(bb, _)| bb), self, vis)

View File

@ -4,15 +4,15 @@ use super::{Analysis, Direction, Results};
/// Calls the corresponding method in `ResultsVisitor` for every location in a `mir::Body` with the /// Calls the corresponding method in `ResultsVisitor` for every location in a `mir::Body` with the
/// dataflow state at that location. /// dataflow state at that location.
pub fn visit_results<'mir, 'tcx, D, R>( pub fn visit_results<'mir, 'tcx, A>(
body: &'mir mir::Body<'tcx>, body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>, blocks: impl IntoIterator<Item = BasicBlock>,
results: &mut R, results: &mut Results<'tcx, A>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>, vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
) where ) where
R: ResultsVisitable<'tcx, Domain = D>, A: Analysis<'tcx>,
{ {
let mut state = results.bottom_value(body); let mut state = results.analysis.bottom_value(body);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
let reachable_blocks = mir::traversal::reachable_as_bitset(body); let reachable_blocks = mir::traversal::reachable_as_bitset(body);
@ -22,23 +22,23 @@ pub fn visit_results<'mir, 'tcx, D, R>(
assert!(reachable_blocks.contains(block)); assert!(reachable_blocks.contains(block));
let block_data = &body[block]; let block_data = &body[block];
R::Direction::visit_results_in_block(&mut state, block, block_data, results, vis); A::Direction::visit_results_in_block(&mut state, block, block_data, results, vis);
} }
} }
/// A visitor over the results of an `Analysis`. The type parameter `R` is the results type being /// A visitor over the results of an `Analysis`.
/// visited. pub trait ResultsVisitor<'mir, 'tcx, A>
pub trait ResultsVisitor<'mir, 'tcx, R> { where
type Domain; A: Analysis<'tcx>,
{
fn visit_block_start(&mut self, _state: &Self::Domain) {} fn visit_block_start(&mut self, _state: &A::Domain) {}
/// Called with the `before_statement_effect` of the given statement applied to `state` but not /// Called with the `before_statement_effect` of the given statement applied to `state` but not
/// its `statement_effect`. /// its `statement_effect`.
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, A>,
_state: &Self::Domain, _state: &A::Domain,
_statement: &'mir mir::Statement<'tcx>, _statement: &'mir mir::Statement<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -48,19 +48,19 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
/// statement applied to `state`. /// statement applied to `state`.
fn visit_statement_after_primary_effect( fn visit_statement_after_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, A>,
_state: &Self::Domain, _state: &A::Domain,
_statement: &'mir mir::Statement<'tcx>, _statement: &'mir mir::Statement<'tcx>,
_location: Location, _location: Location,
) { ) {
} }
/// Called with the `before_terminator_effect` of the given terminator applied to `state` but not /// Called with the `before_terminator_effect` of the given terminator applied to `state` but
/// its `terminator_effect`. /// not its `terminator_effect`.
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, A>,
_state: &Self::Domain, _state: &A::Domain,
_terminator: &'mir mir::Terminator<'tcx>, _terminator: &'mir mir::Terminator<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -72,109 +72,12 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
/// The `call_return_effect` (if one exists) will *not* be applied to `state`. /// The `call_return_effect` (if one exists) will *not* be applied to `state`.
fn visit_terminator_after_primary_effect( fn visit_terminator_after_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, A>,
_state: &Self::Domain, _state: &A::Domain,
_terminator: &'mir mir::Terminator<'tcx>, _terminator: &'mir mir::Terminator<'tcx>,
_location: Location, _location: Location,
) { ) {
} }
fn visit_block_end(&mut self, _state: &Self::Domain) {} fn visit_block_end(&mut self, _state: &A::Domain) {}
}
/// Things that can be visited by a `ResultsVisitor`.
///
/// This trait exists so that we can visit the results of one or more dataflow analyses
/// simultaneously.
pub trait ResultsVisitable<'tcx> {
type Direction: Direction;
type Domain;
/// Creates an empty `Domain` to hold the transient state for these dataflow results.
///
/// The value of the newly created `Domain` will be overwritten by `reset_to_block_entry`
/// before it can be observed by a `ResultsVisitor`.
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain;
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock);
fn reconstruct_before_statement_effect(
&mut self,
state: &mut Self::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
);
fn reconstruct_statement_effect(
&mut self,
state: &mut Self::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
);
fn reconstruct_before_terminator_effect(
&mut self,
state: &mut Self::Domain,
terminator: &mir::Terminator<'tcx>,
location: Location,
);
fn reconstruct_terminator_effect(
&mut self,
state: &mut Self::Domain,
terminator: &mir::Terminator<'tcx>,
location: Location,
);
}
impl<'tcx, A> ResultsVisitable<'tcx> for Results<'tcx, A>
where
A: Analysis<'tcx>,
{
type Domain = A::Domain;
type Direction = A::Direction;
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
self.analysis.bottom_value(body)
}
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock) {
state.clone_from(self.entry_set_for_block(block));
}
fn reconstruct_before_statement_effect(
&mut self,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
self.analysis.apply_before_statement_effect(state, stmt, loc);
}
fn reconstruct_statement_effect(
&mut self,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
self.analysis.apply_statement_effect(state, stmt, loc);
}
fn reconstruct_before_terminator_effect(
&mut self,
state: &mut Self::Domain,
term: &mir::Terminator<'tcx>,
loc: Location,
) {
self.analysis.apply_before_terminator_effect(state, term, loc);
}
fn reconstruct_terminator_effect(
&mut self,
state: &mut Self::Domain,
term: &mir::Terminator<'tcx>,
loc: Location,
) {
self.analysis.apply_terminator_effect(state, term, loc);
}
} }

View File

@ -19,8 +19,8 @@ pub use self::drop_flag_effects::{
}; };
pub use self::framework::{ pub use self::framework::{
Analysis, Backward, Direction, EntrySets, Forward, GenKill, JoinSemiLattice, MaybeReachable, Analysis, Backward, Direction, EntrySets, Forward, GenKill, JoinSemiLattice, MaybeReachable,
Results, ResultsCursor, ResultsVisitable, ResultsVisitor, SwitchIntEdgeEffects, fmt, graphviz, Results, ResultsCursor, ResultsVisitor, SwitchIntEdgeEffects, fmt, graphviz, lattice,
lattice, visit_results, visit_results,
}; };
use self::move_paths::MoveData; use self::move_paths::MoveData;

View File

@ -3,7 +3,7 @@ use rustc_index::interval::SparseIntervalMatrix;
use rustc_index::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_middle::mir::{self, BasicBlock, Body, Location}; use rustc_middle::mir::{self, BasicBlock, Body, Location};
use crate::framework::{ResultsVisitable, ResultsVisitor, visit_results}; use crate::framework::{Analysis, Results, ResultsVisitor, visit_results};
/// Maps between a `Location` and a `PointIndex` (and vice versa). /// Maps between a `Location` and a `PointIndex` (and vice versa).
pub struct DenseLocationMap { pub struct DenseLocationMap {
@ -95,14 +95,14 @@ rustc_index::newtype_index! {
} }
/// Add points depending on the result of the given dataflow analysis. /// Add points depending on the result of the given dataflow analysis.
pub fn save_as_intervals<'tcx, N, R>( pub fn save_as_intervals<'tcx, N, A>(
elements: &DenseLocationMap, elements: &DenseLocationMap,
body: &mir::Body<'tcx>, body: &mir::Body<'tcx>,
mut results: R, mut results: Results<'tcx, A>,
) -> SparseIntervalMatrix<N, PointIndex> ) -> SparseIntervalMatrix<N, PointIndex>
where where
N: Idx, N: Idx,
R: ResultsVisitable<'tcx, Domain = BitSet<N>>, A: Analysis<'tcx, Domain = BitSet<N>>,
{ {
let values = SparseIntervalMatrix::new(elements.num_points()); let values = SparseIntervalMatrix::new(elements.num_points());
let mut visitor = Visitor { elements, values }; let mut visitor = Visitor { elements, values };
@ -120,16 +120,15 @@ struct Visitor<'a, N: Idx> {
values: SparseIntervalMatrix<N, PointIndex>, values: SparseIntervalMatrix<N, PointIndex>,
} }
impl<'mir, 'tcx, R, N> ResultsVisitor<'mir, 'tcx, R> for Visitor<'_, N> impl<'mir, 'tcx, A, N> ResultsVisitor<'mir, 'tcx, A> for Visitor<'_, N>
where where
A: Analysis<'tcx, Domain = BitSet<N>>,
N: Idx, N: Idx,
{ {
type Domain = BitSet<N>;
fn visit_statement_after_primary_effect( fn visit_statement_after_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, A>,
state: &Self::Domain, state: &A::Domain,
_statement: &'mir mir::Statement<'tcx>, _statement: &'mir mir::Statement<'tcx>,
location: Location, location: Location,
) { ) {
@ -142,8 +141,8 @@ where
fn visit_terminator_after_primary_effect( fn visit_terminator_after_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, A>,
state: &Self::Domain, state: &A::Domain,
_terminator: &'mir mir::Terminator<'tcx>, _terminator: &'mir mir::Terminator<'tcx>,
location: Location, location: Location,
) { ) {

View File

@ -68,11 +68,11 @@ use rustc_middle::ty::{
self, CoroutineArgs, CoroutineArgsExt, GenericArgsRef, InstanceKind, Ty, TyCtxt, TypingMode, self, CoroutineArgs, CoroutineArgsExt, GenericArgsRef, InstanceKind, Ty, TyCtxt, TypingMode,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_mir_dataflow::Analysis;
use rustc_mir_dataflow::impls::{ use rustc_mir_dataflow::impls::{
MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive,
}; };
use rustc_mir_dataflow::storage::always_storage_live_locals; use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor};
use rustc_span::Span; use rustc_span::Span;
use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -817,9 +817,9 @@ impl ops::Deref for CoroutineSavedLocals {
/// computation; see `CoroutineLayout` for more. /// computation; see `CoroutineLayout` for more.
fn compute_storage_conflicts<'mir, 'tcx>( fn compute_storage_conflicts<'mir, 'tcx>(
body: &'mir Body<'tcx>, body: &'mir Body<'tcx>,
saved_locals: &CoroutineSavedLocals, saved_locals: &'mir CoroutineSavedLocals,
always_live_locals: BitSet<Local>, always_live_locals: BitSet<Local>,
mut requires_storage: rustc_mir_dataflow::Results<'tcx, MaybeRequiresStorage<'mir, 'tcx>>, mut requires_storage: Results<'tcx, MaybeRequiresStorage<'mir, 'tcx>>,
) -> BitMatrix<CoroutineSavedLocal, CoroutineSavedLocal> { ) -> BitMatrix<CoroutineSavedLocal, CoroutineSavedLocal> {
assert_eq!(body.local_decls.len(), saved_locals.domain_size()); assert_eq!(body.local_decls.len(), saved_locals.domain_size());
@ -877,15 +877,13 @@ struct StorageConflictVisitor<'a, 'tcx> {
eligible_storage_live: BitSet<Local>, eligible_storage_live: BitSet<Local>,
} }
impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R> impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, MaybeRequiresStorage<'a, 'tcx>>
for StorageConflictVisitor<'a, 'tcx> for StorageConflictVisitor<'a, 'tcx>
{ {
type Domain = BitSet<Local>;
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, MaybeRequiresStorage<'a, 'tcx>>,
state: &Self::Domain, state: &BitSet<Local>,
_statement: &'a Statement<'tcx>, _statement: &'a Statement<'tcx>,
loc: Location, loc: Location,
) { ) {
@ -894,8 +892,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut Results<'tcx, MaybeRequiresStorage<'a, 'tcx>>,
state: &Self::Domain, state: &BitSet<Local>,
_terminator: &'a Terminator<'tcx>, _terminator: &'a Terminator<'tcx>,
loc: Location, loc: Location,
) { ) {

View File

@ -941,16 +941,12 @@ fn try_write_constant<'tcx>(
interp_ok(()) interp_ok(())
} }
impl<'mir, 'tcx> ResultsVisitor<'mir, 'tcx, Results<'tcx, ConstAnalysis<'_, 'tcx>>> impl<'mir, 'tcx> ResultsVisitor<'mir, 'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx> {
for Collector<'_, 'tcx>
{
type Domain = State<FlatSet<Scalar>>;
#[instrument(level = "trace", skip(self, results, statement))] #[instrument(level = "trace", skip(self, results, statement))]
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>, results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>,
state: &Self::Domain, state: &State<FlatSet<Scalar>>,
statement: &'mir Statement<'tcx>, statement: &'mir Statement<'tcx>,
location: Location, location: Location,
) { ) {
@ -972,7 +968,7 @@ impl<'mir, 'tcx> ResultsVisitor<'mir, 'tcx, Results<'tcx, ConstAnalysis<'_, 'tcx
fn visit_statement_after_primary_effect( fn visit_statement_after_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>, results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>,
state: &Self::Domain, state: &State<FlatSet<Scalar>>,
statement: &'mir Statement<'tcx>, statement: &'mir Statement<'tcx>,
location: Location, location: Location,
) { ) {
@ -997,7 +993,7 @@ impl<'mir, 'tcx> ResultsVisitor<'mir, 'tcx, Results<'tcx, ConstAnalysis<'_, 'tcx
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>, results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>,
state: &Self::Domain, state: &State<FlatSet<Scalar>>,
terminator: &'mir Terminator<'tcx>, terminator: &'mir Terminator<'tcx>,
location: Location, location: Location,
) { ) {