11use rustc_data_structures:: fx:: FxIndexMap ;
22use rustc_data_structures:: graph;
33use 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 } ;
75use rustc_middle:: ty:: { RegionVid , TyCtxt } ;
86use rustc_mir_dataflow:: fmt:: DebugWithContext ;
97use 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 } ;
119use tracing:: debug;
1210
1311use crate :: { BorrowSet , PlaceConflictBias , PlaceExt , RegionInferenceContext , places_conflict} ;
@@ -22,9 +20,9 @@ pub(crate) struct BorrowckResults<'a, 'tcx> {
2220/// The transient state of the dataflow analyses used by the borrow checker.
2321#[ derive( Debug ) ]
2422pub ( 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 ,
2826}
2927
3028impl < ' a , ' tcx > ResultsVisitable < ' tcx > for BorrowckResults < ' a , ' tcx > {
@@ -427,7 +425,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
427425 /// That means they went out of a nonlexical scope
428426 fn kill_loans_out_of_scope_at_location (
429427 & self ,
430- trans : & mut impl GenKill < BorrowIndex > ,
428+ trans : & mut < Self as Analysis < ' tcx > > :: Domain ,
431429 location : Location ,
432430 ) {
433431 // NOTE: The state associated with a given `location`
@@ -447,7 +445,11 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
447445 }
448446
449447 /// 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+ ) {
451453 debug ! ( "kill_borrows_on_place: place={:?}" , place) ;
452454
453455 let other_borrows_of_local = self
@@ -486,7 +488,14 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
486488 }
487489}
488490
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 > {
490499 type Domain = BitSet < BorrowIndex > ;
491500
492501 const NAME : & ' static str = "borrows" ;
@@ -500,34 +509,19 @@ impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
500509 // no borrows of code region_scopes have been taken prior to
501510 // function execution, so this method has no effect.
502511 }
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- }
518512
519- fn before_statement_effect (
513+ fn apply_before_statement_effect (
520514 & mut self ,
521- trans : & mut impl GenKill < Self :: Idx > ,
515+ trans : & mut Self :: Domain ,
522516 _statement : & mir:: Statement < ' tcx > ,
523517 location : Location ,
524518 ) {
525519 self . kill_loans_out_of_scope_at_location ( trans, location) ;
526520 }
527521
528- fn statement_effect (
522+ fn apply_statement_effect (
529523 & mut self ,
530- trans : & mut impl GenKill < Self :: Idx > ,
524+ trans : & mut Self :: Domain ,
531525 stmt : & mir:: Statement < ' tcx > ,
532526 location : Location ,
533527 ) {
@@ -573,7 +567,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
573567 }
574568 }
575569
576- fn before_terminator_effect (
570+ fn apply_before_terminator_effect (
577571 & mut self ,
578572 trans : & mut Self :: Domain ,
579573 _terminator : & mir:: Terminator < ' tcx > ,
@@ -582,7 +576,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
582576 self . kill_loans_out_of_scope_at_location ( trans, location) ;
583577 }
584578
585- fn terminator_effect < ' mir > (
579+ fn apply_terminator_effect < ' mir > (
586580 & mut self ,
587581 trans : & mut Self :: Domain ,
588582 terminator : & ' mir mir:: Terminator < ' tcx > ,
@@ -599,14 +593,6 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
599593 }
600594 terminator. edges ( )
601595 }
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- }
610596}
611597
612598impl < C > DebugWithContext < C > for BorrowIndex { }
0 commit comments