Skip to content

Commit afbffe8

Browse files
committed
Make analyses and visitables immutable.
Much nicer.
1 parent 52b90f7 commit afbffe8

File tree

13 files changed

+77
-87
lines changed

13 files changed

+77
-87
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
4444
}
4545

4646
fn reconstruct_before_statement_effect(
47-
&mut self,
47+
&self,
4848
state: &mut Self::Domain,
4949
stmt: &mir::Statement<'tcx>,
5050
loc: Location,
@@ -55,7 +55,7 @@ impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
5555
}
5656

5757
fn reconstruct_statement_effect(
58-
&mut self,
58+
&self,
5959
state: &mut Self::Domain,
6060
stmt: &mir::Statement<'tcx>,
6161
loc: Location,
@@ -66,7 +66,7 @@ impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
6666
}
6767

6868
fn reconstruct_before_terminator_effect(
69-
&mut self,
69+
&self,
7070
state: &mut Self::Domain,
7171
term: &mir::Terminator<'tcx>,
7272
loc: Location,
@@ -77,7 +77,7 @@ impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
7777
}
7878

7979
fn reconstruct_terminator_effect(
80-
&mut self,
80+
&self,
8181
state: &mut Self::Domain,
8282
term: &mir::Terminator<'tcx>,
8383
loc: Location,
@@ -511,7 +511,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
511511
}
512512

513513
fn apply_before_statement_effect(
514-
&mut self,
514+
&self,
515515
trans: &mut Self::Domain,
516516
_statement: &mir::Statement<'tcx>,
517517
location: Location,
@@ -520,7 +520,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
520520
}
521521

522522
fn apply_statement_effect(
523-
&mut self,
523+
&self,
524524
trans: &mut Self::Domain,
525525
stmt: &mir::Statement<'tcx>,
526526
location: Location,
@@ -568,7 +568,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
568568
}
569569

570570
fn apply_before_terminator_effect(
571-
&mut self,
571+
&self,
572572
trans: &mut Self::Domain,
573573
_terminator: &mir::Terminator<'tcx>,
574574
location: Location,
@@ -577,7 +577,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
577577
}
578578

579579
fn apply_terminator_effect<'mir>(
580-
&mut self,
580+
&self,
581581
trans: &mut Self::Domain,
582582
terminator: &'mir mir::Terminator<'tcx>,
583583
_location: Location,

compiler/rustc_const_eval/src/check_consts/resolver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ where
330330
}
331331

332332
fn apply_statement_effect(
333-
&mut self,
333+
&self,
334334
state: &mut Self::Domain,
335335
statement: &mir::Statement<'tcx>,
336336
location: Location,
@@ -339,7 +339,7 @@ where
339339
}
340340

341341
fn apply_terminator_effect<'mir>(
342-
&mut self,
342+
&self,
343343
state: &mut Self::Domain,
344344
terminator: &'mir mir::Terminator<'tcx>,
345345
location: Location,
@@ -349,7 +349,7 @@ where
349349
}
350350

351351
fn apply_call_return_effect(
352-
&mut self,
352+
&self,
353353
state: &mut Self::Domain,
354354
block: BasicBlock,
355355
return_places: CallReturnPlaces<'_, 'tcx>,

compiler/rustc_mir_dataflow/src/framework/cursor.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ where
9393
&self.results.analysis
9494
}
9595

96-
/// Returns the `Analysis` used to generate the underlying `Results`.
97-
pub fn mut_analysis(&mut self) -> &mut A {
98-
&mut self.results.analysis
99-
}
100-
10196
/// Resets the cursor to hold the entry set for the given basic block.
10297
///
10398
/// For forward dataflow analyses, this is the dataflow state prior to the first statement.
@@ -199,7 +194,7 @@ where
199194
let target_effect_index = effect.at_index(target.statement_index);
200195

201196
A::Direction::apply_effects_in_range(
202-
&mut self.results.analysis,
197+
&self.results.analysis,
203198
&mut self.state,
204199
target.block,
205200
block_data,
@@ -214,8 +209,8 @@ where
214209
///
215210
/// This can be used, e.g., to apply the call return effect directly to the cursor without
216211
/// creating an extra copy of the dataflow state.
217-
pub fn apply_custom_effect(&mut self, f: impl FnOnce(&mut A, &mut A::Domain)) {
218-
f(&mut self.results.analysis, &mut self.state);
212+
pub fn apply_custom_effect(&mut self, f: impl FnOnce(&A, &mut A::Domain)) {
213+
f(&self.results.analysis, &mut self.state);
219214
self.state_needs_reset = true;
220215
}
221216
}

compiler/rustc_mir_dataflow/src/framework/direction.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub trait Direction {
1616
///
1717
/// `effects.start()` must precede or equal `effects.end()` in this direction.
1818
fn apply_effects_in_range<'tcx, A>(
19-
analysis: &mut A,
19+
analysis: &A,
2020
state: &mut A::Domain,
2121
block: BasicBlock,
2222
block_data: &mir::BasicBlockData<'tcx>,
@@ -25,7 +25,7 @@ pub trait Direction {
2525
A: Analysis<'tcx>;
2626

2727
fn apply_effects_in_block<'mir, 'tcx, A>(
28-
analysis: &mut A,
28+
analysis: &A,
2929
state: &mut A::Domain,
3030
block: BasicBlock,
3131
block_data: &'mir mir::BasicBlockData<'tcx>,
@@ -43,7 +43,7 @@ pub trait Direction {
4343
R: ResultsVisitable<'tcx, Domain = D>;
4444

4545
fn join_state_into_successors_of<'tcx, A>(
46-
analysis: &mut A,
46+
analysis: &A,
4747
body: &mir::Body<'tcx>,
4848
exit_state: &mut A::Domain,
4949
block: BasicBlock,
@@ -60,7 +60,7 @@ impl Direction for Backward {
6060
const IS_FORWARD: bool = false;
6161

6262
fn apply_effects_in_block<'mir, 'tcx, A>(
63-
analysis: &mut A,
63+
analysis: &A,
6464
state: &mut A::Domain,
6565
block: BasicBlock,
6666
block_data: &'mir mir::BasicBlockData<'tcx>,
@@ -81,7 +81,7 @@ impl Direction for Backward {
8181
}
8282

8383
fn apply_effects_in_range<'tcx, A>(
84-
analysis: &mut A,
84+
analysis: &A,
8585
state: &mut A::Domain,
8686
block: BasicBlock,
8787
block_data: &mir::BasicBlockData<'tcx>,
@@ -190,7 +190,7 @@ impl Direction for Backward {
190190
}
191191

192192
fn join_state_into_successors_of<'tcx, A>(
193-
analysis: &mut A,
193+
analysis: &A,
194194
body: &mir::Body<'tcx>,
195195
exit_state: &mut A::Domain,
196196
bb: BasicBlock,
@@ -297,7 +297,7 @@ impl Direction for Forward {
297297
const IS_FORWARD: bool = true;
298298

299299
fn apply_effects_in_block<'mir, 'tcx, A>(
300-
analysis: &mut A,
300+
analysis: &A,
301301
state: &mut A::Domain,
302302
block: BasicBlock,
303303
block_data: &'mir mir::BasicBlockData<'tcx>,
@@ -317,7 +317,7 @@ impl Direction for Forward {
317317
}
318318

319319
fn apply_effects_in_range<'tcx, A>(
320-
analysis: &mut A,
320+
analysis: &A,
321321
state: &mut A::Domain,
322322
block: BasicBlock,
323323
block_data: &mir::BasicBlockData<'tcx>,
@@ -421,7 +421,7 @@ impl Direction for Forward {
421421
}
422422

423423
fn join_state_into_successors_of<'tcx, A>(
424-
analysis: &mut A,
424+
analysis: &A,
425425
_body: &mir::Body<'tcx>,
426426
exit_state: &mut A::Domain,
427427
bb: BasicBlock,

compiler/rustc_mir_dataflow/src/framework/engine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
where
117117
A::Domain: DebugWithContext<A>,
118118
{
119-
let Engine { mut analysis, body, mut entry_sets, tcx, pass_name } = self;
119+
let Engine { analysis, body, mut entry_sets, tcx, pass_name } = self;
120120

121121
let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_none(body.basic_blocks.len());
122122

@@ -146,10 +146,10 @@ where
146146

147147
// Apply the block transfer function, using the cached one if it exists.
148148
let edges =
149-
A::Direction::apply_effects_in_block(&mut analysis, &mut state, bb, bb_data);
149+
A::Direction::apply_effects_in_block(&analysis, &mut state, bb, bb_data);
150150

151151
A::Direction::join_state_into_successors_of(
152-
&mut analysis,
152+
&analysis,
153153
body,
154154
&mut state,
155155
bb,

compiler/rustc_mir_dataflow/src/framework/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub trait Analysis<'tcx> {
136136

137137
/// Updates the current dataflow state with the effect of evaluating a statement.
138138
fn apply_statement_effect(
139-
&mut self,
139+
&self,
140140
state: &mut Self::Domain,
141141
statement: &mir::Statement<'tcx>,
142142
location: Location,
@@ -149,7 +149,7 @@ pub trait Analysis<'tcx> {
149149
/// *part* of the effect of a statement (e.g. for two-phase borrows). As a general rule,
150150
/// analyses should not implement this without also implementing `apply_statement_effect`.
151151
fn apply_before_statement_effect(
152-
&mut self,
152+
&self,
153153
_state: &mut Self::Domain,
154154
_statement: &mir::Statement<'tcx>,
155155
_location: Location,
@@ -163,7 +163,7 @@ pub trait Analysis<'tcx> {
163163
/// `InitializedPlaces` analyses, the return place for a function call is not marked as
164164
/// initialized here.
165165
fn apply_terminator_effect<'mir>(
166-
&mut self,
166+
&self,
167167
_state: &mut Self::Domain,
168168
terminator: &'mir mir::Terminator<'tcx>,
169169
_location: Location,
@@ -178,7 +178,7 @@ pub trait Analysis<'tcx> {
178178
/// *part* of the effect of a terminator (e.g. for two-phase borrows). As a general rule,
179179
/// analyses should not implement this without also implementing `apply_terminator_effect`.
180180
fn apply_before_terminator_effect(
181-
&mut self,
181+
&self,
182182
_state: &mut Self::Domain,
183183
_terminator: &mir::Terminator<'tcx>,
184184
_location: Location,
@@ -193,7 +193,7 @@ pub trait Analysis<'tcx> {
193193
/// This is separate from `apply_terminator_effect` to properly track state across unwind
194194
/// edges.
195195
fn apply_call_return_effect(
196-
&mut self,
196+
&self,
197197
_state: &mut Self::Domain,
198198
_block: BasicBlock,
199199
_return_places: CallReturnPlaces<'_, 'tcx>,
@@ -214,7 +214,7 @@ pub trait Analysis<'tcx> {
214214
/// engine doesn't need to clone the exit state for a block unless
215215
/// `SwitchIntEdgeEffects::apply` is actually called.
216216
fn apply_switch_int_edge_effects(
217-
&mut self,
217+
&self,
218218
_block: BasicBlock,
219219
_discr: &mir::Operand<'tcx>,
220220
_apply_edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,

compiler/rustc_mir_dataflow/src/framework/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'tcx, D: Direction> Analysis<'tcx> for MockAnalysis<'tcx, D> {
169169
}
170170

171171
fn apply_statement_effect(
172-
&mut self,
172+
&self,
173173
state: &mut Self::Domain,
174174
_statement: &mir::Statement<'tcx>,
175175
location: Location,
@@ -179,7 +179,7 @@ impl<'tcx, D: Direction> Analysis<'tcx> for MockAnalysis<'tcx, D> {
179179
}
180180

181181
fn apply_before_statement_effect(
182-
&mut self,
182+
&self,
183183
state: &mut Self::Domain,
184184
_statement: &mir::Statement<'tcx>,
185185
location: Location,
@@ -189,7 +189,7 @@ impl<'tcx, D: Direction> Analysis<'tcx> for MockAnalysis<'tcx, D> {
189189
}
190190

191191
fn apply_terminator_effect<'mir>(
192-
&mut self,
192+
&self,
193193
state: &mut Self::Domain,
194194
terminator: &'mir mir::Terminator<'tcx>,
195195
location: Location,
@@ -200,7 +200,7 @@ impl<'tcx, D: Direction> Analysis<'tcx> for MockAnalysis<'tcx, D> {
200200
}
201201

202202
fn apply_before_terminator_effect(
203-
&mut self,
203+
&self,
204204
state: &mut Self::Domain,
205205
_terminator: &mir::Terminator<'tcx>,
206206
location: Location,

compiler/rustc_mir_dataflow/src/framework/visitor.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,28 @@ pub trait ResultsVisitable<'tcx> {
9999
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock);
100100

101101
fn reconstruct_before_statement_effect(
102-
&mut self,
102+
&self,
103103
state: &mut Self::Domain,
104104
statement: &mir::Statement<'tcx>,
105105
location: Location,
106106
);
107107

108108
fn reconstruct_statement_effect(
109-
&mut self,
109+
&self,
110110
state: &mut Self::Domain,
111111
statement: &mir::Statement<'tcx>,
112112
location: Location,
113113
);
114114

115115
fn reconstruct_before_terminator_effect(
116-
&mut self,
116+
&self,
117117
state: &mut Self::Domain,
118118
terminator: &mir::Terminator<'tcx>,
119119
location: Location,
120120
);
121121

122122
fn reconstruct_terminator_effect(
123-
&mut self,
123+
&self,
124124
state: &mut Self::Domain,
125125
terminator: &mir::Terminator<'tcx>,
126126
location: Location,
@@ -143,7 +143,7 @@ where
143143
}
144144

145145
fn reconstruct_before_statement_effect(
146-
&mut self,
146+
&self,
147147
state: &mut Self::Domain,
148148
stmt: &mir::Statement<'tcx>,
149149
loc: Location,
@@ -152,7 +152,7 @@ where
152152
}
153153

154154
fn reconstruct_statement_effect(
155-
&mut self,
155+
&self,
156156
state: &mut Self::Domain,
157157
stmt: &mir::Statement<'tcx>,
158158
loc: Location,
@@ -161,7 +161,7 @@ where
161161
}
162162

163163
fn reconstruct_before_terminator_effect(
164-
&mut self,
164+
&self,
165165
state: &mut Self::Domain,
166166
term: &mir::Terminator<'tcx>,
167167
loc: Location,
@@ -170,7 +170,7 @@ where
170170
}
171171

172172
fn reconstruct_terminator_effect(
173-
&mut self,
173+
&self,
174174
state: &mut Self::Domain,
175175
term: &mir::Terminator<'tcx>,
176176
loc: Location,

0 commit comments

Comments
 (0)