242
242
243
243
use super :: * ;
244
244
245
- use crate :: framework:: { Analysis , Results , ResultsCursor } ;
245
+ use crate :: framework:: { Analysis , Results , ResultsClonedCursor , ResultsCursor } ;
246
246
use crate :: impls:: MaybeBorrowedLocals ;
247
- use crate :: {
248
- AnalysisDomain , Backward , CallReturnPlaces , GenKill , GenKillAnalysis , ResultsRefCursor ,
249
- } ;
247
+ use crate :: { AnalysisDomain , Backward , CallReturnPlaces , CloneAnalysis , GenKill , GenKillAnalysis } ;
250
248
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
251
249
use rustc_data_structures:: graph;
252
250
use rustc_data_structures:: graph:: implementation:: { Graph , NodeIndex } ;
@@ -257,7 +255,6 @@ use rustc_middle::mir::*;
257
255
use rustc_middle:: ty:: TypeVisitable ;
258
256
use rustc_middle:: ty:: { self , Ty , TypeSuperVisitable } ;
259
257
260
- use std:: cell:: RefCell ;
261
258
use std:: ops:: { ControlFlow , Deref , DerefMut } ;
262
259
263
260
// FIXME Properly determine a reasonable value
@@ -890,7 +887,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BorrowDependencies<'a, 'tcx> {
890
887
}
891
888
}
892
889
893
- pub struct BorrowedLocalsResults < ' a , ' mir , ' tcx > {
890
+ pub struct BorrowedLocalsResults < ' mir , ' tcx > {
894
891
/// the results of the liveness analysis of `LiveBorrows`
895
892
borrows_analysis_results : Results < ' tcx , LiveBorrows < ' mir , ' tcx > > ,
896
893
@@ -900,36 +897,26 @@ pub struct BorrowedLocalsResults<'a, 'mir, 'tcx> {
900
897
/// to the set of `Local`s that are borrowed through those references, pointers or composite values.
901
898
borrowed_local_to_locals_to_keep_alive : FxHashMap < Local , FxHashSet < Local > > ,
902
899
903
- /// The results cursor of the `MaybeBorrowedLocals` analysis. Needed as an upper bound, since
900
+ /// The results of the `MaybeBorrowedLocals` analysis. Needed as an upper bound, since
904
901
/// to ensure soundness the `LiveBorrows` analysis would keep more `Local`s alive than
905
902
/// strictly necessary.
906
- maybe_borrowed_locals_results_cursor : RefCell <
907
- ResultsCursor < ' mir , ' tcx , MaybeBorrowedLocals , & ' a Results < ' tcx , MaybeBorrowedLocals > > ,
908
- > ,
903
+ maybe_borrowed_locals_results : Results < ' tcx , MaybeBorrowedLocals > ,
909
904
}
910
905
911
- impl < ' a , ' mir , ' tcx > BorrowedLocalsResults < ' a , ' mir , ' tcx >
906
+ impl < ' mir , ' tcx > BorrowedLocalsResults < ' mir , ' tcx >
912
907
where
913
908
' tcx : ' mir ,
914
- ' tcx : ' a ,
915
909
{
916
910
fn new (
917
911
borrows_analysis_results : Results < ' tcx , LiveBorrows < ' mir , ' tcx > > ,
918
- maybe_borrowed_locals_results_cursor : ResultsCursor <
919
- ' mir ,
920
- ' tcx ,
921
- MaybeBorrowedLocals ,
922
- & ' a Results < ' tcx , MaybeBorrowedLocals > ,
923
- > ,
912
+ maybe_borrowed_locals_results : Results < ' tcx , MaybeBorrowedLocals > ,
924
913
dep_graph : BorrowDepGraph ,
925
914
) -> Self {
926
915
let borrowed_local_to_locals_to_keep_alive = Self :: get_locals_to_keep_alive_map ( dep_graph) ;
927
916
Self {
928
917
borrows_analysis_results,
929
918
borrowed_local_to_locals_to_keep_alive,
930
- maybe_borrowed_locals_results_cursor : RefCell :: new (
931
- maybe_borrowed_locals_results_cursor,
932
- ) ,
919
+ maybe_borrowed_locals_results,
933
920
}
934
921
}
935
922
@@ -1051,17 +1038,12 @@ where
1051
1038
1052
1039
/// The function gets the results of the borrowed locals analysis in this module. See the module
1053
1040
/// doc-comment for information on what exactly this analysis does.
1054
- #[ instrument( skip( tcx, maybe_borrowed_locals_cursor , body) , level = "debug" ) ]
1055
- pub fn get_borrowed_locals_results < ' a , ' mir , ' tcx > (
1041
+ #[ instrument( skip( tcx, maybe_borrowed_locals , body) , level = "debug" ) ]
1042
+ pub fn get_borrowed_locals_results < ' mir , ' tcx > (
1056
1043
body : & ' mir Body < ' tcx > ,
1057
1044
tcx : TyCtxt < ' tcx > ,
1058
- maybe_borrowed_locals_cursor : ResultsCursor <
1059
- ' mir ,
1060
- ' tcx ,
1061
- MaybeBorrowedLocals ,
1062
- & ' a Results < ' tcx , MaybeBorrowedLocals > ,
1063
- > ,
1064
- ) -> BorrowedLocalsResults < ' a , ' mir , ' tcx > {
1045
+ maybe_borrowed_locals : Results < ' tcx , MaybeBorrowedLocals > ,
1046
+ ) -> BorrowedLocalsResults < ' mir , ' tcx > {
1065
1047
debug ! ( "body: {:#?}" , body) ;
1066
1048
1067
1049
let mut borrow_deps = BorrowDependencies :: new ( body. local_decls ( ) , tcx) ;
@@ -1111,19 +1093,24 @@ pub fn get_borrowed_locals_results<'a, 'mir, 'tcx>(
1111
1093
let live_borrows_results =
1112
1094
live_borrows. into_engine ( tcx, body) . pass_name ( "borrowed_locals" ) . iterate_to_fixpoint ( ) ;
1113
1095
1114
- BorrowedLocalsResults :: new (
1115
- live_borrows_results,
1116
- maybe_borrowed_locals_cursor,
1117
- borrow_deps. dep_graph ,
1118
- )
1096
+ BorrowedLocalsResults :: new ( live_borrows_results, maybe_borrowed_locals, borrow_deps. dep_graph )
1119
1097
}
1120
1098
1121
1099
/// The `ResultsCursor` equivalent for the borrowed locals analysis. Since this analysis doesn't
1122
1100
/// require convergence, we expose the set of borrowed `Local`s for a `Location` directly via
1123
1101
/// the `get` method without the need for any prior 'seek' calls.
1124
1102
pub struct BorrowedLocalsResultsCursor < ' a , ' mir , ' tcx > {
1125
1103
// The cursor for the liveness analysis performed by `LiveBorrows`
1126
- borrows_analysis_cursor : ResultsRefCursor < ' a , ' mir , ' tcx , LiveBorrows < ' mir , ' tcx > > ,
1104
+ borrows_analysis_cursor : ResultsCursor <
1105
+ ' mir ,
1106
+ ' tcx ,
1107
+ LiveBorrows < ' mir , ' tcx > ,
1108
+ Results <
1109
+ ' tcx ,
1110
+ LiveBorrows < ' mir , ' tcx > ,
1111
+ & ' a rustc_index:: IndexVec < BasicBlock , BitSet < Local > > ,
1112
+ > ,
1113
+ > ,
1127
1114
1128
1115
// Maps each `Local` corresponding to a reference or pointer to the set of `Local`s
1129
1116
// that are borrowed through the ref/ptr. Additionally contains entries for `Local`s
@@ -1132,14 +1119,13 @@ pub struct BorrowedLocalsResultsCursor<'a, 'mir, 'tcx> {
1132
1119
borrowed_local_to_locals_to_keep_alive : & ' a FxHashMap < Local , FxHashSet < Local > > ,
1133
1120
1134
1121
// the cursor of the conservative borrowed locals analysis
1135
- maybe_borrowed_locals_results_cursor : & ' a RefCell <
1136
- ResultsCursor < ' mir , ' tcx , MaybeBorrowedLocals , & ' a Results < ' tcx , MaybeBorrowedLocals > > ,
1137
- > ,
1122
+ maybe_borrowed_locals_results_cursor : ResultsClonedCursor < ' a , ' mir , ' tcx , MaybeBorrowedLocals > ,
1138
1123
}
1139
1124
1140
1125
impl < ' a , ' mir , ' tcx > BorrowedLocalsResultsCursor < ' a , ' mir , ' tcx > {
1141
- pub fn new ( body : & ' mir Body < ' tcx > , results : & ' a BorrowedLocalsResults < ' a , ' mir , ' tcx > ) -> Self {
1142
- let mut cursor = ResultsCursor :: new ( body, & results. borrows_analysis_results ) ;
1126
+ pub fn new ( body : & ' mir Body < ' tcx > , results : & ' a BorrowedLocalsResults < ' mir , ' tcx > ) -> Self {
1127
+ let mut cursor =
1128
+ ResultsCursor :: new ( body, results. borrows_analysis_results . clone_analysis ( ) ) ;
1143
1129
1144
1130
// We don't care about the order of the blocks, only about the result at a given location.
1145
1131
// This statement is necessary since we're performing a backward analysis in `LiveBorrows`,
@@ -1149,7 +1135,10 @@ impl<'a, 'mir, 'tcx> BorrowedLocalsResultsCursor<'a, 'mir, 'tcx> {
1149
1135
Self {
1150
1136
borrows_analysis_cursor : cursor,
1151
1137
borrowed_local_to_locals_to_keep_alive : & results. borrowed_local_to_locals_to_keep_alive ,
1152
- maybe_borrowed_locals_results_cursor : & results. maybe_borrowed_locals_results_cursor ,
1138
+ maybe_borrowed_locals_results_cursor : ResultsClonedCursor :: new (
1139
+ body,
1140
+ results. maybe_borrowed_locals_results . clone_analysis ( ) ,
1141
+ ) ,
1153
1142
}
1154
1143
}
1155
1144
@@ -1178,11 +1167,9 @@ impl<'a, 'mir, 'tcx> BorrowedLocalsResultsCursor<'a, 'mir, 'tcx> {
1178
1167
// use results of conservative analysis as an "upper bound" on the borrowed locals. This
1179
1168
// is necessary since to guarantee soundness for this analysis we would have to keep
1180
1169
// more `Local`s alive than strictly necessary.
1181
- let mut maybe_borrowed_locals_cursor =
1182
- self . maybe_borrowed_locals_results_cursor . borrow_mut ( ) ;
1183
- maybe_borrowed_locals_cursor. allow_unreachable ( ) ;
1184
- maybe_borrowed_locals_cursor. seek_before_primary_effect ( loc) ;
1185
- let upper_bound_borrowed_locals = maybe_borrowed_locals_cursor. get ( ) ;
1170
+ self . maybe_borrowed_locals_results_cursor . allow_unreachable ( ) ;
1171
+ self . maybe_borrowed_locals_results_cursor . seek_before_primary_effect ( loc) ;
1172
+ let upper_bound_borrowed_locals = self . maybe_borrowed_locals_results_cursor . get ( ) ;
1186
1173
borrowed_locals. intersect ( upper_bound_borrowed_locals) ;
1187
1174
1188
1175
debug ! ( ?borrowed_locals) ;
@@ -1225,7 +1212,7 @@ impl<'mir, 'tcx> LiveBorrows<'mir, 'tcx> {
1225
1212
}
1226
1213
}
1227
1214
1228
- impl < ' mir , ' tcx > crate :: CloneAnalysis for LiveBorrows < ' mir , ' tcx > {
1215
+ impl < ' mir , ' tcx > CloneAnalysis for LiveBorrows < ' mir , ' tcx > {
1229
1216
fn clone_analysis ( & self ) -> Self {
1230
1217
self . clone ( )
1231
1218
}
@@ -1251,7 +1238,7 @@ impl<'a, 'tcx> GenKillAnalysis<'tcx> for LiveBorrows<'a, 'tcx> {
1251
1238
1252
1239
#[ instrument( skip( self , trans) , level = "debug" ) ]
1253
1240
fn statement_effect (
1254
- & self ,
1241
+ & mut self ,
1255
1242
trans : & mut impl GenKill < Self :: Idx > ,
1256
1243
statement : & mir:: Statement < ' tcx > ,
1257
1244
location : Location ,
@@ -1261,7 +1248,7 @@ impl<'a, 'tcx> GenKillAnalysis<'tcx> for LiveBorrows<'a, 'tcx> {
1261
1248
1262
1249
#[ instrument( skip( self , trans) , level = "debug" ) ]
1263
1250
fn terminator_effect (
1264
- & self ,
1251
+ & mut self ,
1265
1252
trans : & mut impl GenKill < Self :: Idx > ,
1266
1253
terminator : & mir:: Terminator < ' tcx > ,
1267
1254
location : Location ,
@@ -1270,7 +1257,7 @@ impl<'a, 'tcx> GenKillAnalysis<'tcx> for LiveBorrows<'a, 'tcx> {
1270
1257
}
1271
1258
1272
1259
fn call_return_effect (
1273
- & self ,
1260
+ & mut self ,
1274
1261
_trans : & mut impl GenKill < Self :: Idx > ,
1275
1262
_block : mir:: BasicBlock ,
1276
1263
_return_places : CallReturnPlaces < ' _ , ' tcx > ,
0 commit comments