@@ -36,7 +36,7 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
3636 fn bottom_value ( & self , body : & mir:: Body < ' tcx > ) -> Self :: Domain {
3737 BorrowckDomain {
3838 borrows : self . borrows . bottom_value ( body) ,
39- pins : self . pins . bottom_value ( body) ,
39+ pinned_borrows : self . pins . bottom_value ( body) ,
4040 uninits : self . uninits . bottom_value ( body) ,
4141 ever_inits : self . ever_inits . bottom_value ( body) ,
4242 }
@@ -54,7 +54,7 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
5454 loc : Location ,
5555 ) {
5656 self . borrows . apply_early_statement_effect ( & mut state. borrows , stmt, loc) ;
57- self . pins . apply_early_statement_effect ( & mut state. pins , stmt, loc) ;
57+ self . pins . apply_early_statement_effect ( & mut state. pinned_borrows , stmt, loc) ;
5858 self . uninits . apply_early_statement_effect ( & mut state. uninits , stmt, loc) ;
5959 self . ever_inits . apply_early_statement_effect ( & mut state. ever_inits , stmt, loc) ;
6060 }
@@ -66,7 +66,7 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
6666 loc : Location ,
6767 ) {
6868 self . borrows . apply_primary_statement_effect ( & mut state. borrows , stmt, loc) ;
69- self . pins . apply_primary_statement_effect ( & mut state. pins , stmt, loc) ;
69+ self . pins . apply_primary_statement_effect ( & mut state. pinned_borrows , stmt, loc) ;
7070 self . uninits . apply_primary_statement_effect ( & mut state. uninits , stmt, loc) ;
7171 self . ever_inits . apply_primary_statement_effect ( & mut state. ever_inits , stmt, loc) ;
7272 }
@@ -78,7 +78,7 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
7878 loc : Location ,
7979 ) {
8080 self . borrows . apply_early_terminator_effect ( & mut state. borrows , term, loc) ;
81- self . pins . apply_early_terminator_effect ( & mut state. pins , term, loc) ;
81+ self . pins . apply_early_terminator_effect ( & mut state. pinned_borrows , term, loc) ;
8282 self . uninits . apply_early_terminator_effect ( & mut state. uninits , term, loc) ;
8383 self . ever_inits . apply_early_terminator_effect ( & mut state. ever_inits , term, loc) ;
8484 }
@@ -90,7 +90,7 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
9090 loc : Location ,
9191 ) -> TerminatorEdges < ' mir , ' tcx > {
9292 self . borrows . apply_primary_terminator_effect ( & mut state. borrows , term, loc) ;
93- self . pins . apply_primary_terminator_effect ( & mut state. pins , term, loc) ;
93+ self . pins . apply_primary_terminator_effect ( & mut state. pinned_borrows , term, loc) ;
9494 self . uninits . apply_primary_terminator_effect ( & mut state. uninits , term, loc) ;
9595 self . ever_inits . apply_primary_terminator_effect ( & mut state. ever_inits , term, loc) ;
9696
@@ -124,8 +124,8 @@ where
124124 fn fmt_with ( & self , ctxt : & C , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
125125 f. write_str ( "borrows: " ) ?;
126126 self . borrows . fmt_with ( ctxt, f) ?;
127- f. write_str ( " pins : " ) ?;
128- self . pins . fmt_with ( ctxt, f) ?;
127+ f. write_str ( " pinned_borrows : " ) ?;
128+ self . pinned_borrows . fmt_with ( ctxt, f) ?;
129129 f. write_str ( " uninits: " ) ?;
130130 self . uninits . fmt_with ( ctxt, f) ?;
131131 f. write_str ( " ever_inits: " ) ?;
@@ -144,9 +144,9 @@ where
144144 f. write_str ( "\n " ) ?;
145145 }
146146
147- if self . pins != old. pins {
148- f. write_str ( "pins : " ) ?;
149- self . pins . fmt_diff_with ( & old. pins , ctxt, f) ?;
147+ if self . pinned_borrows != old. pinned_borrows {
148+ f. write_str ( "pinned_borrows : " ) ?;
149+ self . pinned_borrows . fmt_diff_with ( & old. pinned_borrows , ctxt, f) ?;
150150 f. write_str ( "\n " ) ?;
151151 }
152152
@@ -170,7 +170,7 @@ where
170170#[ derive( Clone , Debug , PartialEq , Eq ) ]
171171pub ( crate ) struct BorrowckDomain {
172172 pub ( crate ) borrows : BorrowsDomain ,
173- pub ( crate ) pins : PinsDomain ,
173+ pub ( crate ) pinned_borrows : BorrowsDomain ,
174174 pub ( crate ) uninits : MaybeUninitializedPlacesDomain ,
175175 pub ( crate ) ever_inits : EverInitializedPlacesDomain ,
176176}
@@ -183,14 +183,6 @@ rustc_index::newtype_index! {
183183
184184impl < C > DebugWithContext < C > for BorrowIndex { }
185185
186- rustc_index:: newtype_index! {
187- #[ orderable]
188- #[ debug_format = "pi{}" ]
189- pub struct PinIndex { }
190- }
191-
192- impl < C > DebugWithContext < C > for PinIndex { }
193-
194186/// `Borrows` stores the data used in the analyses that track the flow
195187/// of borrows.
196188///
@@ -215,7 +207,8 @@ pub struct Borrows<'a, 'tcx> {
215207pub ( crate ) struct Pins < ' a , ' tcx > {
216208 tcx : TyCtxt < ' tcx > ,
217209 body : & ' a Body < ' tcx > ,
218- pin_set : & ' a PinSet < ' tcx > ,
210+ borrow_set : & ' a BorrowSet < ' tcx > ,
211+ pin_set : & ' a PinSet ,
219212}
220213
221214struct OutOfScopePrecomputer < ' a , ' tcx > {
@@ -658,16 +651,26 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
658651}
659652
660653impl < ' a , ' tcx > Pins < ' a , ' tcx > {
661- pub ( crate ) fn new ( tcx : TyCtxt < ' tcx > , body : & ' a Body < ' tcx > , pin_set : & ' a PinSet < ' tcx > ) -> Self {
662- Pins { tcx, body, pin_set }
654+ pub ( crate ) fn new (
655+ tcx : TyCtxt < ' tcx > ,
656+ body : & ' a Body < ' tcx > ,
657+ borrow_set : & ' a BorrowSet < ' tcx > ,
658+ pin_set : & ' a PinSet ,
659+ ) -> Self {
660+ Pins { tcx, body, borrow_set, pin_set }
663661 }
664662
665663 /// Kill any pins whose original pinned place conflicts with `place`.
666664 fn kill_pins_on_place ( & self , state : & mut <Self as Analysis < ' tcx > >:: Domain , place : Place < ' tcx > ) {
667665 debug ! ( "kill_pins_on_place: place={:?}" , place) ;
668666
669- let other_pins_of_local =
670- self . pin_set . local_map . get ( & place. local ) . into_iter ( ) . flat_map ( |ps| ps. iter ( ) ) . copied ( ) ;
667+ let other_pins_of_local = self
668+ . borrow_set
669+ . local_map
670+ . get ( & place. local )
671+ . into_iter ( )
672+ . flat_map ( |bs| bs. iter ( ) )
673+ . copied ( ) ;
671674
672675 // If the place is a local with no projections, all pins of this
673676 // local must be killed. This is purely an optimization so we don't have to call
@@ -685,7 +688,7 @@ impl<'a, 'tcx> Pins<'a, 'tcx> {
685688 places_conflict (
686689 self . tcx ,
687690 self . body ,
688- self . pin_set [ i] . pinned_place ,
691+ self . borrow_set [ i] . borrowed_place ,
689692 place,
690693 PlaceConflictBias :: NoOverlap ,
691694 )
@@ -704,26 +707,24 @@ impl<'a, 'tcx> Pins<'a, 'tcx> {
704707 debug ! ( "kill_pins_by_pin_local: local={:?}" , local) ;
705708
706709 let pins_of_local =
707- self . pin_set . pin_local_map . get ( & local) . into_iter ( ) . flat_map ( |ps| ps . iter ( ) ) . copied ( ) ;
710+ self . pin_set . pin_local_map . get ( & local) . into_iter ( ) . flat_map ( |bs| bs . iter ( ) ) . copied ( ) ;
708711
709712 state. kill_all ( pins_of_local) ;
710713 }
711714}
712715
713- type PinsDomain = MixedBitSet < PinIndex > ;
714-
715716/// Forward dataflow computation of the set of pins that are in scope at a particular location.
716717/// - we gen the introduced pins
717718/// - we kill pins on locals going out of scope
718719/// - we kill pins when the pinned place is moved or overwritten
719720impl < ' tcx > rustc_mir_dataflow:: Analysis < ' tcx > for Pins < ' _ , ' tcx > {
720- type Domain = PinsDomain ;
721+ type Domain = BorrowsDomain ;
721722
722723 const NAME : & ' static str = "pins" ;
723724
724725 fn bottom_value ( & self , _: & mir:: Body < ' tcx > ) -> Self :: Domain {
725726 // bottom = nothing is pinned yet
726- MixedBitSet :: new_empty ( self . pin_set . len ( ) )
727+ MixedBitSet :: new_empty ( self . borrow_set . len ( ) )
727728 }
728729
729730 fn initialize_start_block ( & self , _: & mir:: Body < ' tcx > , _: & mut Self :: Domain ) {
@@ -758,20 +759,26 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Pins<'_, 'tcx> {
758759 ) {
759760 match & stmt. kind {
760761 mir:: StatementKind :: Assign ( box ( lhs, rhs) ) => {
762+ self . kill_pins_on_place ( state, * lhs) ;
763+
761764 // Check if this is a Pin aggregate creation
762765 if let mir:: Rvalue :: Aggregate ( box agg_kind, _) = rhs
763766 && let mir:: AggregateKind :: Adt ( adt_did, _, args, _, _) = agg_kind
764767 && self . tcx . adt_def ( * adt_did) . is_pin ( )
765768 && args. type_at ( 0 ) . is_ref ( )
766769 {
767770 // Generate the pin
768- if let Some ( index) = self . pin_set . get_index_of ( & location) {
771+ for index in self
772+ . pin_set
773+ . pin_location_map
774+ . get ( & location)
775+ . into_iter ( )
776+ . flat_map ( |bs| bs. iter ( ) )
777+ . copied ( )
778+ {
769779 state. gen_ ( index) ;
770780 }
771781 }
772-
773- // Kill any pins on the place being assigned to
774- self . kill_pins_on_place ( state, * lhs) ;
775782 }
776783
777784 mir:: StatementKind :: StorageDead ( local) => {
0 commit comments