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:
parent
f312775e4f
commit
60e7c6898b
2 changed files with 66 additions and 69 deletions
|
@ -36,76 +36,73 @@ 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 ),* $(,)? }
|
where
|
||||||
)* ) => { $(
|
B: Analysis<'tcx, Direction = D>,
|
||||||
impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*>
|
U: Analysis<'tcx, Direction = D>,
|
||||||
where
|
E: Analysis<'tcx, Direction = D>,
|
||||||
$( $A: Analysis<'tcx, Direction = D>, )*
|
{
|
||||||
{
|
type Direction = D;
|
||||||
type Direction = D;
|
type FlowState = BorrowckAnalyses<B::Domain, U::Domain, E::Domain>;
|
||||||
type FlowState = $T<$( $A::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(
|
|
||||||
&self,
|
|
||||||
state: &mut Self::FlowState,
|
|
||||||
block: BasicBlock,
|
|
||||||
) {
|
|
||||||
$( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )*
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reconstruct_before_statement_effect(
|
|
||||||
&mut self,
|
|
||||||
state: &mut Self::FlowState,
|
|
||||||
stmt: &mir::Statement<'tcx>,
|
|
||||||
loc: Location,
|
|
||||||
) {
|
|
||||||
$( self.$field.analysis
|
|
||||||
.apply_before_statement_effect(&mut state.$field, stmt, loc); )*
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reconstruct_statement_effect(
|
|
||||||
&mut self,
|
|
||||||
state: &mut Self::FlowState,
|
|
||||||
stmt: &mir::Statement<'tcx>,
|
|
||||||
loc: Location,
|
|
||||||
) {
|
|
||||||
$( self.$field.analysis
|
|
||||||
.apply_statement_effect(&mut state.$field, stmt, loc); )*
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reconstruct_before_terminator_effect(
|
|
||||||
&mut self,
|
|
||||||
state: &mut Self::FlowState,
|
|
||||||
term: &mir::Terminator<'tcx>,
|
|
||||||
loc: Location,
|
|
||||||
) {
|
|
||||||
$( self.$field.analysis
|
|
||||||
.apply_before_terminator_effect(&mut state.$field, term, loc); )*
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reconstruct_terminator_effect(
|
|
||||||
&mut self,
|
|
||||||
state: &mut Self::FlowState,
|
|
||||||
term: &mir::Terminator<'tcx>,
|
|
||||||
loc: Location,
|
|
||||||
) {
|
|
||||||
$( self.$field.analysis
|
|
||||||
.apply_terminator_effect(&mut state.$field, term, loc); )*
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)* }
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl_visitable! {
|
fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock) {
|
||||||
BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E }
|
state.borrows.clone_from(&self.borrows.entry_set_for_block(block));
|
||||||
|
state.uninits.clone_from(&self.uninits.entry_set_for_block(block));
|
||||||
|
state.ever_inits.clone_from(&self.ever_inits.entry_set_for_block(block));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reconstruct_before_statement_effect(
|
||||||
|
&mut self,
|
||||||
|
state: &mut Self::FlowState,
|
||||||
|
stmt: &mir::Statement<'tcx>,
|
||||||
|
loc: Location,
|
||||||
|
) {
|
||||||
|
self.borrows.analysis.apply_before_statement_effect(&mut state.borrows, 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(
|
||||||
|
&mut self,
|
||||||
|
state: &mut Self::FlowState,
|
||||||
|
stmt: &mir::Statement<'tcx>,
|
||||||
|
loc: Location,
|
||||||
|
) {
|
||||||
|
self.borrows.analysis.apply_statement_effect(&mut state.borrows, 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(
|
||||||
|
&mut self,
|
||||||
|
state: &mut Self::FlowState,
|
||||||
|
term: &mir::Terminator<'tcx>,
|
||||||
|
loc: Location,
|
||||||
|
) {
|
||||||
|
self.borrows.analysis.apply_before_terminator_effect(&mut state.borrows, 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(
|
||||||
|
&mut self,
|
||||||
|
state: &mut Self::FlowState,
|
||||||
|
term: &mir::Terminator<'tcx>,
|
||||||
|
loc: Location,
|
||||||
|
) {
|
||||||
|
self.borrows.analysis.apply_terminator_effect(&mut state.borrows, 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rustc_index::newtype_index! {
|
rustc_index::newtype_index! {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue