@@ -180,17 +180,20 @@ impl CursorPosition {
180180 }
181181}
182182
183+ type ResultsRefCursor < ' a , ' mir , ' tcx , A > =
184+ ResultsCursor < ' mir , ' tcx , A , & ' a Results < ' tcx , A > > ;
185+
183186/// Inspect the results of dataflow analysis.
184187///
185188/// This cursor has linear performance when visiting statements in a block in order. Visiting
186189/// statements within a block in reverse order is `O(n^2)`, where `n` is the number of statements
187190/// in that block.
188- pub struct ResultsCursor < ' mir , ' tcx , A >
191+ pub struct ResultsCursor < ' mir , ' tcx , A , R = Results < ' tcx , A > >
189192where
190193 A : Analysis < ' tcx > ,
191194{
192195 body : & ' mir mir:: Body < ' tcx > ,
193- results : Results < ' tcx , A > ,
196+ results : R ,
194197 state : BitSet < A :: Idx > ,
195198
196199 pos : CursorPosition ,
@@ -202,24 +205,29 @@ where
202205 is_call_return_effect_applied : bool ,
203206}
204207
205- impl < ' mir , ' tcx , A > ResultsCursor < ' mir , ' tcx , A >
208+ impl < ' mir , ' tcx , A , R > ResultsCursor < ' mir , ' tcx , A , R >
206209where
207210 A : Analysis < ' tcx > ,
211+ R : Borrow < Results < ' tcx , A > > ,
208212{
209213 /// 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 {
211215 ResultsCursor {
212216 body,
213217 pos : CursorPosition :: AtBlockStart ( mir:: START_BLOCK ) ,
214218 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 ( ) ,
216220 results,
217221 }
218222 }
219223
224+ pub fn analysis ( & self ) -> & A {
225+ & self . results . borrow ( ) . analysis
226+ }
227+
220228 /// Resets the cursor to the start of the given `block`.
221229 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] ) ;
223231 self . pos = CursorPosition :: AtBlockStart ( block) ;
224232 self . is_call_return_effect_applied = false ;
225233 }
@@ -275,7 +283,7 @@ where
275283 } = & term. kind {
276284 if !self . is_call_return_effect_applied {
277285 self . is_call_return_effect_applied = true ;
278- self . results . analysis . apply_call_return_effect (
286+ self . results . borrow ( ) . analysis . apply_call_return_effect (
279287 & mut self . state ,
280288 target. block ,
281289 func,
@@ -316,7 +324,7 @@ where
316324 } ;
317325
318326 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 (
320328 & mut self . state ,
321329 target_block,
322330 block_data,
0 commit comments