2
2
3
3
use crate :: framework:: BitSetExt ;
4
4
5
- use std:: borrow:: { Borrow , BorrowMut } ;
6
5
use std:: cmp:: Ordering ;
7
6
8
7
#[ cfg( debug_assertions) ]
9
8
use rustc_index:: bit_set:: BitSet ;
10
9
use rustc_middle:: mir:: { self , BasicBlock , Location } ;
11
10
12
- use super :: { Analysis , Direction , Effect , EffectIndex , EntrySets , Results } ;
13
-
14
- // `AnalysisResults` is needed as an impl such as the following has an unconstrained type
15
- // parameter:
16
- // ```
17
- // impl<'tcx, A, E, R> ResultsCursor<'_, 'tcx, A, R>
18
- // where
19
- // A: Analysis<'tcx>,
20
- // E: Borrow<EntrySets<'tcx, A>>,
21
- // R: Results<'tcx, A, E>,
22
- // {}
23
- // ```
24
-
25
- /// A type representing the analysis results consumed by a `ResultsCursor`.
26
- pub trait AnalysisResults < ' tcx , A > : BorrowMut < Results < ' tcx , A , Self :: EntrySets > >
27
- where
28
- A : Analysis < ' tcx > ,
29
- {
30
- /// The type containing the entry sets for this `Results` type.
31
- ///
32
- /// Should be either `EntrySets<'tcx, A>` or `&EntrySets<'tcx, A>`.
33
- type EntrySets : Borrow < EntrySets < ' tcx , A > > ;
34
- }
35
- impl < ' tcx , A , E > AnalysisResults < ' tcx , A > for Results < ' tcx , A , E >
36
- where
37
- A : Analysis < ' tcx > ,
38
- E : Borrow < EntrySets < ' tcx , A > > ,
39
- {
40
- type EntrySets = E ;
41
- }
11
+ use super :: { Analysis , Direction , Effect , EffectIndex , Results } ;
42
12
43
13
/// Allows random access inspection of the results of a dataflow analysis.
44
14
///
45
15
/// This cursor only has linear performance within a basic block when its statements are visited in
46
16
/// the same order as the `DIRECTION` of the analysis. In the worst case—when statements are
47
17
/// visited in *reverse* order—performance will be quadratic in the number of statements in the
48
18
/// block. The order in which basic blocks are inspected has no impact on performance.
49
- pub struct ResultsCursor < ' mir , ' tcx , A , R = Results < ' tcx , A > >
19
+ pub struct ResultsCursor < ' mir , ' tcx , A >
50
20
where
51
21
A : Analysis < ' tcx > ,
52
22
{
53
23
body : & ' mir mir:: Body < ' tcx > ,
54
- results : R ,
24
+ results : Results < ' tcx , A > ,
55
25
state : A :: Domain ,
56
26
57
27
pos : CursorPosition ,
65
35
reachable_blocks : BitSet < BasicBlock > ,
66
36
}
67
37
68
- impl < ' mir , ' tcx , A , R > ResultsCursor < ' mir , ' tcx , A , R >
38
+ impl < ' mir , ' tcx , A > ResultsCursor < ' mir , ' tcx , A >
69
39
where
70
40
A : Analysis < ' tcx > ,
71
41
{
@@ -80,19 +50,13 @@ where
80
50
}
81
51
82
52
/// Unwraps this cursor, returning the underlying `Results`.
83
- pub fn into_results ( self ) -> R {
53
+ pub fn into_results ( self ) -> Results < ' tcx , A > {
84
54
self . results
85
55
}
86
- }
87
56
88
- impl < ' mir , ' tcx , A , R > ResultsCursor < ' mir , ' tcx , A , R >
89
- where
90
- A : Analysis < ' tcx > ,
91
- R : AnalysisResults < ' tcx , A > ,
92
- {
93
57
/// Returns a new cursor that can inspect `results`.
94
- pub fn new ( body : & ' mir mir:: Body < ' tcx > , results : R ) -> Self {
95
- let bottom_value = results. borrow ( ) . analysis . bottom_value ( body) ;
58
+ pub fn new ( body : & ' mir mir:: Body < ' tcx > , results : Results < ' tcx , A > ) -> Self {
59
+ let bottom_value = results. analysis . bottom_value ( body) ;
96
60
ResultsCursor {
97
61
body,
98
62
results,
@@ -117,23 +81,23 @@ where
117
81
}
118
82
119
83
/// Returns the underlying `Results`.
120
- pub fn results ( & self ) -> & Results < ' tcx , A , R :: EntrySets > {
121
- self . results . borrow ( )
84
+ pub fn results ( & self ) -> & Results < ' tcx , A > {
85
+ & self . results
122
86
}
123
87
124
88
/// Returns the underlying `Results`.
125
- pub fn mut_results ( & mut self ) -> & mut Results < ' tcx , A , R :: EntrySets > {
126
- self . results . borrow_mut ( )
89
+ pub fn mut_results ( & mut self ) -> & mut Results < ' tcx , A > {
90
+ & mut self . results
127
91
}
128
92
129
93
/// Returns the `Analysis` used to generate the underlying `Results`.
130
94
pub fn analysis ( & self ) -> & A {
131
- & self . results . borrow ( ) . analysis
95
+ & self . results . analysis
132
96
}
133
97
134
98
/// Returns the `Analysis` used to generate the underlying `Results`.
135
99
pub fn mut_analysis ( & mut self ) -> & mut A {
136
- & mut self . results . borrow_mut ( ) . analysis
100
+ & mut self . results . analysis
137
101
}
138
102
139
103
/// Resets the cursor to hold the entry set for the given basic block.
@@ -145,7 +109,7 @@ where
145
109
#[ cfg( debug_assertions) ]
146
110
assert ! ( self . reachable_blocks. contains( block) ) ;
147
111
148
- self . state . clone_from ( self . results . borrow ( ) . entry_set_for_block ( block) ) ;
112
+ self . state . clone_from ( self . results . entry_set_for_block ( block) ) ;
149
113
self . pos = CursorPosition :: block_entry ( block) ;
150
114
self . state_needs_reset = false ;
151
115
}
@@ -234,11 +198,10 @@ where
234
198
)
235
199
} ;
236
200
237
- let analysis = & mut self . results . borrow_mut ( ) . analysis ;
238
201
let target_effect_index = effect. at_index ( target. statement_index ) ;
239
202
240
203
A :: Direction :: apply_effects_in_range (
241
- analysis,
204
+ & mut self . results . analysis ,
242
205
& mut self . state ,
243
206
target. block ,
244
207
block_data,
@@ -254,12 +217,12 @@ where
254
217
/// This can be used, e.g., to apply the call return effect directly to the cursor without
255
218
/// creating an extra copy of the dataflow state.
256
219
pub fn apply_custom_effect ( & mut self , f : impl FnOnce ( & mut A , & mut A :: Domain ) ) {
257
- f ( & mut self . results . borrow_mut ( ) . analysis , & mut self . state ) ;
220
+ f ( & mut self . results . analysis , & mut self . state ) ;
258
221
self . state_needs_reset = true ;
259
222
}
260
223
}
261
224
262
- impl < ' mir , ' tcx , A , R > ResultsCursor < ' mir , ' tcx , A , R >
225
+ impl < ' mir , ' tcx , A > ResultsCursor < ' mir , ' tcx , A >
263
226
where
264
227
A : crate :: GenKillAnalysis < ' tcx > ,
265
228
A :: Domain : BitSetExt < A :: Idx > ,
0 commit comments