@@ -735,20 +735,31 @@ impl Map {
735
735
}
736
736
737
737
/// Locates the given place, if it exists in the tree.
738
- pub fn find ( & self , place : PlaceRef < ' _ > ) -> Option < PlaceIndex > {
738
+ pub fn find_extra (
739
+ & self ,
740
+ place : PlaceRef < ' _ > ,
741
+ extra : impl IntoIterator < Item = TrackElem > ,
742
+ ) -> Option < PlaceIndex > {
739
743
let mut index = * self . locals . get ( place. local ) ?. as_ref ( ) ?;
740
744
741
745
for & elem in place. projection {
742
746
index = self . apply ( index, elem. try_into ( ) . ok ( ) ?) ?;
743
747
}
748
+ for elem in extra {
749
+ index = self . apply ( index, elem) ?;
750
+ }
744
751
745
752
Some ( index)
746
753
}
747
754
748
755
/// Locates the given place, if it exists in the tree.
756
+ pub fn find ( & self , place : PlaceRef < ' _ > ) -> Option < PlaceIndex > {
757
+ self . find_extra ( place, [ ] )
758
+ }
759
+
760
+ /// Locates the given place and applies `Discriminant`, if it exists in the tree.
749
761
pub fn find_discr ( & self , place : PlaceRef < ' _ > ) -> Option < PlaceIndex > {
750
- let index = self . find ( place) ?;
751
- self . apply ( index, TrackElem :: Discriminant )
762
+ self . find_extra ( place, [ TrackElem :: Discriminant ] )
752
763
}
753
764
754
765
/// Iterate over all direct children.
@@ -763,14 +774,14 @@ impl Map {
763
774
///
764
775
/// `tail_elem` allows to support discriminants that are not a place in MIR, but that we track
765
776
/// as such.
766
- fn for_each_aliasing_place (
777
+ pub fn for_each_aliasing_place (
767
778
& self ,
768
779
place : PlaceRef < ' _ > ,
769
780
tail_elem : Option < TrackElem > ,
770
781
f : & mut impl FnMut ( PlaceIndex ) ,
771
782
) {
772
783
let Some ( & Some ( mut index) ) = self . locals . get ( place. local ) else {
773
- // The local is not tracked at all, nothing to invalidate .
784
+ // The local is not tracked at all, so it does not alias anything .
774
785
return ;
775
786
} ;
776
787
let elems = place
@@ -782,7 +793,7 @@ impl Map {
782
793
let Ok ( elem) = elem else { return } ;
783
794
let sub = self . apply ( index, elem) ;
784
795
if let TrackElem :: Variant ( ..) | TrackElem :: Discriminant = elem {
785
- // Writing to an enum variant field invalidates the other variants and the discriminant .
796
+ // Enum variant fields and enum discriminants alias each another .
786
797
self . for_each_variant_sibling ( index, sub, f) ;
787
798
}
788
799
if let Some ( sub) = sub {
@@ -795,7 +806,7 @@ impl Map {
795
806
}
796
807
797
808
/// Invoke the given function on all the descendants of the given place, except one branch.
798
- pub fn for_each_variant_sibling (
809
+ fn for_each_variant_sibling (
799
810
& self ,
800
811
parent : PlaceIndex ,
801
812
preserved_child : Option < PlaceIndex > ,
0 commit comments