Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4ff5558

Browse files
committed
Pass Analysis to visit_* instead of Results.
Every `Results` contains an `Analysis`, but these methods only need the `Analysis`. No point passing them more data than they need.
1 parent fa58ce3 commit 4ff5558

File tree

7 files changed

+50
-56
lines changed

7 files changed

+50
-56
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
705705
impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> {
706706
fn visit_after_early_statement_effect(
707707
&mut self,
708-
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
708+
_analysis: &mut Borrowck<'a, 'tcx>,
709709
state: &BorrowckDomain,
710710
stmt: &Statement<'tcx>,
711711
location: Location,
@@ -781,7 +781,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a,
781781

782782
fn visit_after_early_terminator_effect(
783783
&mut self,
784-
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
784+
_analysis: &mut Borrowck<'a, 'tcx>,
785785
state: &BorrowckDomain,
786786
term: &Terminator<'tcx>,
787787
loc: Location,
@@ -894,7 +894,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a,
894894

895895
fn visit_after_primary_terminator_effect(
896896
&mut self,
897-
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
897+
_analysis: &mut Borrowck<'a, 'tcx>,
898898
state: &BorrowckDomain,
899899
term: &Terminator<'tcx>,
900900
loc: Location,

compiler/rustc_mir_dataflow/src/framework/direction.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,18 @@ impl Direction for Backward {
222222

223223
let loc = Location { block, statement_index: block_data.statements.len() };
224224
let term = block_data.terminator();
225-
results.analysis.apply_early_terminator_effect(state, term, loc);
226-
vis.visit_after_early_terminator_effect(results, state, term, loc);
227-
results.analysis.apply_primary_terminator_effect(state, term, loc);
228-
vis.visit_after_primary_terminator_effect(results, state, term, loc);
225+
let analysis = &mut results.analysis;
226+
analysis.apply_early_terminator_effect(state, term, loc);
227+
vis.visit_after_early_terminator_effect(analysis, state, term, loc);
228+
analysis.apply_primary_terminator_effect(state, term, loc);
229+
vis.visit_after_primary_terminator_effect(analysis, state, term, loc);
229230

230231
for (statement_index, stmt) in block_data.statements.iter().enumerate().rev() {
231232
let loc = Location { block, statement_index };
232-
results.analysis.apply_early_statement_effect(state, stmt, loc);
233-
vis.visit_after_early_statement_effect(results, state, stmt, loc);
234-
results.analysis.apply_primary_statement_effect(state, stmt, loc);
235-
vis.visit_after_primary_statement_effect(results, state, stmt, loc);
233+
analysis.apply_early_statement_effect(state, stmt, loc);
234+
vis.visit_after_early_statement_effect(analysis, state, stmt, loc);
235+
analysis.apply_primary_statement_effect(state, stmt, loc);
236+
vis.visit_after_primary_statement_effect(analysis, state, stmt, loc);
236237
}
237238

238239
vis.visit_block_start(state);
@@ -402,20 +403,21 @@ impl Direction for Forward {
402403

403404
vis.visit_block_start(state);
404405

406+
let analysis = &mut results.analysis;
405407
for (statement_index, stmt) in block_data.statements.iter().enumerate() {
406408
let loc = Location { block, statement_index };
407-
results.analysis.apply_early_statement_effect(state, stmt, loc);
408-
vis.visit_after_early_statement_effect(results, state, stmt, loc);
409-
results.analysis.apply_primary_statement_effect(state, stmt, loc);
410-
vis.visit_after_primary_statement_effect(results, state, stmt, loc);
409+
analysis.apply_early_statement_effect(state, stmt, loc);
410+
vis.visit_after_early_statement_effect(analysis, state, stmt, loc);
411+
analysis.apply_primary_statement_effect(state, stmt, loc);
412+
vis.visit_after_primary_statement_effect(analysis, state, stmt, loc);
411413
}
412414

413415
let loc = Location { block, statement_index: block_data.statements.len() };
414416
let term = block_data.terminator();
415-
results.analysis.apply_early_terminator_effect(state, term, loc);
416-
vis.visit_after_early_terminator_effect(results, state, term, loc);
417-
results.analysis.apply_primary_terminator_effect(state, term, loc);
418-
vis.visit_after_primary_terminator_effect(results, state, term, loc);
417+
analysis.apply_early_terminator_effect(state, term, loc);
418+
vis.visit_after_early_terminator_effect(analysis, state, term, loc);
419+
analysis.apply_primary_terminator_effect(state, term, loc);
420+
vis.visit_after_primary_terminator_effect(analysis, state, term, loc);
419421

420422
vis.visit_block_end(state);
421423
}

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -729,49 +729,49 @@ where
729729

730730
fn visit_after_early_statement_effect(
731731
&mut self,
732-
results: &mut Results<'tcx, A>,
732+
analysis: &mut A,
733733
state: &A::Domain,
734734
_statement: &mir::Statement<'tcx>,
735735
_location: Location,
736736
) {
737737
if let Some(before) = self.before.as_mut() {
738-
before.push(diff_pretty(state, &self.prev_state, &results.analysis));
738+
before.push(diff_pretty(state, &self.prev_state, analysis));
739739
self.prev_state.clone_from(state)
740740
}
741741
}
742742

743743
fn visit_after_primary_statement_effect(
744744
&mut self,
745-
results: &mut Results<'tcx, A>,
745+
analysis: &mut A,
746746
state: &A::Domain,
747747
_statement: &mir::Statement<'tcx>,
748748
_location: Location,
749749
) {
750-
self.after.push(diff_pretty(state, &self.prev_state, &results.analysis));
750+
self.after.push(diff_pretty(state, &self.prev_state, analysis));
751751
self.prev_state.clone_from(state)
752752
}
753753

754754
fn visit_after_early_terminator_effect(
755755
&mut self,
756-
results: &mut Results<'tcx, A>,
756+
analysis: &mut A,
757757
state: &A::Domain,
758758
_terminator: &mir::Terminator<'tcx>,
759759
_location: Location,
760760
) {
761761
if let Some(before) = self.before.as_mut() {
762-
before.push(diff_pretty(state, &self.prev_state, &results.analysis));
762+
before.push(diff_pretty(state, &self.prev_state, analysis));
763763
self.prev_state.clone_from(state)
764764
}
765765
}
766766

767767
fn visit_after_primary_terminator_effect(
768768
&mut self,
769-
results: &mut Results<'tcx, A>,
769+
analysis: &mut A,
770770
state: &A::Domain,
771771
_terminator: &mir::Terminator<'tcx>,
772772
_location: Location,
773773
) {
774-
self.after.push(diff_pretty(state, &self.prev_state, &results.analysis));
774+
self.after.push(diff_pretty(state, &self.prev_state, analysis));
775775
self.prev_state.clone_from(state)
776776
}
777777
}

compiler/rustc_mir_dataflow/src/framework/visitor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ where
3838
/// Called after the "early" effect of the given statement is applied to `state`.
3939
fn visit_after_early_statement_effect(
4040
&mut self,
41-
_results: &mut Results<'tcx, A>,
41+
_analysis: &mut A,
4242
_state: &A::Domain,
4343
_statement: &mir::Statement<'tcx>,
4444
_location: Location,
@@ -48,7 +48,7 @@ where
4848
/// Called after the "primary" effect of the given statement is applied to `state`.
4949
fn visit_after_primary_statement_effect(
5050
&mut self,
51-
_results: &mut Results<'tcx, A>,
51+
_analysis: &mut A,
5252
_state: &A::Domain,
5353
_statement: &mir::Statement<'tcx>,
5454
_location: Location,
@@ -58,7 +58,7 @@ where
5858
/// Called after the "early" effect of the given terminator is applied to `state`.
5959
fn visit_after_early_terminator_effect(
6060
&mut self,
61-
_results: &mut Results<'tcx, A>,
61+
_analysis: &mut A,
6262
_state: &A::Domain,
6363
_terminator: &mir::Terminator<'tcx>,
6464
_location: Location,
@@ -70,7 +70,7 @@ where
7070
/// The `call_return_effect` (if one exists) will *not* be applied to `state`.
7171
fn visit_after_primary_terminator_effect(
7272
&mut self,
73-
_results: &mut Results<'tcx, A>,
73+
_analysis: &mut A,
7474
_state: &A::Domain,
7575
_terminator: &mir::Terminator<'tcx>,
7676
_location: Location,

compiler/rustc_mir_dataflow/src/points.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ where
127127
{
128128
fn visit_after_primary_statement_effect<'mir>(
129129
&mut self,
130-
_results: &mut Results<'tcx, A>,
130+
_analysis: &mut A,
131131
state: &A::Domain,
132132
_statement: &'mir mir::Statement<'tcx>,
133133
location: Location,
@@ -141,7 +141,7 @@ where
141141

142142
fn visit_after_primary_terminator_effect<'mir>(
143143
&mut self,
144-
_results: &mut Results<'tcx, A>,
144+
_analysis: &mut A,
145145
state: &A::Domain,
146146
_terminator: &'mir mir::Terminator<'tcx>,
147147
location: Location,

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, MaybeRequiresStorage<'a, 'tcx>>
880880
{
881881
fn visit_after_early_statement_effect(
882882
&mut self,
883-
_results: &mut Results<'tcx, MaybeRequiresStorage<'a, 'tcx>>,
883+
_analysis: &mut MaybeRequiresStorage<'a, 'tcx>,
884884
state: &DenseBitSet<Local>,
885885
_statement: &Statement<'tcx>,
886886
loc: Location,
@@ -890,7 +890,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, MaybeRequiresStorage<'a, 'tcx>>
890890

891891
fn visit_after_early_terminator_effect(
892892
&mut self,
893-
_results: &mut Results<'tcx, MaybeRequiresStorage<'a, 'tcx>>,
893+
_analysis: &mut MaybeRequiresStorage<'a, 'tcx>,
894894
state: &DenseBitSet<Local>,
895895
_terminator: &Terminator<'tcx>,
896896
loc: Location,

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_mir_dataflow::lattice::{FlatSet, HasBottom};
2323
use rustc_mir_dataflow::value_analysis::{
2424
Map, PlaceIndex, State, TrackElem, ValueOrPlace, debug_with_context,
2525
};
26-
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor};
26+
use rustc_mir_dataflow::{Analysis, ResultsVisitor};
2727
use rustc_span::DUMMY_SP;
2828
use tracing::{debug, debug_span, instrument};
2929

@@ -959,10 +959,10 @@ fn try_write_constant<'tcx>(
959959
}
960960

961961
impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx> {
962-
#[instrument(level = "trace", skip(self, results, statement))]
962+
#[instrument(level = "trace", skip(self, analysis, statement))]
963963
fn visit_after_early_statement_effect(
964964
&mut self,
965-
results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>,
965+
analysis: &mut ConstAnalysis<'_, 'tcx>,
966966
state: &State<FlatSet<Scalar>>,
967967
statement: &Statement<'tcx>,
968968
location: Location,
@@ -972,19 +972,19 @@ impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx>
972972
OperandCollector {
973973
state,
974974
visitor: self,
975-
ecx: &mut results.analysis.ecx,
976-
map: &results.analysis.map,
975+
ecx: &mut analysis.ecx,
976+
map: &analysis.map,
977977
}
978978
.visit_rvalue(rvalue, location);
979979
}
980980
_ => (),
981981
}
982982
}
983983

984-
#[instrument(level = "trace", skip(self, results, statement))]
984+
#[instrument(level = "trace", skip(self, analysis, statement))]
985985
fn visit_after_primary_statement_effect(
986986
&mut self,
987-
results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>,
987+
analysis: &mut ConstAnalysis<'_, 'tcx>,
988988
state: &State<FlatSet<Scalar>>,
989989
statement: &Statement<'tcx>,
990990
location: Location,
@@ -994,12 +994,9 @@ impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx>
994994
// Don't overwrite the assignment if it already uses a constant (to keep the span).
995995
}
996996
StatementKind::Assign(box (place, _)) => {
997-
if let Some(value) = self.try_make_constant(
998-
&mut results.analysis.ecx,
999-
place,
1000-
state,
1001-
&results.analysis.map,
1002-
) {
997+
if let Some(value) =
998+
self.try_make_constant(&mut analysis.ecx, place, state, &analysis.map)
999+
{
10031000
self.patch.assignments.insert(location, value);
10041001
}
10051002
}
@@ -1009,18 +1006,13 @@ impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx>
10091006

10101007
fn visit_after_early_terminator_effect(
10111008
&mut self,
1012-
results: &mut Results<'tcx, ConstAnalysis<'_, 'tcx>>,
1009+
analysis: &mut ConstAnalysis<'_, 'tcx>,
10131010
state: &State<FlatSet<Scalar>>,
10141011
terminator: &Terminator<'tcx>,
10151012
location: Location,
10161013
) {
1017-
OperandCollector {
1018-
state,
1019-
visitor: self,
1020-
ecx: &mut results.analysis.ecx,
1021-
map: &results.analysis.map,
1022-
}
1023-
.visit_terminator(terminator, location);
1014+
OperandCollector { state, visitor: self, ecx: &mut analysis.ecx, map: &analysis.map }
1015+
.visit_terminator(terminator, location);
10241016
}
10251017
}
10261018

0 commit comments

Comments
 (0)