11use std:: fmt:: Debug ;
22use std:: rc:: Rc ;
33
4- use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
4+ use rustc_data_structures:: fx:: FxIndexSet ;
55use rustc_index:: Idx ;
66use rustc_index:: bit_set:: SparseBitMatrix ;
77use rustc_index:: interval:: { IntervalSet , SparseIntervalMatrix } ;
@@ -42,15 +42,11 @@ pub(crate) struct LivenessValues {
4242 /// The map from locations to points.
4343 location_map : Rc < DenseLocationMap > ,
4444
45- /// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and
46- /// currently only used for validating promoteds (which don't care about more precise tracking).
47- live_regions : Option < FxHashSet < RegionVid > > ,
48-
4945 /// For each region: the points where it is live.
5046 ///
5147 /// This is not initialized for promoteds, because we don't care *where* within a promoted a
5248 /// region is live, only that it is.
53- points : Option < SparseIntervalMatrix < RegionVid , PointIndex > > ,
49+ points : SparseIntervalMatrix < RegionVid , PointIndex > ,
5450
5551 /// When using `-Zpolonius=next`, the set of loans that are live at a given point in the CFG.
5652 live_loans : Option < LiveLoans > ,
@@ -60,21 +56,7 @@ impl LivenessValues {
6056 /// Create an empty map of regions to locations where they're live.
6157 pub ( crate ) fn with_specific_points ( location_map : Rc < DenseLocationMap > ) -> Self {
6258 LivenessValues {
63- live_regions : None ,
64- points : Some ( SparseIntervalMatrix :: new ( location_map. num_points ( ) ) ) ,
65- location_map,
66- live_loans : None ,
67- }
68- }
69-
70- /// Create an empty map of regions to locations where they're live.
71- ///
72- /// Unlike `with_specific_points`, does not track exact locations where something is live, only
73- /// which regions are live.
74- pub ( crate ) fn without_specific_points ( location_map : Rc < DenseLocationMap > ) -> Self {
75- LivenessValues {
76- live_regions : Some ( Default :: default ( ) ) ,
77- points : None ,
59+ points : SparseIntervalMatrix :: new ( location_map. num_points ( ) ) ,
7860 location_map,
7961 live_loans : None ,
8062 }
@@ -83,52 +65,30 @@ impl LivenessValues {
8365 /// Returns the liveness matrix of points where each region is live. Panics if the liveness
8466 /// values have been created without any per-point data (that is, for promoteds).
8567 pub ( crate ) fn points ( & self ) -> & SparseIntervalMatrix < RegionVid , PointIndex > {
86- self . points
87- . as_ref ( )
88- . expect ( "this `LivenessValues` wasn't created using `with_specific_points`" )
68+ & self . points
8969 }
9070
9171 /// Iterate through each region that has a value in this set.
9272 pub ( crate ) fn regions ( & self ) -> impl Iterator < Item = RegionVid > {
93- self . points . as_ref ( ) . expect ( "use with_specific_points" ) . rows ( )
94- }
95-
96- /// Iterate through each region that has a value in this set.
97- // We are passing query instability implications to the caller.
98- #[ rustc_lint_query_instability]
99- #[ allow( rustc:: potential_query_instability) ]
100- pub ( crate ) fn live_regions_unordered ( & self ) -> impl Iterator < Item = RegionVid > {
101- self . live_regions . as_ref ( ) . unwrap ( ) . iter ( ) . copied ( )
73+ self . points . rows ( )
10274 }
10375
10476 /// Records `region` as being live at the given `location`.
10577 pub ( crate ) fn add_location ( & mut self , region : RegionVid , location : Location ) {
10678 let point = self . location_map . point_from_location ( location) ;
10779 debug ! ( "LivenessValues::add_location(region={:?}, location={:?})" , region, location) ;
108- if let Some ( points) = & mut self . points {
109- points. insert ( region, point) ;
110- } else if self . location_map . point_in_range ( point) {
111- self . live_regions . as_mut ( ) . unwrap ( ) . insert ( region) ;
112- }
80+ self . points . insert ( region, point) ;
11381 }
11482
11583 /// Records `region` as being live at all the given `points`.
11684 pub ( crate ) fn add_points ( & mut self , region : RegionVid , points : & IntervalSet < PointIndex > ) {
11785 debug ! ( "LivenessValues::add_points(region={:?}, points={:?})" , region, points) ;
118- if let Some ( this) = & mut self . points {
119- this. union_row ( region, points) ;
120- } else if points. iter ( ) . any ( |point| self . location_map . point_in_range ( point) ) {
121- self . live_regions . as_mut ( ) . unwrap ( ) . insert ( region) ;
122- }
86+ self . points . union_row ( region, points) ;
12387 }
12488
12589 /// Records `region` as being live at all the control-flow points.
12690 pub ( crate ) fn add_all_points ( & mut self , region : RegionVid ) {
127- if let Some ( points) = & mut self . points {
128- points. insert_all_into_row ( region) ;
129- } else {
130- self . live_regions . as_mut ( ) . unwrap ( ) . insert ( region) ;
131- }
91+ self . points . insert_all_into_row ( region) ;
13292 }
13393
13494 /// Returns whether `region` is marked live at the given
@@ -142,23 +102,12 @@ impl LivenessValues {
142102 /// [`point`][rustc_mir_dataflow::points::PointIndex].
143103 #[ inline]
144104 pub ( crate ) fn is_live_at_point ( & self , region : RegionVid , point : PointIndex ) -> bool {
145- if let Some ( points) = & self . points {
146- points. row ( region) . is_some_and ( |r| r. contains ( point) )
147- } else {
148- unreachable ! (
149- "Should be using LivenessValues::with_specific_points to ask whether live at a location"
150- )
151- }
105+ self . points . row ( region) . is_some_and ( |r| r. contains ( point) )
152106 }
153107
154108 /// Returns an iterator of all the points where `region` is live.
155109 fn live_points ( & self , region : RegionVid ) -> impl Iterator < Item = PointIndex > {
156- let Some ( points) = & self . points else {
157- unreachable ! (
158- "Should be using LivenessValues::with_specific_points to ask whether live at a location"
159- )
160- } ;
161- points
110+ self . points
162111 . row ( region)
163112 . into_iter ( )
164113 . flat_map ( |set| set. iter ( ) )
@@ -328,10 +277,7 @@ impl<'tcx, N: Idx> RegionValues<'tcx, N> {
328277 /// elements for the region `from` from `values` and add them to
329278 /// the region `to` in `self`.
330279 pub ( crate ) fn merge_liveness ( & mut self , to : N , from : RegionVid , values : & LivenessValues ) {
331- let Some ( value_points) = & values. points else {
332- panic ! ( "LivenessValues must track specific points for use in merge_liveness" ) ;
333- } ;
334- if let Some ( set) = value_points. row ( from) {
280+ if let Some ( set) = values. points . row ( from) {
335281 self . points . union_row ( to, set) ;
336282 }
337283 }
0 commit comments