@@ -8,7 +8,10 @@ use rustc_middle::mir::{
8
8
} ;
9
9
use rustc_middle:: ty:: { RegionVid , TyCtxt } ;
10
10
use rustc_mir_dataflow:: fmt:: DebugWithContext ;
11
- use rustc_mir_dataflow:: impls:: { EverInitializedPlaces , MaybeUninitializedPlaces } ;
11
+ use rustc_mir_dataflow:: impls:: {
12
+ EverInitializedPlaces , EverInitializedPlacesDomain , MaybeUninitializedPlaces ,
13
+ MaybeUninitializedPlacesDomain ,
14
+ } ;
12
15
use rustc_mir_dataflow:: { Analysis , GenKill , JoinSemiLattice , SwitchIntEdgeEffects } ;
13
16
use tracing:: debug;
14
17
@@ -24,7 +27,7 @@ pub(crate) struct Borrowck<'a, 'tcx> {
24
27
}
25
28
26
29
impl < ' a , ' tcx > Analysis < ' tcx > for Borrowck < ' a , ' tcx > {
27
- type Domain = BorrowckDomain < ' a , ' tcx > ;
30
+ type Domain = BorrowckDomain ;
28
31
29
32
const NAME : & ' static str = "borrowck" ;
30
33
@@ -41,48 +44,48 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
41
44
unreachable ! ( ) ;
42
45
}
43
46
44
- fn apply_before_statement_effect (
47
+ fn apply_early_statement_effect (
45
48
& mut self ,
46
49
state : & mut Self :: Domain ,
47
50
stmt : & mir:: Statement < ' tcx > ,
48
51
loc : Location ,
49
52
) {
50
- self . borrows . apply_before_statement_effect ( & mut state. borrows , stmt, loc) ;
51
- self . uninits . apply_before_statement_effect ( & mut state. uninits , stmt, loc) ;
52
- self . ever_inits . apply_before_statement_effect ( & mut state. ever_inits , stmt, loc) ;
53
+ self . borrows . apply_early_statement_effect ( & mut state. borrows , stmt, loc) ;
54
+ self . uninits . apply_early_statement_effect ( & mut state. uninits , stmt, loc) ;
55
+ self . ever_inits . apply_early_statement_effect ( & mut state. ever_inits , stmt, loc) ;
53
56
}
54
57
55
- fn apply_statement_effect (
58
+ fn apply_primary_statement_effect (
56
59
& mut self ,
57
60
state : & mut Self :: Domain ,
58
61
stmt : & mir:: Statement < ' tcx > ,
59
62
loc : Location ,
60
63
) {
61
- self . borrows . apply_statement_effect ( & mut state. borrows , stmt, loc) ;
62
- self . uninits . apply_statement_effect ( & mut state. uninits , stmt, loc) ;
63
- self . ever_inits . apply_statement_effect ( & mut state. ever_inits , stmt, loc) ;
64
+ self . borrows . apply_primary_statement_effect ( & mut state. borrows , stmt, loc) ;
65
+ self . uninits . apply_primary_statement_effect ( & mut state. uninits , stmt, loc) ;
66
+ self . ever_inits . apply_primary_statement_effect ( & mut state. ever_inits , stmt, loc) ;
64
67
}
65
68
66
- fn apply_before_terminator_effect (
69
+ fn apply_early_terminator_effect (
67
70
& mut self ,
68
71
state : & mut Self :: Domain ,
69
72
term : & mir:: Terminator < ' tcx > ,
70
73
loc : Location ,
71
74
) {
72
- self . borrows . apply_before_terminator_effect ( & mut state. borrows , term, loc) ;
73
- self . uninits . apply_before_terminator_effect ( & mut state. uninits , term, loc) ;
74
- self . ever_inits . apply_before_terminator_effect ( & mut state. ever_inits , term, loc) ;
75
+ self . borrows . apply_early_terminator_effect ( & mut state. borrows , term, loc) ;
76
+ self . uninits . apply_early_terminator_effect ( & mut state. uninits , term, loc) ;
77
+ self . ever_inits . apply_early_terminator_effect ( & mut state. ever_inits , term, loc) ;
75
78
}
76
79
77
- fn apply_terminator_effect < ' mir > (
80
+ fn apply_primary_terminator_effect < ' mir > (
78
81
& mut self ,
79
82
state : & mut Self :: Domain ,
80
83
term : & ' mir mir:: Terminator < ' tcx > ,
81
84
loc : Location ,
82
85
) -> TerminatorEdges < ' mir , ' tcx > {
83
- self . borrows . apply_terminator_effect ( & mut state. borrows , term, loc) ;
84
- self . uninits . apply_terminator_effect ( & mut state. uninits , term, loc) ;
85
- self . ever_inits . apply_terminator_effect ( & mut state. ever_inits , term, loc) ;
86
+ self . borrows . apply_primary_terminator_effect ( & mut state. borrows , term, loc) ;
87
+ self . uninits . apply_primary_terminator_effect ( & mut state. uninits , term, loc) ;
88
+ self . ever_inits . apply_primary_terminator_effect ( & mut state. ever_inits , term, loc) ;
86
89
87
90
// This return value doesn't matter. It's only used by `iterate_to_fixpoint`, which this
88
91
// analysis doesn't use.
@@ -110,14 +113,14 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
110
113
}
111
114
}
112
115
113
- impl JoinSemiLattice for BorrowckDomain < ' _ , ' _ > {
116
+ impl JoinSemiLattice for BorrowckDomain {
114
117
fn join ( & mut self , _other : & Self ) -> bool {
115
118
// This is only reachable from `iterate_to_fixpoint`, which this analysis doesn't use.
116
119
unreachable ! ( ) ;
117
120
}
118
121
}
119
122
120
- impl < ' tcx , C > DebugWithContext < C > for BorrowckDomain < ' _ , ' tcx >
123
+ impl < ' tcx , C > DebugWithContext < C > for BorrowckDomain
121
124
where
122
125
C : rustc_mir_dataflow:: move_paths:: HasMoveData < ' tcx > ,
123
126
{
@@ -160,10 +163,10 @@ where
160
163
161
164
/// The transient state of the dataflow analyses used by the borrow checker.
162
165
#[ derive( Clone , Debug , PartialEq , Eq ) ]
163
- pub ( crate ) struct BorrowckDomain < ' a , ' tcx > {
164
- pub ( crate ) borrows : < Borrows < ' a , ' tcx > as Analysis < ' tcx > > :: Domain ,
165
- pub ( crate ) uninits : < MaybeUninitializedPlaces < ' a , ' tcx > as Analysis < ' tcx > > :: Domain ,
166
- pub ( crate ) ever_inits : < EverInitializedPlaces < ' a , ' tcx > as Analysis < ' tcx > > :: Domain ,
166
+ pub ( crate ) struct BorrowckDomain {
167
+ pub ( crate ) borrows : BorrowsDomain ,
168
+ pub ( crate ) uninits : MaybeUninitializedPlacesDomain ,
169
+ pub ( crate ) ever_inits : EverInitializedPlacesDomain ,
167
170
}
168
171
169
172
rustc_index:: newtype_index! {
@@ -503,7 +506,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
503
506
/// That means they went out of a nonlexical scope
504
507
fn kill_loans_out_of_scope_at_location (
505
508
& self ,
506
- trans : & mut <Self as Analysis < ' tcx > >:: Domain ,
509
+ state : & mut <Self as Analysis < ' tcx > >:: Domain ,
507
510
location : Location ,
508
511
) {
509
512
// NOTE: The state associated with a given `location`
@@ -518,14 +521,14 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
518
521
// region, then setting that gen-bit will override any
519
522
// potential kill introduced here.
520
523
if let Some ( indices) = self . borrows_out_of_scope_at_location . get ( & location) {
521
- trans . kill_all ( indices. iter ( ) . copied ( ) ) ;
524
+ state . kill_all ( indices. iter ( ) . copied ( ) ) ;
522
525
}
523
526
}
524
527
525
528
/// Kill any borrows that conflict with `place`.
526
529
fn kill_borrows_on_place (
527
530
& self ,
528
- trans : & mut <Self as Analysis < ' tcx > >:: Domain ,
531
+ state : & mut <Self as Analysis < ' tcx > >:: Domain ,
529
532
place : Place < ' tcx > ,
530
533
) {
531
534
debug ! ( "kill_borrows_on_place: place={:?}" , place) ;
@@ -543,7 +546,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
543
546
// `places_conflict` for every borrow.
544
547
if place. projection . is_empty ( ) {
545
548
if !self . body . local_decls [ place. local ] . is_ref_to_static ( ) {
546
- trans . kill_all ( other_borrows_of_local) ;
549
+ state . kill_all ( other_borrows_of_local) ;
547
550
}
548
551
return ;
549
552
}
@@ -562,10 +565,12 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
562
565
)
563
566
} ) ;
564
567
565
- trans . kill_all ( definitely_conflicting_borrows) ;
568
+ state . kill_all ( definitely_conflicting_borrows) ;
566
569
}
567
570
}
568
571
572
+ type BorrowsDomain = BitSet < BorrowIndex > ;
573
+
569
574
/// Forward dataflow computation of the set of borrows that are in scope at a particular location.
570
575
/// - we gen the introduced loans
571
576
/// - we kill loans on locals going out of (regular) scope
@@ -574,7 +579,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
574
579
/// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
575
580
/// `a.b.c` when `a` is overwritten.
576
581
impl < ' tcx > rustc_mir_dataflow:: Analysis < ' tcx > for Borrows < ' _ , ' tcx > {
577
- type Domain = BitSet < BorrowIndex > ;
582
+ type Domain = BorrowsDomain ;
578
583
579
584
const NAME : & ' static str = "borrows" ;
580
585
@@ -588,18 +593,18 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
588
593
// function execution, so this method has no effect.
589
594
}
590
595
591
- fn apply_before_statement_effect (
596
+ fn apply_early_statement_effect (
592
597
& mut self ,
593
- trans : & mut Self :: Domain ,
598
+ state : & mut Self :: Domain ,
594
599
_statement : & mir:: Statement < ' tcx > ,
595
600
location : Location ,
596
601
) {
597
- self . kill_loans_out_of_scope_at_location ( trans , location) ;
602
+ self . kill_loans_out_of_scope_at_location ( state , location) ;
598
603
}
599
604
600
- fn apply_statement_effect (
605
+ fn apply_primary_statement_effect (
601
606
& mut self ,
602
- trans : & mut Self :: Domain ,
607
+ state : & mut Self :: Domain ,
603
608
stmt : & mir:: Statement < ' tcx > ,
604
609
location : Location ,
605
610
) {
@@ -617,18 +622,18 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
617
622
panic ! ( "could not find BorrowIndex for location {location:?}" ) ;
618
623
} ) ;
619
624
620
- trans . gen_ ( index) ;
625
+ state . gen_ ( index) ;
621
626
}
622
627
623
628
// Make sure there are no remaining borrows for variables
624
629
// that are assigned over.
625
- self . kill_borrows_on_place ( trans , * lhs) ;
630
+ self . kill_borrows_on_place ( state , * lhs) ;
626
631
}
627
632
628
633
mir:: StatementKind :: StorageDead ( local) => {
629
634
// Make sure there are no remaining borrows for locals that
630
635
// are gone out of scope.
631
- self . kill_borrows_on_place ( trans , Place :: from ( * local) ) ;
636
+ self . kill_borrows_on_place ( state , Place :: from ( * local) ) ;
632
637
}
633
638
634
639
mir:: StatementKind :: FakeRead ( ..)
@@ -646,18 +651,18 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
646
651
}
647
652
}
648
653
649
- fn apply_before_terminator_effect (
654
+ fn apply_early_terminator_effect (
650
655
& mut self ,
651
- trans : & mut Self :: Domain ,
656
+ state : & mut Self :: Domain ,
652
657
_terminator : & mir:: Terminator < ' tcx > ,
653
658
location : Location ,
654
659
) {
655
- self . kill_loans_out_of_scope_at_location ( trans , location) ;
660
+ self . kill_loans_out_of_scope_at_location ( state , location) ;
656
661
}
657
662
658
- fn apply_terminator_effect < ' mir > (
663
+ fn apply_primary_terminator_effect < ' mir > (
659
664
& mut self ,
660
- trans : & mut Self :: Domain ,
665
+ state : & mut Self :: Domain ,
661
666
terminator : & ' mir mir:: Terminator < ' tcx > ,
662
667
_location : Location ,
663
668
) -> TerminatorEdges < ' mir , ' tcx > {
@@ -666,7 +671,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
666
671
if let mir:: InlineAsmOperand :: Out { place : Some ( place) , .. }
667
672
| mir:: InlineAsmOperand :: InOut { out_place : Some ( place) , .. } = * op
668
673
{
669
- self . kill_borrows_on_place ( trans , place) ;
674
+ self . kill_borrows_on_place ( state , place) ;
670
675
}
671
676
}
672
677
}
0 commit comments