1
1
pub use super :: * ;
2
2
3
- use crate :: { CallReturnPlaces , GenKill , ResultsClonedCursor } ;
3
+ use crate :: impls:: { BorrowedLocalsResults , BorrowedLocalsResultsCursor } ;
4
+ use crate :: { CallReturnPlaces , GenKill } ;
4
5
use rustc_middle:: mir:: visit:: { NonMutatingUseContext , PlaceContext , Visitor } ;
5
6
use rustc_middle:: mir:: * ;
6
7
use std:: borrow:: Cow ;
@@ -146,28 +147,26 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageDead {
146
147
}
147
148
}
148
149
149
- type BorrowedLocalsResults < ' res , ' mir , ' tcx > =
150
- ResultsClonedCursor < ' res , ' mir , ' tcx , MaybeBorrowedLocals > ;
151
-
152
150
/// Dataflow analysis that determines whether each local requires storage at a
153
151
/// given location; i.e. whether its storage can go away without being observed.
154
- pub struct MaybeRequiresStorage < ' res , ' mir , ' tcx > {
155
- borrowed_locals : BorrowedLocalsResults < ' res , ' mir , ' tcx > ,
156
- }
157
-
158
- impl < ' res , ' mir , ' tcx > MaybeRequiresStorage < ' res , ' mir , ' tcx > {
159
- pub fn new ( borrowed_locals : BorrowedLocalsResults < ' res , ' mir , ' tcx > ) -> Self {
160
- MaybeRequiresStorage { borrowed_locals }
161
- }
152
+ pub struct MaybeRequiresStorage < ' a , ' mir , ' tcx > {
153
+ body : & ' mir Body < ' tcx > ,
154
+ borrowed_locals : RefCell < BorrowedLocalsResultsCursor < ' a , ' mir , ' tcx > > ,
162
155
}
163
156
164
- impl crate :: CloneAnalysis for MaybeRequiresStorage < ' _ , ' _ , ' _ > {
165
- fn clone_analysis ( & self ) -> Self {
166
- Self { borrowed_locals : self . borrowed_locals . new_cursor ( ) }
157
+ impl < ' a , ' mir , ' tcx > MaybeRequiresStorage < ' a , ' mir , ' tcx > {
158
+ pub fn new (
159
+ body : & ' mir Body < ' tcx > ,
160
+ borrowed_locals : & ' a BorrowedLocalsResults < ' mir , ' tcx > ,
161
+ ) -> Self {
162
+ MaybeRequiresStorage {
163
+ body,
164
+ borrowed_locals : RefCell :: new ( BorrowedLocalsResultsCursor :: new ( body, borrowed_locals) ) ,
165
+ }
167
166
}
168
167
}
169
168
170
- impl < ' tcx > crate :: AnalysisDomain < ' tcx > for MaybeRequiresStorage < ' _ , ' _ , ' tcx > {
169
+ impl < ' a , ' mir , ' tcx > crate :: AnalysisDomain < ' tcx > for MaybeRequiresStorage < ' a , ' mir , ' tcx > {
171
170
type Domain = BitSet < Local > ;
172
171
173
172
const NAME : & ' static str = "requires_storage" ;
@@ -186,7 +185,7 @@ impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
186
185
}
187
186
}
188
187
189
- impl < ' tcx > crate :: GenKillAnalysis < ' tcx > for MaybeRequiresStorage < ' _ , ' _ , ' tcx > {
188
+ impl < ' a , ' mir , ' tcx > crate :: GenKillAnalysis < ' tcx > for MaybeRequiresStorage < ' a , ' mir , ' tcx > {
190
189
type Idx = Local ;
191
190
192
191
fn before_statement_effect (
@@ -196,7 +195,13 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
196
195
loc : Location ,
197
196
) {
198
197
// If a place is borrowed in a statement, it needs storage for that statement.
199
- self . borrowed_locals . mut_analysis ( ) . statement_effect ( trans, stmt, loc) ;
198
+ let borrowed_locals_at_loc = self . borrowed_locals . borrow_mut ( ) . get ( loc) ;
199
+ for i in 0 ..self . body . local_decls ( ) . len ( ) {
200
+ let local = Local :: from_usize ( i) ;
201
+ if borrowed_locals_at_loc. contains ( local) {
202
+ trans. gen ( local) ;
203
+ }
204
+ }
200
205
201
206
match & stmt. kind {
202
207
StatementKind :: StorageDead ( l) => trans. kill ( * l) ,
@@ -239,8 +244,14 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
239
244
terminator : & mir:: Terminator < ' tcx > ,
240
245
loc : Location ,
241
246
) {
242
- // If a place is borrowed in a terminator, it needs storage for that terminator.
243
- self . borrowed_locals . mut_analysis ( ) . terminator_effect ( trans, terminator, loc) ;
247
+ // If a place is borrowed in a statement, it needs storage for that statement.
248
+ let borrowed_locals_at_loc = self . borrowed_locals . borrow_mut ( ) . get ( loc) ;
249
+ for i in 0 ..self . body . local_decls ( ) . len ( ) {
250
+ let local = Local :: from_usize ( i) ;
251
+ if borrowed_locals_at_loc. contains ( local) {
252
+ trans. gen ( local) ;
253
+ }
254
+ }
244
255
245
256
match & terminator. kind {
246
257
TerminatorKind :: Call { destination, .. } => {
@@ -344,7 +355,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
344
355
}
345
356
}
346
357
347
- impl < ' tcx > MaybeRequiresStorage < ' _ , ' _ , ' tcx > {
358
+ impl < ' a , ' mir , ' tcx > MaybeRequiresStorage < ' a , ' mir , ' tcx > {
348
359
/// Kill locals that are fully moved and have not been borrowed.
349
360
fn check_for_move ( & mut self , trans : & mut impl GenKill < Local > , loc : Location ) {
350
361
let body = self . borrowed_locals . body ( ) ;
@@ -353,19 +364,21 @@ impl<'tcx> MaybeRequiresStorage<'_, '_, 'tcx> {
353
364
}
354
365
}
355
366
356
- struct MoveVisitor < ' a , ' res , ' mir , ' tcx , T > {
357
- borrowed_locals : & ' a mut BorrowedLocalsResults < ' res , ' mir , ' tcx > ,
367
+ struct MoveVisitor < ' a , ' b , ' mir , ' tcx , T > {
368
+ borrowed_locals : & ' a RefCell < BorrowedLocalsResultsCursor < ' b , ' mir , ' tcx > > ,
358
369
trans : & ' a mut T ,
359
370
}
360
371
361
- impl < ' tcx , T > Visitor < ' tcx > for MoveVisitor < ' _ , ' _ , ' _ , ' tcx , T >
372
+ impl < ' a , ' b , ' mir , ' tcx , T > Visitor < ' tcx > for MoveVisitor < ' a , ' b , ' mir , ' tcx , T >
362
373
where
363
374
T : GenKill < Local > ,
364
375
{
376
+ #[ instrument( skip( self ) , level = "debug" ) ]
365
377
fn visit_local ( & mut self , local : Local , context : PlaceContext , loc : Location ) {
366
378
if PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Move ) == context {
367
- self . borrowed_locals . seek_before_primary_effect ( loc) ;
368
- if !self . borrowed_locals . contains ( local) {
379
+ let borrowed_locals = self . borrowed_locals . borrow_mut ( ) . get ( loc) ;
380
+ debug ! ( ?borrowed_locals) ;
381
+ if !borrowed_locals. contains ( local) {
369
382
self . trans . kill ( local) ;
370
383
}
371
384
}
0 commit comments