1
1
use rustc_data_structures:: fx:: FxIndexMap ;
2
2
use rustc_data_structures:: graph;
3
3
use rustc_index:: bit_set:: BitSet ;
4
- use rustc_middle:: mir:: {
5
- self , BasicBlock , Body , CallReturnPlaces , Location , Place , TerminatorEdges ,
6
- } ;
4
+ use rustc_middle:: mir:: { self , BasicBlock , Body , Location , Place , TerminatorEdges } ;
7
5
use rustc_middle:: ty:: { RegionVid , TyCtxt } ;
8
6
use rustc_mir_dataflow:: fmt:: DebugWithContext ;
9
7
use rustc_mir_dataflow:: impls:: { EverInitializedPlaces , MaybeUninitializedPlaces } ;
10
- use rustc_mir_dataflow:: { Analysis , AnalysisDomain , Forward , GenKill , Results , ResultsVisitable } ;
8
+ use rustc_mir_dataflow:: { Analysis , Forward , GenKill , Results , ResultsVisitable } ;
11
9
use tracing:: debug;
12
10
13
11
use crate :: { BorrowSet , PlaceConflictBias , PlaceExt , RegionInferenceContext , places_conflict} ;
@@ -22,9 +20,9 @@ pub(crate) struct BorrowckResults<'a, 'tcx> {
22
20
/// The transient state of the dataflow analyses used by the borrow checker.
23
21
#[ derive( Debug ) ]
24
22
pub ( crate ) struct BorrowckDomain < ' a , ' tcx > {
25
- pub ( crate ) borrows : <Borrows < ' a , ' tcx > as AnalysisDomain < ' tcx > >:: Domain ,
26
- pub ( crate ) uninits : <MaybeUninitializedPlaces < ' a , ' tcx > as AnalysisDomain < ' tcx > >:: Domain ,
27
- pub ( crate ) ever_inits : <EverInitializedPlaces < ' a , ' tcx > as AnalysisDomain < ' tcx > >:: Domain ,
23
+ pub ( crate ) borrows : <Borrows < ' a , ' tcx > as Analysis < ' tcx > >:: Domain ,
24
+ pub ( crate ) uninits : <MaybeUninitializedPlaces < ' a , ' tcx > as Analysis < ' tcx > >:: Domain ,
25
+ pub ( crate ) ever_inits : <EverInitializedPlaces < ' a , ' tcx > as Analysis < ' tcx > >:: Domain ,
28
26
}
29
27
30
28
impl < ' a , ' tcx > ResultsVisitable < ' tcx > for BorrowckResults < ' a , ' tcx > {
@@ -427,7 +425,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
427
425
/// That means they went out of a nonlexical scope
428
426
fn kill_loans_out_of_scope_at_location (
429
427
& self ,
430
- trans : & mut impl GenKill < BorrowIndex > ,
428
+ trans : & mut < Self as Analysis < ' tcx > > :: Domain ,
431
429
location : Location ,
432
430
) {
433
431
// NOTE: The state associated with a given `location`
@@ -447,7 +445,11 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
447
445
}
448
446
449
447
/// Kill any borrows that conflict with `place`.
450
- fn kill_borrows_on_place ( & self , trans : & mut impl GenKill < BorrowIndex > , place : Place < ' tcx > ) {
448
+ fn kill_borrows_on_place (
449
+ & self ,
450
+ trans : & mut <Self as Analysis < ' tcx > >:: Domain ,
451
+ place : Place < ' tcx > ,
452
+ ) {
451
453
debug ! ( "kill_borrows_on_place: place={:?}" , place) ;
452
454
453
455
let other_borrows_of_local = self
@@ -486,7 +488,14 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
486
488
}
487
489
}
488
490
489
- impl < ' tcx > rustc_mir_dataflow:: AnalysisDomain < ' tcx > for Borrows < ' _ , ' tcx > {
491
+ /// Forward dataflow computation of the set of borrows that are in scope at a particular location.
492
+ /// - we gen the introduced loans
493
+ /// - we kill loans on locals going out of (regular) scope
494
+ /// - we kill the loans going out of their region's NLL scope: in NLL terms, the frontier where a
495
+ /// region stops containing the CFG points reachable from the issuing location.
496
+ /// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
497
+ /// `a.b.c` when `a` is overwritten.
498
+ impl < ' tcx > rustc_mir_dataflow:: Analysis < ' tcx > for Borrows < ' _ , ' tcx > {
490
499
type Domain = BitSet < BorrowIndex > ;
491
500
492
501
const NAME : & ' static str = "borrows" ;
@@ -500,34 +509,19 @@ impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
500
509
// no borrows of code region_scopes have been taken prior to
501
510
// function execution, so this method has no effect.
502
511
}
503
- }
504
-
505
- /// Forward dataflow computation of the set of borrows that are in scope at a particular location.
506
- /// - we gen the introduced loans
507
- /// - we kill loans on locals going out of (regular) scope
508
- /// - we kill the loans going out of their region's NLL scope: in NLL terms, the frontier where a
509
- /// region stops containing the CFG points reachable from the issuing location.
510
- /// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
511
- /// `a.b.c` when `a` is overwritten.
512
- impl < ' tcx > rustc_mir_dataflow:: GenKillAnalysis < ' tcx > for Borrows < ' _ , ' tcx > {
513
- type Idx = BorrowIndex ;
514
-
515
- fn domain_size ( & self , _: & mir:: Body < ' tcx > ) -> usize {
516
- self . borrow_set . len ( )
517
- }
518
512
519
- fn before_statement_effect (
513
+ fn apply_before_statement_effect (
520
514
& mut self ,
521
- trans : & mut impl GenKill < Self :: Idx > ,
515
+ trans : & mut Self :: Domain ,
522
516
_statement : & mir:: Statement < ' tcx > ,
523
517
location : Location ,
524
518
) {
525
519
self . kill_loans_out_of_scope_at_location ( trans, location) ;
526
520
}
527
521
528
- fn statement_effect (
522
+ fn apply_statement_effect (
529
523
& mut self ,
530
- trans : & mut impl GenKill < Self :: Idx > ,
524
+ trans : & mut Self :: Domain ,
531
525
stmt : & mir:: Statement < ' tcx > ,
532
526
location : Location ,
533
527
) {
@@ -573,7 +567,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
573
567
}
574
568
}
575
569
576
- fn before_terminator_effect (
570
+ fn apply_before_terminator_effect (
577
571
& mut self ,
578
572
trans : & mut Self :: Domain ,
579
573
_terminator : & mir:: Terminator < ' tcx > ,
@@ -582,7 +576,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
582
576
self . kill_loans_out_of_scope_at_location ( trans, location) ;
583
577
}
584
578
585
- fn terminator_effect < ' mir > (
579
+ fn apply_terminator_effect < ' mir > (
586
580
& mut self ,
587
581
trans : & mut Self :: Domain ,
588
582
terminator : & ' mir mir:: Terminator < ' tcx > ,
@@ -599,14 +593,6 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
599
593
}
600
594
terminator. edges ( )
601
595
}
602
-
603
- fn call_return_effect (
604
- & mut self ,
605
- _trans : & mut Self :: Domain ,
606
- _block : mir:: BasicBlock ,
607
- _return_places : CallReturnPlaces < ' _ , ' tcx > ,
608
- ) {
609
- }
610
596
}
611
597
612
598
impl < C > DebugWithContext < C > for BorrowIndex { }
0 commit comments