Skip to content

Commit c904c6a

Browse files
committed
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.
1 parent 3350edf commit c904c6a

File tree

10 files changed

+91
-201
lines changed

10 files changed

+91
-201
lines changed

compiler/rustc_borrowck/src/lib.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_mir_dataflow::impls::{
4242
use rustc_mir_dataflow::move_paths::{
4343
InitIndex, InitLocation, LookupResult, MoveData, MoveOutIndex, MovePathIndex,
4444
};
45-
use rustc_mir_dataflow::{Analysis, EntrySets, Results};
45+
use rustc_mir_dataflow::{Analysis, EntrySets, Results, ResultsVisitor, visit_results};
4646
use rustc_session::lint::builtin::UNUSED_MUT;
4747
use rustc_span::{Span, Symbol};
4848
use smallvec::SmallVec;
@@ -318,7 +318,7 @@ fn do_mir_borrowck<'tcx>(
318318
mbcx.report_region_errors(nll_errors);
319319

320320
let mut flow_results = get_flow_results(tcx, body, &move_data, &borrow_set, &regioncx);
321-
rustc_mir_dataflow::visit_results(
321+
visit_results(
322322
body,
323323
traversal::reverse_postorder(body).map(|(bb, _)| bb),
324324
&mut flow_results,
@@ -607,14 +607,10 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
607607
// 2. loans made in overlapping scopes do not conflict
608608
// 3. assignments do not affect things loaned out as immutable
609609
// 4. moves do not affect things loaned out in any way
610-
impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
611-
for MirBorrowckCtxt<'a, '_, 'tcx>
612-
{
613-
type Domain = BorrowckDomain<'a, 'tcx>;
614-
610+
impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> {
615611
fn visit_statement_before_primary_effect(
616612
&mut self,
617-
_results: &mut R,
613+
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
618614
state: &BorrowckDomain<'a, 'tcx>,
619615
stmt: &'a Statement<'tcx>,
620616
location: Location,
@@ -686,7 +682,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
686682

687683
fn visit_terminator_before_primary_effect(
688684
&mut self,
689-
_results: &mut R,
685+
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
690686
state: &BorrowckDomain<'a, 'tcx>,
691687
term: &'a Terminator<'tcx>,
692688
loc: Location,
@@ -799,7 +795,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
799795

800796
fn visit_terminator_after_primary_effect(
801797
&mut self,
802-
_results: &mut R,
798+
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
803799
state: &BorrowckDomain<'a, 'tcx>,
804800
term: &'a Terminator<'tcx>,
805801
loc: Location,

compiler/rustc_mir_dataflow/src/framework/direction.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use rustc_middle::mir::{
44
self, BasicBlock, CallReturnPlaces, Location, SwitchTargets, TerminatorEdges,
55
};
66

7-
use super::visitor::{ResultsVisitable, ResultsVisitor};
8-
use super::{Analysis, Effect, EffectIndex, SwitchIntTarget};
7+
use super::visitor::ResultsVisitor;
8+
use super::{Analysis, Effect, EffectIndex, Results, SwitchIntTarget};
99

1010
pub trait Direction {
1111
const IS_FORWARD: bool;
@@ -33,14 +33,14 @@ pub trait Direction {
3333
where
3434
A: Analysis<'tcx>;
3535

36-
fn visit_results_in_block<'mir, 'tcx, D, R>(
37-
state: &mut D,
36+
fn visit_results_in_block<'mir, 'tcx, A>(
37+
state: &mut A::Domain,
3838
block: BasicBlock,
3939
block_data: &'mir mir::BasicBlockData<'tcx>,
40-
results: &mut R,
41-
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
40+
results: &mut Results<'tcx, A>,
41+
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
4242
) where
43-
R: ResultsVisitable<'tcx, Domain = D>;
43+
A: Analysis<'tcx>;
4444

4545
fn join_state_into_successors_of<'tcx, A>(
4646
analysis: &mut A,
@@ -53,7 +53,7 @@ pub trait Direction {
5353
A: Analysis<'tcx>;
5454
}
5555

56-
/// Dataflow that runs from the exit of a block (the terminator), to its entry (the first statement).
56+
/// Dataflow that runs from the exit of a block (terminator), to its entry (the first statement).
5757
pub struct Backward;
5858

5959
impl Direction for Backward {
@@ -157,32 +157,32 @@ impl Direction for Backward {
157157
analysis.apply_statement_effect(state, statement, location);
158158
}
159159

160-
fn visit_results_in_block<'mir, 'tcx, D, R>(
161-
state: &mut D,
160+
fn visit_results_in_block<'mir, 'tcx, A>(
161+
state: &mut A::Domain,
162162
block: BasicBlock,
163163
block_data: &'mir mir::BasicBlockData<'tcx>,
164-
results: &mut R,
165-
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
164+
results: &mut Results<'tcx, A>,
165+
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
166166
) where
167-
R: ResultsVisitable<'tcx, Domain = D>,
167+
A: Analysis<'tcx>,
168168
{
169-
results.reset_to_block_entry(state, block);
169+
state.clone_from(results.entry_set_for_block(block));
170170

171171
vis.visit_block_end(state);
172172

173173
// Terminator
174174
let loc = Location { block, statement_index: block_data.statements.len() };
175175
let term = block_data.terminator();
176-
results.reconstruct_before_terminator_effect(state, term, loc);
176+
results.analysis.apply_before_terminator_effect(state, term, loc);
177177
vis.visit_terminator_before_primary_effect(results, state, term, loc);
178-
results.reconstruct_terminator_effect(state, term, loc);
178+
results.analysis.apply_terminator_effect(state, term, loc);
179179
vis.visit_terminator_after_primary_effect(results, state, term, loc);
180180

181181
for (statement_index, stmt) in block_data.statements.iter().enumerate().rev() {
182182
let loc = Location { block, statement_index };
183-
results.reconstruct_before_statement_effect(state, stmt, loc);
183+
results.analysis.apply_before_statement_effect(state, stmt, loc);
184184
vis.visit_statement_before_primary_effect(results, state, stmt, loc);
185-
results.reconstruct_statement_effect(state, stmt, loc);
185+
results.analysis.apply_statement_effect(state, stmt, loc);
186186
vis.visit_statement_after_primary_effect(results, state, stmt, loc);
187187
}
188188

@@ -389,32 +389,32 @@ impl Direction for Forward {
389389
}
390390
}
391391

392-
fn visit_results_in_block<'mir, 'tcx, F, R>(
393-
state: &mut F,
392+
fn visit_results_in_block<'mir, 'tcx, A>(
393+
state: &mut A::Domain,
394394
block: BasicBlock,
395395
block_data: &'mir mir::BasicBlockData<'tcx>,
396-
results: &mut R,
397-
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = F>,
396+
results: &mut Results<'tcx, A>,
397+
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
398398
) where
399-
R: ResultsVisitable<'tcx, Domain = F>,
399+
A: Analysis<'tcx>,
400400
{
401-
results.reset_to_block_entry(state, block);
401+
state.clone_from(results.entry_set_for_block(block));
402402

403403
vis.visit_block_start(state);
404404

405405
for (statement_index, stmt) in block_data.statements.iter().enumerate() {
406406
let loc = Location { block, statement_index };
407-
results.reconstruct_before_statement_effect(state, stmt, loc);
407+
results.analysis.apply_before_statement_effect(state, stmt, loc);
408408
vis.visit_statement_before_primary_effect(results, state, stmt, loc);
409-
results.reconstruct_statement_effect(state, stmt, loc);
409+
results.analysis.apply_statement_effect(state, stmt, loc);
410410
vis.visit_statement_after_primary_effect(results, state, stmt, loc);
411411
}
412412

413413
let loc = Location { block, statement_index: block_data.statements.len() };
414414
let term = block_data.terminator();
415-
results.reconstruct_before_terminator_effect(state, term, loc);
415+
results.analysis.apply_before_terminator_effect(state, term, loc);
416416
vis.visit_terminator_before_primary_effect(results, state, term, loc);
417-
results.reconstruct_terminator_effect(state, term, loc);
417+
results.analysis.apply_terminator_effect(state, term, loc);
418418
vis.visit_terminator_after_primary_effect(results, state, term, loc);
419419

420420
vis.visit_block_end(state);

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -544,20 +544,18 @@ impl<D> StateDiffCollector<D> {
544544
}
545545
}
546546

547-
impl<'tcx, A> ResultsVisitor<'_, 'tcx, Results<'tcx, A>> for StateDiffCollector<A::Domain>
547+
impl<'tcx, A> ResultsVisitor<'_, 'tcx, A> for StateDiffCollector<A::Domain>
548548
where
549549
A: Analysis<'tcx>,
550550
A::Domain: DebugWithContext<A>,
551551
{
552-
type Domain = A::Domain;
553-
554-
fn visit_block_start(&mut self, state: &Self::Domain) {
552+
fn visit_block_start(&mut self, state: &A::Domain) {
555553
if A::Direction::IS_FORWARD {
556554
self.prev_state.clone_from(state);
557555
}
558556
}
559557

560-
fn visit_block_end(&mut self, state: &Self::Domain) {
558+
fn visit_block_end(&mut self, state: &A::Domain) {
561559
if A::Direction::IS_BACKWARD {
562560
self.prev_state.clone_from(state);
563561
}
@@ -566,7 +564,7 @@ where
566564
fn visit_statement_before_primary_effect(
567565
&mut self,
568566
results: &mut Results<'tcx, A>,
569-
state: &Self::Domain,
567+
state: &A::Domain,
570568
_statement: &mir::Statement<'tcx>,
571569
_location: Location,
572570
) {
@@ -579,7 +577,7 @@ where
579577
fn visit_statement_after_primary_effect(
580578
&mut self,
581579
results: &mut Results<'tcx, A>,
582-
state: &Self::Domain,
580+
state: &A::Domain,
583581
_statement: &mir::Statement<'tcx>,
584582
_location: Location,
585583
) {
@@ -590,7 +588,7 @@ where
590588
fn visit_terminator_before_primary_effect(
591589
&mut self,
592590
results: &mut Results<'tcx, A>,
593-
state: &Self::Domain,
591+
state: &A::Domain,
594592
_terminator: &mir::Terminator<'tcx>,
595593
_location: Location,
596594
) {
@@ -603,7 +601,7 @@ where
603601
fn visit_terminator_after_primary_effect(
604602
&mut self,
605603
results: &mut Results<'tcx, A>,
606-
state: &Self::Domain,
604+
state: &A::Domain,
607605
_terminator: &mir::Terminator<'tcx>,
608606
_location: Location,
609607
) {

compiler/rustc_mir_dataflow/src/framework/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub use self::cursor::ResultsCursor;
5656
pub use self::direction::{Backward, Direction, Forward};
5757
pub use self::lattice::{JoinSemiLattice, MaybeReachable};
5858
pub use self::results::{EntrySets, Results};
59-
pub use self::visitor::{ResultsVisitable, ResultsVisitor, visit_results};
59+
pub use self::visitor::{ResultsVisitor, visit_results};
6060

6161
/// Analysis domains are all bitsets of various kinds. This trait holds
6262
/// operations needed by all of them.

compiler/rustc_mir_dataflow/src/framework/results.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ where
5151
&mut self,
5252
body: &'mir mir::Body<'tcx>,
5353
blocks: impl IntoIterator<Item = BasicBlock>,
54-
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, Domain = A::Domain>,
54+
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
5555
) {
5656
visit_results(body, blocks, self, vis)
5757
}
5858

5959
pub fn visit_reachable_with<'mir>(
6060
&mut self,
6161
body: &'mir mir::Body<'tcx>,
62-
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, Domain = A::Domain>,
62+
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
6363
) {
6464
let blocks = traversal::reachable(body);
6565
visit_results(body, blocks.map(|(bb, _)| bb), self, vis)

0 commit comments

Comments
 (0)