@@ -180,20 +180,20 @@ impl ToElementIndex for RegionElementIndex {
180
180
/// compact `SparseBitMatrix` representation, with one row per region
181
181
/// variable. The columns consist of either universal regions or
182
182
/// points in the CFG.
183
- pub ( super ) struct RegionValues {
183
+ pub ( super ) struct RegionValues < N : Idx > {
184
184
elements : Rc < RegionValueElements > ,
185
- matrix : SparseBitMatrix < RegionVid , RegionElementIndex > ,
185
+ matrix : SparseBitMatrix < N , RegionElementIndex > ,
186
186
187
187
/// If cause tracking is enabled, maps from a pair (r, e)
188
188
/// consisting of a region `r` that contains some element `e` to
189
189
/// the reason that the element is contained. There should be an
190
190
/// entry for every bit set to 1 in `SparseBitMatrix`.
191
- causes : Option < CauseMap > ,
191
+ causes : Option < CauseMap < N > > ,
192
192
}
193
193
194
- type CauseMap = FxHashMap < ( RegionVid , RegionElementIndex ) , Cause > ;
194
+ type CauseMap < N > = FxHashMap < ( N , RegionElementIndex ) , Cause > ;
195
195
196
- impl RegionValues {
196
+ impl < N : Idx > RegionValues < N > {
197
197
/// Creates a new set of "region values" that tracks causal information.
198
198
/// Each of the regions in num_region_variables will be initialized with an
199
199
/// empty set of points and no causal information.
@@ -206,7 +206,7 @@ impl RegionValues {
206
206
Self {
207
207
elements : elements. clone ( ) ,
208
208
matrix : SparseBitMatrix :: new (
209
- RegionVid :: new ( num_region_variables) ,
209
+ N :: new ( num_region_variables) ,
210
210
RegionElementIndex :: new ( elements. num_elements ( ) ) ,
211
211
) ,
212
212
causes : Some ( CauseMap :: default ( ) ) ,
@@ -235,7 +235,7 @@ impl RegionValues {
235
235
/// the element is newly added (i.e., was not already present).
236
236
pub ( super ) fn add_element < E : ToElementIndex > (
237
237
& mut self ,
238
- r : RegionVid ,
238
+ r : N ,
239
239
elem : E ,
240
240
cause : & Cause ,
241
241
) -> bool {
@@ -245,18 +245,20 @@ impl RegionValues {
245
245
246
246
/// Add all elements in `r_from` to `r_to` (because e.g. `r_to:
247
247
/// r_from`).
248
- pub ( super ) fn add_region ( & mut self , r_to : RegionVid , r_from : RegionVid ) -> bool {
248
+ pub ( super ) fn add_region ( & mut self , r_to : N , r_from : N ) -> bool {
249
249
self . matrix . merge ( r_from, r_to)
250
250
}
251
251
252
252
/// Internal method to add an element to a region.
253
253
///
254
254
/// Takes a "lazy" cause -- this function will return the cause, but it will only
255
255
/// be invoked if cause tracking is enabled.
256
- fn add_internal < F > ( & mut self , r : RegionVid , i : RegionElementIndex , make_cause : F ) -> bool
257
- where
258
- F : FnOnce ( & CauseMap ) -> Cause ,
259
- {
256
+ fn add_internal (
257
+ & mut self ,
258
+ r : N ,
259
+ i : RegionElementIndex ,
260
+ make_cause : impl FnOnce ( & CauseMap < N > ) -> Cause ,
261
+ ) -> bool {
260
262
if self . matrix . add ( r, i) {
261
263
debug ! ( "add(r={:?}, i={:?})" , r, self . elements. to_element( i) ) ;
262
264
@@ -284,14 +286,14 @@ impl RegionValues {
284
286
}
285
287
286
288
/// True if the region `r` contains the given element.
287
- pub ( super ) fn contains < E : ToElementIndex > ( & self , r : RegionVid , elem : E ) -> bool {
289
+ pub ( super ) fn contains < E : ToElementIndex > ( & self , r : N , elem : E ) -> bool {
288
290
let i = self . elements . index ( elem) ;
289
291
self . matrix . contains ( r, i)
290
292
}
291
293
292
294
/// True if `sup_region` contains all the CFG points that
293
295
/// `sub_region` contains. Ignores universal regions.
294
- pub ( super ) fn contains_points ( & self , sup_region : RegionVid , sub_region : RegionVid ) -> bool {
296
+ pub ( super ) fn contains_points ( & self , sup_region : N , sub_region : N ) -> bool {
295
297
// This could be done faster by comparing the bitsets. But I
296
298
// am lazy.
297
299
self . element_indices_contained_in ( sub_region)
@@ -304,15 +306,15 @@ impl RegionValues {
304
306
/// `elements_contained_in`.
305
307
pub ( super ) fn element_indices_contained_in < ' a > (
306
308
& ' a self ,
307
- r : RegionVid ,
309
+ r : N ,
308
310
) -> impl Iterator < Item = RegionElementIndex > + ' a {
309
311
self . matrix . iter ( r) . map ( move |i| i)
310
312
}
311
313
312
314
/// Returns just the universal regions that are contained in a given region's value.
313
315
pub ( super ) fn universal_regions_outlived_by < ' a > (
314
316
& ' a self ,
315
- r : RegionVid ,
317
+ r : N ,
316
318
) -> impl Iterator < Item = RegionVid > + ' a {
317
319
self . element_indices_contained_in ( r)
318
320
. map ( move |i| self . elements . to_universal_region ( i) )
@@ -323,14 +325,14 @@ impl RegionValues {
323
325
/// Returns all the elements contained in a given region's value.
324
326
pub ( super ) fn elements_contained_in < ' a > (
325
327
& ' a self ,
326
- r : RegionVid ,
328
+ r : N ,
327
329
) -> impl Iterator < Item = RegionElement > + ' a {
328
330
self . element_indices_contained_in ( r)
329
331
. map ( move |r| self . elements . to_element ( r) )
330
332
}
331
333
332
334
/// Returns a "pretty" string value of the region. Meant for debugging.
333
- pub ( super ) fn region_value_str ( & self , r : RegionVid ) -> String {
335
+ pub ( super ) fn region_value_str ( & self , r : N ) -> String {
334
336
let mut result = String :: new ( ) ;
335
337
result. push_str ( "{" ) ;
336
338
@@ -404,7 +406,7 @@ impl RegionValues {
404
406
///
405
407
/// Returns None if cause tracking is disabled or `elem` is not
406
408
/// actually found in `r`.
407
- pub ( super ) fn cause < T : ToElementIndex > ( & self , r : RegionVid , elem : T ) -> Option < Cause > {
409
+ pub ( super ) fn cause < T : ToElementIndex > ( & self , r : N , elem : T ) -> Option < Cause > {
408
410
let index = self . elements . index ( elem) ;
409
411
if let Some ( causes) = & self . causes {
410
412
causes. get ( & ( r, index) ) . cloned ( )
0 commit comments