@@ -34,6 +34,7 @@ use crate::{
34
34
} ,
35
35
type_check:: { free_region_relations:: UniversalRegionRelations , Locations } ,
36
36
universal_regions:: UniversalRegions ,
37
+ BorrowckInferCtxt ,
37
38
} ;
38
39
39
40
mod dump_mir;
@@ -243,6 +244,59 @@ pub enum ExtraConstraintInfo {
243
244
PlaceholderFromPredicate ( Span ) ,
244
245
}
245
246
247
+ #[ cfg( debug_assertions) ]
248
+ #[ instrument( skip( infcx, sccs) , level = "debug" ) ]
249
+ fn sccs_info < ' cx , ' tcx > (
250
+ infcx : & ' cx BorrowckInferCtxt < ' cx , ' tcx > ,
251
+ sccs : Rc < Sccs < RegionVid , ConstraintSccIndex > > ,
252
+ ) {
253
+ use crate :: renumber:: RegionCtxt ;
254
+
255
+ let var_to_origin = infcx. reg_var_to_origin . borrow ( ) ;
256
+ let num_components = sccs. scc_data . ranges . len ( ) ;
257
+ let mut components = vec ! [ FxHashSet :: default ( ) ; num_components] ;
258
+
259
+ for ( reg_var_idx, scc_idx) in sccs. scc_indices . iter ( ) . enumerate ( ) {
260
+ let reg_var = ty:: RegionVid :: from_usize ( reg_var_idx) ;
261
+ let origin = var_to_origin. get ( & reg_var) . unwrap_or_else ( || & RegionCtxt :: Unknown ) ;
262
+ components[ scc_idx. as_usize ( ) ] . insert ( * origin) ;
263
+ }
264
+
265
+ debug ! (
266
+ "strongly connected components: {:#?}" ,
267
+ components
268
+ . iter( )
269
+ . enumerate( )
270
+ . map( |( idx, origin) | { ( ConstraintSccIndex :: from_usize( idx) , origin) } )
271
+ . collect:: <Vec <_>>( )
272
+ ) ;
273
+
274
+ // Now let's calculate the best representative for each component
275
+ let components_representatives = components
276
+ . into_iter ( )
277
+ . enumerate ( )
278
+ . map ( |( scc_idx, region_ctxts) | {
279
+ let repr = region_ctxts
280
+ . into_iter ( )
281
+ . max_by ( |x, y| x. _preference_value ( ) . cmp ( & y. _preference_value ( ) ) )
282
+ . unwrap ( ) ;
283
+
284
+ ( ConstraintSccIndex :: from_usize ( scc_idx) , repr)
285
+ } )
286
+ . collect :: < FxHashMap < _ , _ > > ( ) ;
287
+
288
+ let mut scc_node_to_edges = FxHashMap :: default ( ) ;
289
+ for ( scc_idx, repr) in components_representatives. iter ( ) {
290
+ let edges_range = sccs. scc_data . ranges [ * scc_idx] . clone ( ) ;
291
+ let edges = & sccs. scc_data . all_successors [ edges_range] ;
292
+ let edge_representatives =
293
+ edges. iter ( ) . map ( |scc_idx| components_representatives[ scc_idx] ) . collect :: < Vec < _ > > ( ) ;
294
+ scc_node_to_edges. insert ( ( scc_idx, repr) , edge_representatives) ;
295
+ }
296
+
297
+ debug ! ( "SCC edges {:#?}" , scc_node_to_edges) ;
298
+ }
299
+
246
300
impl < ' tcx > RegionInferenceContext < ' tcx > {
247
301
/// Creates a new region inference context with a total of
248
302
/// `num_region_variables` valid inference variables; the first N
@@ -251,7 +305,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
251
305
///
252
306
/// The `outlives_constraints` and `type_tests` are an initial set
253
307
/// of constraints produced by the MIR type check.
254
- pub ( crate ) fn new (
308
+ pub ( crate ) fn new < ' cx > (
309
+ _infcx : & BorrowckInferCtxt < ' cx , ' tcx > ,
255
310
var_infos : VarInfos ,
256
311
universal_regions : Rc < UniversalRegions < ' tcx > > ,
257
312
placeholder_indices : Rc < PlaceholderIndices > ,
@@ -263,6 +318,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
263
318
liveness_constraints : LivenessValues < RegionVid > ,
264
319
elements : & Rc < RegionValueElements > ,
265
320
) -> Self {
321
+ debug ! ( "universal_regions: {:#?}" , universal_regions) ;
322
+ debug ! ( "outlives constraints: {:#?}" , outlives_constraints) ;
323
+ debug ! ( "placeholder_indices: {:#?}" , placeholder_indices) ;
324
+ debug ! ( "type tests: {:#?}" , type_tests) ;
325
+
266
326
// Create a RegionDefinition for each inference variable.
267
327
let definitions: IndexVec < _ , _ > = var_infos
268
328
. iter ( )
@@ -274,6 +334,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
274
334
let fr_static = universal_regions. fr_static ;
275
335
let constraint_sccs = Rc :: new ( constraints. compute_sccs ( & constraint_graph, fr_static) ) ;
276
336
337
+ #[ cfg( debug_assertions) ]
338
+ {
339
+ sccs_info ( _infcx, constraint_sccs. clone ( ) ) ;
340
+ }
341
+
277
342
let mut scc_values =
278
343
RegionValues :: new ( elements, universal_regions. len ( ) , & placeholder_indices) ;
279
344
0 commit comments