Skip to content

Commit 4b364b6

Browse files
committed
Tweak GenKillAnalysis.
`GenKillAnalysis` has five methods that take a transfer function arg: - `statement_effect` - `before_statement_effect` - `terminator_effect` - `before_terminator_effect` - `call_return_effect` All the transfer function args have type `&mut impl GenKill<Self::Idx>`, except for `terminator_effect`, which takes the simpler `Self::Domain`. But only the first two need to be `impl GenKill`. The other three can all be `Self::Domain`, just like `Analysis`. So this commit changes the last two to take `Self::Domain`, making `GenKillAnalysis` and `Analysis` more similar. (Another idea would be to make all these methods `impl GenKill`. But that doesn't work: `MaybeInitializedPlaces::terminator_effect` requires the arg be `Self::Domain` so that `self_is_unwind_dead(place, state)` can be called on it.)
1 parent 0158404 commit 4b364b6

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

compiler/rustc_borrowck/src/dataflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
585585

586586
fn before_terminator_effect(
587587
&mut self,
588-
trans: &mut impl GenKill<Self::Idx>,
588+
trans: &mut Self::Domain,
589589
_terminator: &mir::Terminator<'tcx>,
590590
location: Location,
591591
) {
@@ -612,7 +612,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
612612

613613
fn call_return_effect(
614614
&mut self,
615-
_trans: &mut impl GenKill<Self::Idx>,
615+
_trans: &mut Self::Domain,
616616
_block: mir::BasicBlock,
617617
_return_places: CallReturnPlaces<'_, 'tcx>,
618618
) {

compiler/rustc_mir_dataflow/src/framework/mod.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -248,26 +248,28 @@ pub trait Analysis<'tcx>: AnalysisDomain<'tcx> {
248248

249249
/// A gen/kill dataflow problem.
250250
///
251-
/// Each method in this trait has a corresponding one in `Analysis`. However, these methods only
252-
/// allow modification of the dataflow state via "gen" and "kill" operations. By defining transfer
253-
/// functions for each statement in this way, the transfer function for an entire basic block can
254-
/// be computed efficiently.
251+
/// Each method in this trait has a corresponding one in `Analysis`. However, the first two methods
252+
/// here only allow modification of the dataflow state via "gen" and "kill" operations. By defining
253+
/// transfer functions for each statement in this way, the transfer function for an entire basic
254+
/// block can be computed efficiently. The remaining methods match up with `Analysis` exactly.
255255
///
256-
/// `Analysis` is automatically implemented for all implementers of `GenKillAnalysis`.
256+
/// `Analysis` is automatically implemented for all implementers of `GenKillAnalysis` via a blanket
257+
/// impl below.
257258
pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
258259
type Idx: Idx;
259260

260261
fn domain_size(&self, body: &mir::Body<'tcx>) -> usize;
261262

262-
/// See `Analysis::apply_statement_effect`.
263+
/// See `Analysis::apply_statement_effect`. Note how the second arg differs.
263264
fn statement_effect(
264265
&mut self,
265266
trans: &mut impl GenKill<Self::Idx>,
266267
statement: &mir::Statement<'tcx>,
267268
location: Location,
268269
);
269270

270-
/// See `Analysis::apply_before_statement_effect`.
271+
/// See `Analysis::apply_before_statement_effect`. Note how the second arg
272+
/// differs.
271273
fn before_statement_effect(
272274
&mut self,
273275
_trans: &mut impl GenKill<Self::Idx>,
@@ -287,7 +289,7 @@ pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
287289
/// See `Analysis::apply_before_terminator_effect`.
288290
fn before_terminator_effect(
289291
&mut self,
290-
_trans: &mut impl GenKill<Self::Idx>,
292+
_trans: &mut Self::Domain,
291293
_terminator: &mir::Terminator<'tcx>,
292294
_location: Location,
293295
) {
@@ -298,7 +300,7 @@ pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
298300
/// See `Analysis::apply_call_return_effect`.
299301
fn call_return_effect(
300302
&mut self,
301-
trans: &mut impl GenKill<Self::Idx>,
303+
trans: &mut Self::Domain,
302304
block: BasicBlock,
303305
return_places: CallReturnPlaces<'_, 'tcx>,
304306
);
@@ -313,6 +315,7 @@ pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
313315
}
314316
}
315317

318+
// Blanket impl: any impl of `GenKillAnalysis` automatically impls `Analysis`.
316319
impl<'tcx, A> Analysis<'tcx> for A
317320
where
318321
A: GenKillAnalysis<'tcx>,

compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeBorrowedLocals {
6262

6363
fn call_return_effect(
6464
&mut self,
65-
_trans: &mut impl GenKill<Self::Idx>,
65+
_trans: &mut Self::Domain,
6666
_block: BasicBlock,
6767
_return_places: CallReturnPlaces<'_, 'tcx>,
6868
) {

compiler/rustc_mir_dataflow/src/impls/initialized.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
376376

377377
fn call_return_effect(
378378
&mut self,
379-
trans: &mut impl GenKill<Self::Idx>,
379+
trans: &mut Self::Domain,
380380
_block: mir::BasicBlock,
381381
return_places: CallReturnPlaces<'_, 'tcx>,
382382
) {
@@ -499,7 +499,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
499499

500500
fn call_return_effect(
501501
&mut self,
502-
trans: &mut impl GenKill<Self::Idx>,
502+
trans: &mut Self::Domain,
503503
_block: mir::BasicBlock,
504504
return_places: CallReturnPlaces<'_, 'tcx>,
505505
) {
@@ -617,7 +617,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
617617

618618
fn call_return_effect(
619619
&mut self,
620-
trans: &mut impl GenKill<Self::Idx>,
620+
trans: &mut Self::Domain,
621621
_block: mir::BasicBlock,
622622
return_places: CallReturnPlaces<'_, 'tcx>,
623623
) {
@@ -712,7 +712,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
712712

713713
fn call_return_effect(
714714
&mut self,
715-
trans: &mut impl GenKill<Self::Idx>,
715+
trans: &mut Self::Domain,
716716
block: mir::BasicBlock,
717717
_return_places: CallReturnPlaces<'_, 'tcx>,
718718
) {

compiler/rustc_mir_dataflow/src/impls/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
6969

7070
fn call_return_effect(
7171
&mut self,
72-
trans: &mut impl GenKill<Self::Idx>,
72+
trans: &mut Self::Domain,
7373
_block: mir::BasicBlock,
7474
return_places: CallReturnPlaces<'_, 'tcx>,
7575
) {

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> {
7272

7373
fn call_return_effect(
7474
&mut self,
75-
_trans: &mut impl GenKill<Self::Idx>,
75+
_trans: &mut Self::Domain,
7676
_block: BasicBlock,
7777
_return_places: CallReturnPlaces<'_, 'tcx>,
7878
) {
@@ -144,7 +144,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageDead {
144144

145145
fn call_return_effect(
146146
&mut self,
147-
_trans: &mut impl GenKill<Self::Idx>,
147+
_trans: &mut Self::Domain,
148148
_block: BasicBlock,
149149
_return_places: CallReturnPlaces<'_, 'tcx>,
150150
) {
@@ -238,7 +238,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
238238

239239
fn before_terminator_effect(
240240
&mut self,
241-
trans: &mut impl GenKill<Self::Idx>,
241+
trans: &mut Self::Domain,
242242
terminator: &Terminator<'tcx>,
243243
loc: Location,
244244
) {
@@ -334,7 +334,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
334334

335335
fn call_return_effect(
336336
&mut self,
337-
trans: &mut impl GenKill<Self::Idx>,
337+
trans: &mut Self::Domain,
338338
_block: BasicBlock,
339339
return_places: CallReturnPlaces<'_, 'tcx>,
340340
) {

0 commit comments

Comments
 (0)