Skip to content

Commit 1d56943

Browse files
committed
Rename some Analysis and ResultsVisitor methods.
The words "before" and "after" have an obvious temporal meaning, e.g. `seek_before_primary_effect`, `visit_statement_{before,after}_primary_effect`. But "before" is also used to name the effect that occurs before the primary effect of a statement/terminator; this is `Effect::Before`. This leads to the confusing possibility of talking about things happening "before/after the before event". This commit removes this awkward overloading of "before" by renaming `Effect::Before` as `Effect::Early`. It also renames some of the `Analysis` and `ResultsVisitor` methods to be more consistent. Here are the before and after names: - `Effect::{Before,Primary}` -> `Effect::{Early,Primary}` - `apply_before_statement_effect` -> `apply_early_statement_effect` - `apply_statement_effect` -> `apply_primary_statement_effect` - `visit_statement_before_primary_effect` -> `visit_after_early_statement_effect` - `visit_statement_after_primary_effect` -> `visit_after_primary_statement_effect` (And s/statement/terminator/ for all the terminator events.)
1 parent 119fbd3 commit 1d56943

File tree

16 files changed

+148
-150
lines changed

16 files changed

+148
-150
lines changed

Diff for: compiler/rustc_borrowck/src/dataflow.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -44,48 +44,48 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
4444
unreachable!();
4545
}
4646

47-
fn apply_before_statement_effect(
47+
fn apply_early_statement_effect(
4848
&mut self,
4949
state: &mut Self::Domain,
5050
stmt: &mir::Statement<'tcx>,
5151
loc: Location,
5252
) {
53-
self.borrows.apply_before_statement_effect(&mut state.borrows, stmt, loc);
54-
self.uninits.apply_before_statement_effect(&mut state.uninits, stmt, loc);
55-
self.ever_inits.apply_before_statement_effect(&mut state.ever_inits, stmt, loc);
53+
self.borrows.apply_early_statement_effect(&mut state.borrows, stmt, loc);
54+
self.uninits.apply_early_statement_effect(&mut state.uninits, stmt, loc);
55+
self.ever_inits.apply_early_statement_effect(&mut state.ever_inits, stmt, loc);
5656
}
5757

58-
fn apply_statement_effect(
58+
fn apply_primary_statement_effect(
5959
&mut self,
6060
state: &mut Self::Domain,
6161
stmt: &mir::Statement<'tcx>,
6262
loc: Location,
6363
) {
64-
self.borrows.apply_statement_effect(&mut state.borrows, stmt, loc);
65-
self.uninits.apply_statement_effect(&mut state.uninits, stmt, loc);
66-
self.ever_inits.apply_statement_effect(&mut state.ever_inits, stmt, loc);
64+
self.borrows.apply_primary_statement_effect(&mut state.borrows, stmt, loc);
65+
self.uninits.apply_primary_statement_effect(&mut state.uninits, stmt, loc);
66+
self.ever_inits.apply_primary_statement_effect(&mut state.ever_inits, stmt, loc);
6767
}
6868

69-
fn apply_before_terminator_effect(
69+
fn apply_early_terminator_effect(
7070
&mut self,
7171
state: &mut Self::Domain,
7272
term: &mir::Terminator<'tcx>,
7373
loc: Location,
7474
) {
75-
self.borrows.apply_before_terminator_effect(&mut state.borrows, term, loc);
76-
self.uninits.apply_before_terminator_effect(&mut state.uninits, term, loc);
77-
self.ever_inits.apply_before_terminator_effect(&mut state.ever_inits, term, loc);
75+
self.borrows.apply_early_terminator_effect(&mut state.borrows, term, loc);
76+
self.uninits.apply_early_terminator_effect(&mut state.uninits, term, loc);
77+
self.ever_inits.apply_early_terminator_effect(&mut state.ever_inits, term, loc);
7878
}
7979

80-
fn apply_terminator_effect<'mir>(
80+
fn apply_primary_terminator_effect<'mir>(
8181
&mut self,
8282
state: &mut Self::Domain,
8383
term: &'mir mir::Terminator<'tcx>,
8484
loc: Location,
8585
) -> TerminatorEdges<'mir, 'tcx> {
86-
self.borrows.apply_terminator_effect(&mut state.borrows, term, loc);
87-
self.uninits.apply_terminator_effect(&mut state.uninits, term, loc);
88-
self.ever_inits.apply_terminator_effect(&mut state.ever_inits, term, loc);
86+
self.borrows.apply_primary_terminator_effect(&mut state.borrows, term, loc);
87+
self.uninits.apply_primary_terminator_effect(&mut state.uninits, term, loc);
88+
self.ever_inits.apply_primary_terminator_effect(&mut state.ever_inits, term, loc);
8989

9090
// This return value doesn't matter. It's only used by `iterate_to_fixpoint`, which this
9191
// analysis doesn't use.
@@ -593,7 +593,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
593593
// function execution, so this method has no effect.
594594
}
595595

596-
fn apply_before_statement_effect(
596+
fn apply_early_statement_effect(
597597
&mut self,
598598
state: &mut Self::Domain,
599599
_statement: &mir::Statement<'tcx>,
@@ -602,7 +602,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
602602
self.kill_loans_out_of_scope_at_location(state, location);
603603
}
604604

605-
fn apply_statement_effect(
605+
fn apply_primary_statement_effect(
606606
&mut self,
607607
state: &mut Self::Domain,
608608
stmt: &mir::Statement<'tcx>,
@@ -651,7 +651,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
651651
}
652652
}
653653

654-
fn apply_before_terminator_effect(
654+
fn apply_early_terminator_effect(
655655
&mut self,
656656
state: &mut Self::Domain,
657657
_terminator: &mir::Terminator<'tcx>,
@@ -660,7 +660,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
660660
self.kill_loans_out_of_scope_at_location(state, location);
661661
}
662662

663-
fn apply_terminator_effect<'mir>(
663+
fn apply_primary_terminator_effect<'mir>(
664664
&mut self,
665665
state: &mut Self::Domain,
666666
terminator: &'mir mir::Terminator<'tcx>,

Diff for: compiler/rustc_borrowck/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
600600
// 3. assignments do not affect things loaned out as immutable
601601
// 4. moves do not affect things loaned out in any way
602602
impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> {
603-
fn visit_statement_before_primary_effect(
603+
fn visit_after_early_statement_effect(
604604
&mut self,
605605
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
606606
state: &BorrowckDomain,
@@ -674,7 +674,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
674674
}
675675
}
676676

677-
fn visit_terminator_before_primary_effect(
677+
fn visit_after_early_terminator_effect(
678678
&mut self,
679679
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
680680
state: &BorrowckDomain,
@@ -787,7 +787,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
787787
}
788788
}
789789

790-
fn visit_terminator_after_primary_effect(
790+
fn visit_after_primary_terminator_effect(
791791
&mut self,
792792
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
793793
state: &BorrowckDomain,

Diff for: compiler/rustc_const_eval/src/check_consts/resolver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ where
329329
self.transfer_function(state).initialize_state();
330330
}
331331

332-
fn apply_statement_effect(
332+
fn apply_primary_statement_effect(
333333
&mut self,
334334
state: &mut Self::Domain,
335335
statement: &mir::Statement<'tcx>,
@@ -338,7 +338,7 @@ where
338338
self.transfer_function(state).visit_statement(statement, location);
339339
}
340340

341-
fn apply_terminator_effect<'mir>(
341+
fn apply_primary_terminator_effect<'mir>(
342342
&mut self,
343343
state: &mut Self::Domain,
344344
terminator: &'mir mir::Terminator<'tcx>,

Diff for: compiler/rustc_mir_dataflow/src/framework/cursor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ where
179179
/// Advances the cursor to hold the dataflow state at `target` before its "primary" effect is
180180
/// applied.
181181
///
182-
/// The "before" effect at the target location *will be* applied.
182+
/// The "early" effect at the target location *will be* applied.
183183
pub fn seek_before_primary_effect(&mut self, target: Location) {
184-
self.seek_after(target, Effect::Before)
184+
self.seek_after(target, Effect::Early)
185185
}
186186

187187
/// Advances the cursor to hold the dataflow state at `target` after its "primary" effect is
188188
/// applied.
189189
///
190-
/// The "before" effect at the target location will be applied as well.
190+
/// The "early" effect at the target location will be applied as well.
191191
pub fn seek_after_primary_effect(&mut self, target: Location) {
192192
self.seek_after(target, Effect::Primary)
193193
}
@@ -222,12 +222,12 @@ where
222222
#[rustfmt::skip]
223223
let next_effect = if A::Direction::IS_FORWARD {
224224
self.pos.curr_effect_index.map_or_else(
225-
|| Effect::Before.at_index(0),
225+
|| Effect::Early.at_index(0),
226226
EffectIndex::next_in_forward_order,
227227
)
228228
} else {
229229
self.pos.curr_effect_index.map_or_else(
230-
|| Effect::Before.at_index(block_data.statements.len()),
230+
|| Effect::Early.at_index(block_data.statements.len()),
231231
EffectIndex::next_in_backward_order,
232232
)
233233
};

Diff for: compiler/rustc_mir_dataflow/src/framework/direction.rs

+44-44
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ impl Direction for Backward {
6666
{
6767
let terminator = block_data.terminator();
6868
let location = Location { block, statement_index: block_data.statements.len() };
69-
analysis.apply_before_terminator_effect(state, terminator, location);
70-
analysis.apply_terminator_effect(state, terminator, location);
69+
analysis.apply_early_terminator_effect(state, terminator, location);
70+
analysis.apply_primary_terminator_effect(state, terminator, location);
7171
for (statement_index, statement) in block_data.statements.iter().enumerate().rev() {
7272
let location = Location { block, statement_index };
73-
analysis.apply_before_statement_effect(state, statement, location);
74-
analysis.apply_statement_effect(state, statement, location);
73+
analysis.apply_early_statement_effect(state, statement, location);
74+
analysis.apply_primary_statement_effect(state, statement, location);
7575
}
7676

7777
let exit_state = state;
@@ -159,14 +159,14 @@ impl Direction for Backward {
159159
let location = Location { block, statement_index: from.statement_index };
160160
let terminator = block_data.terminator();
161161

162-
if from.effect == Effect::Before {
163-
analysis.apply_before_terminator_effect(state, terminator, location);
164-
if to == Effect::Before.at_index(terminator_index) {
162+
if from.effect == Effect::Early {
163+
analysis.apply_early_terminator_effect(state, terminator, location);
164+
if to == Effect::Early.at_index(terminator_index) {
165165
return;
166166
}
167167
}
168168

169-
analysis.apply_terminator_effect(state, terminator, location);
169+
analysis.apply_primary_terminator_effect(state, terminator, location);
170170
if to == Effect::Primary.at_index(terminator_index) {
171171
return;
172172
}
@@ -180,37 +180,37 @@ impl Direction for Backward {
180180
let location = Location { block, statement_index: from.statement_index };
181181
let statement = &block_data.statements[from.statement_index];
182182

183-
analysis.apply_statement_effect(state, statement, location);
183+
analysis.apply_primary_statement_effect(state, statement, location);
184184
if to == Effect::Primary.at_index(from.statement_index) {
185185
return;
186186
}
187187

188188
from.statement_index - 1
189189
}
190190

191-
Effect::Before => from.statement_index,
191+
Effect::Early => from.statement_index,
192192
};
193193

194194
// Handle all statements between `first_unapplied_idx` and `to.statement_index`.
195195

196196
for statement_index in (to.statement_index..next_effect).rev().map(|i| i + 1) {
197197
let location = Location { block, statement_index };
198198
let statement = &block_data.statements[statement_index];
199-
analysis.apply_before_statement_effect(state, statement, location);
200-
analysis.apply_statement_effect(state, statement, location);
199+
analysis.apply_early_statement_effect(state, statement, location);
200+
analysis.apply_primary_statement_effect(state, statement, location);
201201
}
202202

203203
// Handle the statement at `to`.
204204

205205
let location = Location { block, statement_index: to.statement_index };
206206
let statement = &block_data.statements[to.statement_index];
207-
analysis.apply_before_statement_effect(state, statement, location);
207+
analysis.apply_early_statement_effect(state, statement, location);
208208

209-
if to.effect == Effect::Before {
209+
if to.effect == Effect::Early {
210210
return;
211211
}
212212

213-
analysis.apply_statement_effect(state, statement, location);
213+
analysis.apply_primary_statement_effect(state, statement, location);
214214
}
215215

216216
fn visit_results_in_block<'mir, 'tcx, A>(
@@ -228,17 +228,17 @@ impl Direction for Backward {
228228

229229
let loc = Location { block, statement_index: block_data.statements.len() };
230230
let term = block_data.terminator();
231-
results.analysis.apply_before_terminator_effect(state, term, loc);
232-
vis.visit_terminator_before_primary_effect(results, state, term, loc);
233-
results.analysis.apply_terminator_effect(state, term, loc);
234-
vis.visit_terminator_after_primary_effect(results, state, term, loc);
231+
results.analysis.apply_early_terminator_effect(state, term, loc);
232+
vis.visit_after_early_terminator_effect(results, state, term, loc);
233+
results.analysis.apply_primary_terminator_effect(state, term, loc);
234+
vis.visit_after_primary_terminator_effect(results, state, term, loc);
235235

236236
for (statement_index, stmt) in block_data.statements.iter().enumerate().rev() {
237237
let loc = Location { block, statement_index };
238-
results.analysis.apply_before_statement_effect(state, stmt, loc);
239-
vis.visit_statement_before_primary_effect(results, state, stmt, loc);
240-
results.analysis.apply_statement_effect(state, stmt, loc);
241-
vis.visit_statement_after_primary_effect(results, state, stmt, loc);
238+
results.analysis.apply_early_statement_effect(state, stmt, loc);
239+
vis.visit_after_early_statement_effect(results, state, stmt, loc);
240+
results.analysis.apply_primary_statement_effect(state, stmt, loc);
241+
vis.visit_after_primary_statement_effect(results, state, stmt, loc);
242242
}
243243

244244
vis.visit_block_start(state);
@@ -294,13 +294,13 @@ impl Direction for Forward {
294294
{
295295
for (statement_index, statement) in block_data.statements.iter().enumerate() {
296296
let location = Location { block, statement_index };
297-
analysis.apply_before_statement_effect(state, statement, location);
298-
analysis.apply_statement_effect(state, statement, location);
297+
analysis.apply_early_statement_effect(state, statement, location);
298+
analysis.apply_primary_statement_effect(state, statement, location);
299299
}
300300
let terminator = block_data.terminator();
301301
let location = Location { block, statement_index: block_data.statements.len() };
302-
analysis.apply_before_terminator_effect(state, terminator, location);
303-
let edges = analysis.apply_terminator_effect(state, terminator, location);
302+
analysis.apply_early_terminator_effect(state, terminator, location);
303+
let edges = analysis.apply_primary_terminator_effect(state, terminator, location);
304304

305305
let exit_state = state;
306306
match edges {
@@ -368,21 +368,21 @@ impl Direction for Forward {
368368
// after effect, do so now and start the loop below from the next statement.
369369

370370
let first_unapplied_index = match from.effect {
371-
Effect::Before => from.statement_index,
371+
Effect::Early => from.statement_index,
372372

373373
Effect::Primary if from.statement_index == terminator_index => {
374374
debug_assert_eq!(from, to);
375375

376376
let location = Location { block, statement_index: terminator_index };
377377
let terminator = block_data.terminator();
378-
analysis.apply_terminator_effect(state, terminator, location);
378+
analysis.apply_primary_terminator_effect(state, terminator, location);
379379
return;
380380
}
381381

382382
Effect::Primary => {
383383
let location = Location { block, statement_index: from.statement_index };
384384
let statement = &block_data.statements[from.statement_index];
385-
analysis.apply_statement_effect(state, statement, location);
385+
analysis.apply_primary_statement_effect(state, statement, location);
386386

387387
// If we only needed to apply the after effect of the statement at `idx`, we are
388388
// done.
@@ -399,26 +399,26 @@ impl Direction for Forward {
399399
for statement_index in first_unapplied_index..to.statement_index {
400400
let location = Location { block, statement_index };
401401
let statement = &block_data.statements[statement_index];
402-
analysis.apply_before_statement_effect(state, statement, location);
403-
analysis.apply_statement_effect(state, statement, location);
402+
analysis.apply_early_statement_effect(state, statement, location);
403+
analysis.apply_primary_statement_effect(state, statement, location);
404404
}
405405

406406
// Handle the statement or terminator at `to`.
407407

408408
let location = Location { block, statement_index: to.statement_index };
409409
if to.statement_index == terminator_index {
410410
let terminator = block_data.terminator();
411-
analysis.apply_before_terminator_effect(state, terminator, location);
411+
analysis.apply_early_terminator_effect(state, terminator, location);
412412

413413
if to.effect == Effect::Primary {
414-
analysis.apply_terminator_effect(state, terminator, location);
414+
analysis.apply_primary_terminator_effect(state, terminator, location);
415415
}
416416
} else {
417417
let statement = &block_data.statements[to.statement_index];
418-
analysis.apply_before_statement_effect(state, statement, location);
418+
analysis.apply_early_statement_effect(state, statement, location);
419419

420420
if to.effect == Effect::Primary {
421-
analysis.apply_statement_effect(state, statement, location);
421+
analysis.apply_primary_statement_effect(state, statement, location);
422422
}
423423
}
424424
}
@@ -438,18 +438,18 @@ impl Direction for Forward {
438438

439439
for (statement_index, stmt) in block_data.statements.iter().enumerate() {
440440
let loc = Location { block, statement_index };
441-
results.analysis.apply_before_statement_effect(state, stmt, loc);
442-
vis.visit_statement_before_primary_effect(results, state, stmt, loc);
443-
results.analysis.apply_statement_effect(state, stmt, loc);
444-
vis.visit_statement_after_primary_effect(results, state, stmt, loc);
441+
results.analysis.apply_early_statement_effect(state, stmt, loc);
442+
vis.visit_after_early_statement_effect(results, state, stmt, loc);
443+
results.analysis.apply_primary_statement_effect(state, stmt, loc);
444+
vis.visit_after_primary_statement_effect(results, state, stmt, loc);
445445
}
446446

447447
let loc = Location { block, statement_index: block_data.statements.len() };
448448
let term = block_data.terminator();
449-
results.analysis.apply_before_terminator_effect(state, term, loc);
450-
vis.visit_terminator_before_primary_effect(results, state, term, loc);
451-
results.analysis.apply_terminator_effect(state, term, loc);
452-
vis.visit_terminator_after_primary_effect(results, state, term, loc);
449+
results.analysis.apply_early_terminator_effect(state, term, loc);
450+
vis.visit_after_early_terminator_effect(results, state, term, loc);
451+
results.analysis.apply_primary_terminator_effect(state, term, loc);
452+
vis.visit_after_primary_terminator_effect(results, state, term, loc);
453453

454454
vis.visit_block_end(state);
455455
}

0 commit comments

Comments
 (0)