11//! Random access inspection of the results of a dataflow analysis.
22
3- use std:: borrow:: Cow ;
43use std:: cmp:: Ordering ;
5- use std:: ops:: { Deref , DerefMut } ;
4+ use std:: ops:: Deref ;
65
76#[ cfg( debug_assertions) ]
87use rustc_index:: bit_set:: DenseBitSet ;
98use rustc_middle:: mir:: { self , BasicBlock , Location } ;
109
1110use super :: { Analysis , Direction , Effect , EffectIndex , Results } ;
1211
13- /// Some `ResultsCursor`s want to own an `Analysis`, and some want to borrow an `Analysis`, either
14- /// mutable or immutably. This type allows all of the above. It's similar to `Cow`, but `Cow`
15- /// doesn't allow mutable borrowing.
16- enum CowMut < ' a , T > {
17- BorrowedMut ( & ' a mut T ) ,
12+ /// This is like `Cow`, but it lacks the `T: ToOwned` bound and doesn't support
13+ /// `to_owned`/`into_owned`.
14+ enum SimpleCow < ' a , T > {
15+ Borrowed ( & ' a T ) ,
1816 Owned ( T ) ,
1917}
2018
21- impl < T > Deref for CowMut < ' _ , T > {
19+ impl < T > Deref for SimpleCow < ' _ , T > {
2220 type Target = T ;
2321
2422 fn deref ( & self ) -> & T {
2523 match self {
26- CowMut :: BorrowedMut ( borrowed) => borrowed,
27- CowMut :: Owned ( owned) => owned,
28- }
29- }
30- }
31-
32- impl < T > DerefMut for CowMut < ' _ , T > {
33- fn deref_mut ( & mut self ) -> & mut T {
34- match self {
35- CowMut :: BorrowedMut ( borrowed) => borrowed,
36- CowMut :: Owned ( owned) => owned,
24+ SimpleCow :: Borrowed ( borrowed) => borrowed,
25+ SimpleCow :: Owned ( owned) => owned,
3726 }
3827 }
3928}
5342 A : Analysis < ' tcx > ,
5443{
5544 body : & ' mir mir:: Body < ' tcx > ,
56- analysis : CowMut < ' mir , A > ,
57- results : Cow < ' mir , Results < A :: Domain > > ,
45+ analysis : SimpleCow < ' mir , A > ,
46+ results : SimpleCow < ' mir , Results < A :: Domain > > ,
5847 state : A :: Domain ,
5948
6049 pos : CursorPosition ,
8473
8574 fn new (
8675 body : & ' mir mir:: Body < ' tcx > ,
87- analysis : CowMut < ' mir , A > ,
88- results : Cow < ' mir , Results < A :: Domain > > ,
76+ analysis : SimpleCow < ' mir , A > ,
77+ results : SimpleCow < ' mir , Results < A :: Domain > > ,
8978 ) -> Self {
9079 let bottom_value = analysis. bottom_value ( body) ;
9180 ResultsCursor {
@@ -111,16 +100,16 @@ where
111100 analysis : A ,
112101 results : Results < A :: Domain > ,
113102 ) -> Self {
114- Self :: new ( body, CowMut :: Owned ( analysis) , Cow :: Owned ( results) )
103+ Self :: new ( body, SimpleCow :: Owned ( analysis) , SimpleCow :: Owned ( results) )
115104 }
116105
117106 /// Returns a new cursor that borrows and inspects analysis results.
118107 pub fn new_borrowing (
119108 body : & ' mir mir:: Body < ' tcx > ,
120- analysis : & ' mir mut A ,
109+ analysis : & ' mir A ,
121110 results : & ' mir Results < A :: Domain > ,
122111 ) -> Self {
123- Self :: new ( body, CowMut :: BorrowedMut ( analysis) , Cow :: Borrowed ( results) )
112+ Self :: new ( body, SimpleCow :: Borrowed ( analysis) , SimpleCow :: Borrowed ( results) )
124113 }
125114
126115 /// Allows inspection of unreachable basic blocks even with `debug_assertions` enabled.
@@ -236,7 +225,7 @@ where
236225 let target_effect_index = effect. at_index ( target. statement_index ) ;
237226
238227 A :: Direction :: apply_effects_in_range (
239- & mut * self . analysis ,
228+ & * self . analysis ,
240229 & mut self . state ,
241230 target. block ,
242231 block_data,
@@ -251,8 +240,8 @@ where
251240 ///
252241 /// This can be used, e.g., to apply the call return effect directly to the cursor without
253242 /// creating an extra copy of the dataflow state.
254- pub fn apply_custom_effect ( & mut self , f : impl FnOnce ( & mut A , & mut A :: Domain ) ) {
255- f ( & mut self . analysis , & mut self . state ) ;
243+ pub fn apply_custom_effect ( & mut self , f : impl FnOnce ( & A , & mut A :: Domain ) ) {
244+ f ( & self . analysis , & mut self . state ) ;
256245 self . state_needs_reset = true ;
257246 }
258247}
0 commit comments