1
Fork 0

Remove impl_visitable!.

It is used just once. With it removed, the relevant code is a little
boilerplate-y but much easier to read, and is the same length. Overall I
think it's an improvement.
This commit is contained in:
Nicholas Nethercote 2023-11-26 08:31:19 +11:00
parent f312775e4f
commit 60e7c6898b
2 changed files with 66 additions and 69 deletions

View file

@ -36,29 +36,28 @@ pub type BorrowckResults<'mir, 'tcx> = BorrowckAnalyses<
pub type BorrowckFlowState<'mir, 'tcx> = pub type BorrowckFlowState<'mir, 'tcx> =
<BorrowckResults<'mir, 'tcx> as ResultsVisitable<'tcx>>::FlowState; <BorrowckResults<'mir, 'tcx> as ResultsVisitable<'tcx>>::FlowState;
macro_rules! impl_visitable { impl<'tcx, B, U, E, D: Direction> ResultsVisitable<'tcx>
( $( for BorrowckAnalyses<Results<'tcx, B>, Results<'tcx, U>, Results<'tcx, E>>
$T:ident { $( $field:ident : $A:ident ),* $(,)? }
)* ) => { $(
impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*>
where where
$( $A: Analysis<'tcx, Direction = D>, )* B: Analysis<'tcx, Direction = D>,
U: Analysis<'tcx, Direction = D>,
E: Analysis<'tcx, Direction = D>,
{ {
type Direction = D; type Direction = D;
type FlowState = $T<$( $A::Domain ),*>; type FlowState = BorrowckAnalyses<B::Domain, U::Domain, E::Domain>;
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState { fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
$T { BorrowckAnalyses {
$( $field: self.$field.analysis.bottom_value(body) ),* borrows: self.borrows.analysis.bottom_value(body),
uninits: self.uninits.analysis.bottom_value(body),
ever_inits: self.ever_inits.analysis.bottom_value(body),
} }
} }
fn reset_to_block_entry( fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock) {
&self, state.borrows.clone_from(&self.borrows.entry_set_for_block(block));
state: &mut Self::FlowState, state.uninits.clone_from(&self.uninits.entry_set_for_block(block));
block: BasicBlock, state.ever_inits.clone_from(&self.ever_inits.entry_set_for_block(block));
) {
$( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )*
} }
fn reconstruct_before_statement_effect( fn reconstruct_before_statement_effect(
@ -67,8 +66,9 @@ macro_rules! impl_visitable {
stmt: &mir::Statement<'tcx>, stmt: &mir::Statement<'tcx>,
loc: Location, loc: Location,
) { ) {
$( self.$field.analysis self.borrows.analysis.apply_before_statement_effect(&mut state.borrows, stmt, loc);
.apply_before_statement_effect(&mut state.$field, stmt, loc); )* self.uninits.analysis.apply_before_statement_effect(&mut state.uninits, stmt, loc);
self.ever_inits.analysis.apply_before_statement_effect(&mut state.ever_inits, stmt, loc);
} }
fn reconstruct_statement_effect( fn reconstruct_statement_effect(
@ -77,8 +77,9 @@ macro_rules! impl_visitable {
stmt: &mir::Statement<'tcx>, stmt: &mir::Statement<'tcx>,
loc: Location, loc: Location,
) { ) {
$( self.$field.analysis self.borrows.analysis.apply_statement_effect(&mut state.borrows, stmt, loc);
.apply_statement_effect(&mut state.$field, stmt, loc); )* self.uninits.analysis.apply_statement_effect(&mut state.uninits, stmt, loc);
self.ever_inits.analysis.apply_statement_effect(&mut state.ever_inits, stmt, loc);
} }
fn reconstruct_before_terminator_effect( fn reconstruct_before_terminator_effect(
@ -87,8 +88,9 @@ macro_rules! impl_visitable {
term: &mir::Terminator<'tcx>, term: &mir::Terminator<'tcx>,
loc: Location, loc: Location,
) { ) {
$( self.$field.analysis self.borrows.analysis.apply_before_terminator_effect(&mut state.borrows, term, loc);
.apply_before_terminator_effect(&mut state.$field, term, loc); )* self.uninits.analysis.apply_before_terminator_effect(&mut state.uninits, term, loc);
self.ever_inits.analysis.apply_before_terminator_effect(&mut state.ever_inits, term, loc);
} }
fn reconstruct_terminator_effect( fn reconstruct_terminator_effect(
@ -97,16 +99,11 @@ macro_rules! impl_visitable {
term: &mir::Terminator<'tcx>, term: &mir::Terminator<'tcx>,
loc: Location, loc: Location,
) { ) {
$( self.$field.analysis self.borrows.analysis.apply_terminator_effect(&mut state.borrows, term, loc);
.apply_terminator_effect(&mut state.$field, term, loc); )* self.uninits.analysis.apply_terminator_effect(&mut state.uninits, term, loc);
self.ever_inits.analysis.apply_terminator_effect(&mut state.ever_inits, term, loc);
} }
} }
)* }
}
impl_visitable! {
BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E }
}
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable] #[orderable]

View file

@ -84,8 +84,8 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
/// Things that can be visited by a `ResultsVisitor`. /// Things that can be visited by a `ResultsVisitor`.
/// ///
/// This trait exists so that we can visit the results of multiple dataflow analyses simultaneously. /// This trait exists so that we can visit the results of one or more dataflow analyses
/// DO NOT IMPLEMENT MANUALLY. Instead, use the `impl_visitable` macro below. /// simultaneously.
pub trait ResultsVisitable<'tcx> { pub trait ResultsVisitable<'tcx> {
type Direction: Direction; type Direction: Direction;
type FlowState; type FlowState;