Skip to content

Commit 63e7cc1

Browse files
committed
Make results immutable.
Because most of them are. The one exception is `ConstAnalysis`, which gains a `RefCell` to provide interior mutability. This is a bit annoying, but I think it's worth inconveniencing the one analysis that requires mutability in exchange for making the interface simpler for all the other analyses.
1 parent 039b562 commit 63e7cc1

File tree

9 files changed

+70
-59
lines changed

9 files changed

+70
-59
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
602602

603603
fn visit_statement_before_primary_effect(
604604
&mut self,
605-
_results: &mut R,
605+
_results: &R,
606606
state: &BorrowckDomain<'a, 'tcx>,
607607
stmt: &'a Statement<'tcx>,
608608
location: Location,
@@ -672,7 +672,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
672672

673673
fn visit_terminator_before_primary_effect(
674674
&mut self,
675-
_results: &mut R,
675+
_results: &R,
676676
state: &BorrowckDomain<'a, 'tcx>,
677677
term: &'a Terminator<'tcx>,
678678
loc: Location,
@@ -785,7 +785,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
785785

786786
fn visit_terminator_after_primary_effect(
787787
&mut self,
788-
_results: &mut R,
788+
_results: &R,
789789
state: &BorrowckDomain<'a, 'tcx>,
790790
term: &'a Terminator<'tcx>,
791791
loc: Location,

compiler/rustc_mir_dataflow/src/framework/cursor.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ where
8383
&self.results
8484
}
8585

86-
/// Returns the underlying `Results`.
87-
pub fn mut_results(&mut self) -> &mut Results<'tcx, A> {
88-
&mut self.results
89-
}
90-
9186
/// Returns the `Analysis` used to generate the underlying `Results`.
9287
pub fn analysis(&self) -> &A {
9388
&self.results.analysis

compiler/rustc_mir_dataflow/src/framework/direction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait Direction {
3737
state: &mut D,
3838
block: BasicBlock,
3939
block_data: &'mir mir::BasicBlockData<'tcx>,
40-
results: &mut R,
40+
results: &R,
4141
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
4242
) where
4343
R: ResultsVisitable<'tcx, Domain = D>;
@@ -161,7 +161,7 @@ impl Direction for Backward {
161161
state: &mut D,
162162
block: BasicBlock,
163163
block_data: &'mir mir::BasicBlockData<'tcx>,
164-
results: &mut R,
164+
results: &R,
165165
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
166166
) where
167167
R: ResultsVisitable<'tcx, Domain = D>,
@@ -393,7 +393,7 @@ impl Direction for Forward {
393393
state: &mut F,
394394
block: BasicBlock,
395395
block_data: &'mir mir::BasicBlockData<'tcx>,
396-
results: &mut R,
396+
results: &R,
397397
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = F>,
398398
) where
399399
R: ResultsVisitable<'tcx, Domain = F>,

compiler/rustc_mir_dataflow/src/framework/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ where
5252
}
5353

5454
pub fn visit_with<'mir>(
55-
&mut self,
55+
&self,
5656
body: &'mir mir::Body<'tcx>,
5757
blocks: impl IntoIterator<Item = BasicBlock>,
5858
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, Domain = A::Domain>,

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,8 @@ where
406406
w: &mut impl io::Write,
407407
block: BasicBlock,
408408
) -> io::Result<()> {
409-
let diffs = StateDiffCollector::run(
410-
self.results.body(),
411-
block,
412-
self.results.mut_results(),
413-
self.style,
414-
);
409+
let diffs =
410+
StateDiffCollector::run(self.results.body(), block, self.results.results(), self.style);
415411

416412
let mut diffs_before = diffs.before.map(|v| v.into_iter());
417413
let mut diffs_after = diffs.after.into_iter();
@@ -521,7 +517,7 @@ impl<D> StateDiffCollector<D> {
521517
fn run<'tcx, A>(
522518
body: &mir::Body<'tcx>,
523519
block: BasicBlock,
524-
results: &mut Results<'tcx, A>,
520+
results: &Results<'tcx, A>,
525521
style: OutputStyle,
526522
) -> Self
527523
where
@@ -560,7 +556,7 @@ where
560556

561557
fn visit_statement_before_primary_effect(
562558
&mut self,
563-
results: &mut Results<'tcx, A>,
559+
results: &Results<'tcx, A>,
564560
state: &Self::Domain,
565561
_statement: &mir::Statement<'tcx>,
566562
_location: Location,
@@ -573,7 +569,7 @@ where
573569

574570
fn visit_statement_after_primary_effect(
575571
&mut self,
576-
results: &mut Results<'tcx, A>,
572+
results: &Results<'tcx, A>,
577573
state: &Self::Domain,
578574
_statement: &mir::Statement<'tcx>,
579575
_location: Location,
@@ -584,7 +580,7 @@ where
584580

585581
fn visit_terminator_before_primary_effect(
586582
&mut self,
587-
results: &mut Results<'tcx, A>,
583+
results: &Results<'tcx, A>,
588584
state: &Self::Domain,
589585
_terminator: &mir::Terminator<'tcx>,
590586
_location: Location,
@@ -597,7 +593,7 @@ where
597593

598594
fn visit_terminator_after_primary_effect(
599595
&mut self,
600-
results: &mut Results<'tcx, A>,
596+
results: &Results<'tcx, A>,
601597
state: &Self::Domain,
602598
_terminator: &mir::Terminator<'tcx>,
603599
_location: Location,

compiler/rustc_mir_dataflow/src/framework/visitor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::{Analysis, Direction, Results};
77
pub fn visit_results<'mir, 'tcx, D, R>(
88
body: &'mir mir::Body<'tcx>,
99
blocks: impl IntoIterator<Item = BasicBlock>,
10-
results: &mut R,
10+
results: &R,
1111
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
1212
) where
1313
R: ResultsVisitable<'tcx, Domain = D>,
@@ -37,7 +37,7 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
3737
/// its `statement_effect`.
3838
fn visit_statement_before_primary_effect(
3939
&mut self,
40-
_results: &mut R,
40+
_results: &R,
4141
_state: &Self::Domain,
4242
_statement: &'mir mir::Statement<'tcx>,
4343
_location: Location,
@@ -48,7 +48,7 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
4848
/// statement applied to `state`.
4949
fn visit_statement_after_primary_effect(
5050
&mut self,
51-
_results: &mut R,
51+
_results: &R,
5252
_state: &Self::Domain,
5353
_statement: &'mir mir::Statement<'tcx>,
5454
_location: Location,
@@ -59,7 +59,7 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
5959
/// its `terminator_effect`.
6060
fn visit_terminator_before_primary_effect(
6161
&mut self,
62-
_results: &mut R,
62+
_results: &R,
6363
_state: &Self::Domain,
6464
_terminator: &'mir mir::Terminator<'tcx>,
6565
_location: Location,
@@ -72,7 +72,7 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
7272
/// The `call_return_effect` (if one exists) will *not* be applied to `state`.
7373
fn visit_terminator_after_primary_effect(
7474
&mut self,
75-
_results: &mut R,
75+
_results: &R,
7676
_state: &Self::Domain,
7777
_terminator: &'mir mir::Terminator<'tcx>,
7878
_location: Location,

compiler/rustc_mir_dataflow/src/points.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ where
128128

129129
fn visit_statement_after_primary_effect(
130130
&mut self,
131-
_results: &mut R,
131+
_results: &R,
132132
state: &Self::Domain,
133133
_statement: &'mir mir::Statement<'tcx>,
134134
location: Location,
@@ -142,7 +142,7 @@ where
142142

143143
fn visit_terminator_after_primary_effect(
144144
&mut self,
145-
_results: &mut R,
145+
_results: &R,
146146
state: &Self::Domain,
147147
_terminator: &'mir mir::Terminator<'tcx>,
148148
location: Location,

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
888888

889889
fn visit_statement_before_primary_effect(
890890
&mut self,
891-
_results: &mut R,
891+
_results: &R,
892892
state: &Self::Domain,
893893
_statement: &'a Statement<'tcx>,
894894
loc: Location,
@@ -898,7 +898,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
898898

899899
fn visit_terminator_before_primary_effect(
900900
&mut self,
901-
_results: &mut R,
901+
_results: &R,
902902
state: &Self::Domain,
903903
_terminator: &'a Terminator<'tcx>,
904904
loc: Location,

0 commit comments

Comments
 (0)