@@ -180,17 +180,20 @@ impl CursorPosition {
180
180
}
181
181
}
182
182
183
+ type ResultsRefCursor < ' a , ' mir , ' tcx , A > =
184
+ ResultsCursor < ' mir , ' tcx , A , & ' a Results < ' tcx , A > > ;
185
+
183
186
/// Inspect the results of dataflow analysis.
184
187
///
185
188
/// This cursor has linear performance when visiting statements in a block in order. Visiting
186
189
/// statements within a block in reverse order is `O(n^2)`, where `n` is the number of statements
187
190
/// in that block.
188
- pub struct ResultsCursor < ' mir , ' tcx , A >
191
+ pub struct ResultsCursor < ' mir , ' tcx , A , R = Results < ' tcx , A > >
189
192
where
190
193
A : Analysis < ' tcx > ,
191
194
{
192
195
body : & ' mir mir:: Body < ' tcx > ,
193
- results : Results < ' tcx , A > ,
196
+ results : R ,
194
197
state : BitSet < A :: Idx > ,
195
198
196
199
pos : CursorPosition ,
@@ -202,24 +205,29 @@ where
202
205
is_call_return_effect_applied : bool ,
203
206
}
204
207
205
- impl < ' mir , ' tcx , A > ResultsCursor < ' mir , ' tcx , A >
208
+ impl < ' mir , ' tcx , A , R > ResultsCursor < ' mir , ' tcx , A , R >
206
209
where
207
210
A : Analysis < ' tcx > ,
211
+ R : Borrow < Results < ' tcx , A > > ,
208
212
{
209
213
/// Returns a new cursor for `results` that points to the start of the `START_BLOCK`.
210
- pub fn new ( body : & ' mir mir:: Body < ' tcx > , results : Results < ' tcx , A > ) -> Self {
214
+ pub fn new ( body : & ' mir mir:: Body < ' tcx > , results : R ) -> Self {
211
215
ResultsCursor {
212
216
body,
213
217
pos : CursorPosition :: AtBlockStart ( mir:: START_BLOCK ) ,
214
218
is_call_return_effect_applied : false ,
215
- state : results. entry_sets [ mir:: START_BLOCK ] . clone ( ) ,
219
+ state : results. borrow ( ) . entry_sets [ mir:: START_BLOCK ] . clone ( ) ,
216
220
results,
217
221
}
218
222
}
219
223
224
+ pub fn analysis ( & self ) -> & A {
225
+ & self . results . borrow ( ) . analysis
226
+ }
227
+
220
228
/// Resets the cursor to the start of the given `block`.
221
229
pub fn seek_to_block_start ( & mut self , block : BasicBlock ) {
222
- self . state . overwrite ( & self . results . entry_sets [ block] ) ;
230
+ self . state . overwrite ( & self . results . borrow ( ) . entry_sets [ block] ) ;
223
231
self . pos = CursorPosition :: AtBlockStart ( block) ;
224
232
self . is_call_return_effect_applied = false ;
225
233
}
@@ -275,7 +283,7 @@ where
275
283
} = & term. kind {
276
284
if !self . is_call_return_effect_applied {
277
285
self . is_call_return_effect_applied = true ;
278
- self . results . analysis . apply_call_return_effect (
286
+ self . results . borrow ( ) . analysis . apply_call_return_effect (
279
287
& mut self . state ,
280
288
target. block ,
281
289
func,
@@ -316,7 +324,7 @@ where
316
324
} ;
317
325
318
326
let block_data = & self . body . basic_blocks ( ) [ target_block] ;
319
- self . results . analysis . apply_partial_block_effect (
327
+ self . results . borrow ( ) . analysis . apply_partial_block_effect (
320
328
& mut self . state ,
321
329
target_block,
322
330
block_data,
0 commit comments