Skip to content

Commit 1b35beb

Browse files
committed
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.
1 parent 76c00f2 commit 1b35beb

File tree

2 files changed

+64
-67
lines changed

2 files changed

+64
-67
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -36,76 +36,73 @@ pub type BorrowckResults<'mir, 'tcx> = BorrowckAnalyses<
3636
pub type BorrowckFlowState<'mir, 'tcx> =
3737
<BorrowckResults<'mir, 'tcx> as ResultsVisitable<'tcx>>::FlowState;
3838

39-
macro_rules! impl_visitable {
40-
( $(
41-
$T:ident { $( $field:ident : $A:ident ),* $(,)? }
42-
)* ) => { $(
43-
impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*>
44-
where
45-
$( $A: Analysis<'tcx, Direction = D>, )*
46-
{
47-
type Direction = D;
48-
type FlowState = $T<$( $A::Domain ),*>;
49-
50-
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
51-
$T {
52-
$( $field: self.$field.analysis.bottom_value(body) ),*
53-
}
54-
}
55-
56-
fn reset_to_block_entry(
57-
&self,
58-
state: &mut Self::FlowState,
59-
block: BasicBlock,
60-
) {
61-
$( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )*
62-
}
39+
impl<'tcx, B, U, E, D: Direction> ResultsVisitable<'tcx>
40+
for BorrowckAnalyses<Results<'tcx, B>, Results<'tcx, U>, Results<'tcx, E>>
41+
where
42+
B: Analysis<'tcx, Direction = D>,
43+
U: Analysis<'tcx, Direction = D>,
44+
E: Analysis<'tcx, Direction = D>,
45+
{
46+
type Direction = D;
47+
type FlowState = BorrowckAnalyses<B::Domain, U::Domain, E::Domain>;
48+
49+
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
50+
BorrowckAnalyses {
51+
borrows: self.borrows.analysis.bottom_value(body),
52+
uninits: self.uninits.analysis.bottom_value(body),
53+
ever_inits: self.ever_inits.analysis.bottom_value(body),
54+
}
55+
}
6356

64-
fn reconstruct_before_statement_effect(
65-
&mut self,
66-
state: &mut Self::FlowState,
67-
stmt: &mir::Statement<'tcx>,
68-
loc: Location,
69-
) {
70-
$( self.$field.analysis
71-
.apply_before_statement_effect(&mut state.$field, stmt, loc); )*
72-
}
57+
fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock) {
58+
state.borrows.clone_from(&self.borrows.entry_set_for_block(block));
59+
state.uninits.clone_from(&self.uninits.entry_set_for_block(block));
60+
state.ever_inits.clone_from(&self.ever_inits.entry_set_for_block(block));
61+
}
7362

74-
fn reconstruct_statement_effect(
75-
&mut self,
76-
state: &mut Self::FlowState,
77-
stmt: &mir::Statement<'tcx>,
78-
loc: Location,
79-
) {
80-
$( self.$field.analysis
81-
.apply_statement_effect(&mut state.$field, stmt, loc); )*
82-
}
63+
fn reconstruct_before_statement_effect(
64+
&mut self,
65+
state: &mut Self::FlowState,
66+
stmt: &mir::Statement<'tcx>,
67+
loc: Location,
68+
) {
69+
self.borrows.analysis.apply_before_statement_effect(&mut state.borrows, stmt, loc);
70+
self.uninits.analysis.apply_before_statement_effect(&mut state.uninits, stmt, loc);
71+
self.ever_inits.analysis.apply_before_statement_effect(&mut state.ever_inits, stmt, loc);
72+
}
8373

84-
fn reconstruct_before_terminator_effect(
85-
&mut self,
86-
state: &mut Self::FlowState,
87-
term: &mir::Terminator<'tcx>,
88-
loc: Location,
89-
) {
90-
$( self.$field.analysis
91-
.apply_before_terminator_effect(&mut state.$field, term, loc); )*
92-
}
74+
fn reconstruct_statement_effect(
75+
&mut self,
76+
state: &mut Self::FlowState,
77+
stmt: &mir::Statement<'tcx>,
78+
loc: Location,
79+
) {
80+
self.borrows.analysis.apply_statement_effect(&mut state.borrows, stmt, loc);
81+
self.uninits.analysis.apply_statement_effect(&mut state.uninits, stmt, loc);
82+
self.ever_inits.analysis.apply_statement_effect(&mut state.ever_inits, stmt, loc);
83+
}
9384

94-
fn reconstruct_terminator_effect(
95-
&mut self,
96-
state: &mut Self::FlowState,
97-
term: &mir::Terminator<'tcx>,
98-
loc: Location,
99-
) {
100-
$( self.$field.analysis
101-
.apply_terminator_effect(&mut state.$field, term, loc); )*
102-
}
103-
}
104-
)* }
105-
}
85+
fn reconstruct_before_terminator_effect(
86+
&mut self,
87+
state: &mut Self::FlowState,
88+
term: &mir::Terminator<'tcx>,
89+
loc: Location,
90+
) {
91+
self.borrows.analysis.apply_before_terminator_effect(&mut state.borrows, term, loc);
92+
self.uninits.analysis.apply_before_terminator_effect(&mut state.uninits, term, loc);
93+
self.ever_inits.analysis.apply_before_terminator_effect(&mut state.ever_inits, term, loc);
94+
}
10695

107-
impl_visitable! {
108-
BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E }
96+
fn reconstruct_terminator_effect(
97+
&mut self,
98+
state: &mut Self::FlowState,
99+
term: &mir::Terminator<'tcx>,
100+
loc: Location,
101+
) {
102+
self.borrows.analysis.apply_terminator_effect(&mut state.borrows, term, loc);
103+
self.uninits.analysis.apply_terminator_effect(&mut state.uninits, term, loc);
104+
self.ever_inits.analysis.apply_terminator_effect(&mut state.ever_inits, term, loc);
105+
}
109106
}
110107

111108
rustc_index::newtype_index! {

compiler/rustc_mir_dataflow/src/framework/visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
8484

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

0 commit comments

Comments
 (0)