22
33use crate :: framework:: BitSetExt ;
44
5- use std:: borrow:: { Borrow , BorrowMut } ;
65use std:: cmp:: Ordering ;
76
87#[ cfg( debug_assertions) ]
98use rustc_index:: bit_set:: BitSet ;
109use rustc_middle:: mir:: { self , BasicBlock , Location } ;
1110
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 } ;
4212
4313/// Allows random access inspection of the results of a dataflow analysis.
4414///
4515/// This cursor only has linear performance within a basic block when its statements are visited in
4616/// the same order as the `DIRECTION` of the analysis. In the worst case—when statements are
4717/// visited in *reverse* order—performance will be quadratic in the number of statements in the
4818/// 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 >
5020where
5121 A : Analysis < ' tcx > ,
5222{
5323 body : & ' mir mir:: Body < ' tcx > ,
54- results : R ,
24+ results : Results < ' tcx , A > ,
5525 state : A :: Domain ,
5626
5727 pos : CursorPosition ,
6535 reachable_blocks : BitSet < BasicBlock > ,
6636}
6737
68- impl < ' mir , ' tcx , A , R > ResultsCursor < ' mir , ' tcx , A , R >
38+ impl < ' mir , ' tcx , A > ResultsCursor < ' mir , ' tcx , A >
6939where
7040 A : Analysis < ' tcx > ,
7141{
@@ -80,19 +50,13 @@ where
8050 }
8151
8252 /// Unwraps this cursor, returning the underlying `Results`.
83- pub fn into_results ( self ) -> R {
53+ pub fn into_results ( self ) -> Results < ' tcx , A > {
8454 self . results
8555 }
86- }
8756
88- impl < ' mir , ' tcx , A , R > ResultsCursor < ' mir , ' tcx , A , R >
89- where
90- A : Analysis < ' tcx > ,
91- R : AnalysisResults < ' tcx , A > ,
92- {
9357 /// 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) ;
9660 ResultsCursor {
9761 body,
9862 results,
@@ -117,23 +81,23 @@ where
11781 }
11882
11983 /// 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
12286 }
12387
12488 /// 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
12791 }
12892
12993 /// Returns the `Analysis` used to generate the underlying `Results`.
13094 pub fn analysis ( & self ) -> & A {
131- & self . results . borrow ( ) . analysis
95+ & self . results . analysis
13296 }
13397
13498 /// Returns the `Analysis` used to generate the underlying `Results`.
13599 pub fn mut_analysis ( & mut self ) -> & mut A {
136- & mut self . results . borrow_mut ( ) . analysis
100+ & mut self . results . analysis
137101 }
138102
139103 /// Resets the cursor to hold the entry set for the given basic block.
@@ -145,7 +109,7 @@ where
145109 #[ cfg( debug_assertions) ]
146110 assert ! ( self . reachable_blocks. contains( block) ) ;
147111
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) ) ;
149113 self . pos = CursorPosition :: block_entry ( block) ;
150114 self . state_needs_reset = false ;
151115 }
@@ -234,11 +198,10 @@ where
234198 )
235199 } ;
236200
237- let analysis = & mut self . results . borrow_mut ( ) . analysis ;
238201 let target_effect_index = effect. at_index ( target. statement_index ) ;
239202
240203 A :: Direction :: apply_effects_in_range (
241- analysis,
204+ & mut self . results . analysis ,
242205 & mut self . state ,
243206 target. block ,
244207 block_data,
@@ -254,12 +217,12 @@ where
254217 /// This can be used, e.g., to apply the call return effect directly to the cursor without
255218 /// creating an extra copy of the dataflow state.
256219 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 ) ;
258221 self . state_needs_reset = true ;
259222 }
260223}
261224
262- impl < ' mir , ' tcx , A , R > ResultsCursor < ' mir , ' tcx , A , R >
225+ impl < ' mir , ' tcx , A > ResultsCursor < ' mir , ' tcx , A >
263226where
264227 A : crate :: GenKillAnalysis < ' tcx > ,
265228 A :: Domain : BitSetExt < A :: Idx > ,
0 commit comments