@@ -34,6 +34,7 @@ use crate::{
3434 } ,
3535 type_check:: { free_region_relations:: UniversalRegionRelations , Locations } ,
3636 universal_regions:: UniversalRegions ,
37+ BorrowckInferCtxt ,
3738} ;
3839
3940mod dump_mir;
@@ -243,6 +244,59 @@ pub enum ExtraConstraintInfo {
243244 PlaceholderFromPredicate ( Span ) ,
244245}
245246
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+
246300impl < ' tcx > RegionInferenceContext < ' tcx > {
247301 /// Creates a new region inference context with a total of
248302 /// `num_region_variables` valid inference variables; the first N
@@ -251,7 +305,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
251305 ///
252306 /// The `outlives_constraints` and `type_tests` are an initial set
253307 /// of constraints produced by the MIR type check.
254- pub ( crate ) fn new (
308+ pub ( crate ) fn new < ' cx > (
309+ _infcx : & BorrowckInferCtxt < ' cx , ' tcx > ,
255310 var_infos : VarInfos ,
256311 universal_regions : Rc < UniversalRegions < ' tcx > > ,
257312 placeholder_indices : Rc < PlaceholderIndices > ,
@@ -263,6 +318,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
263318 liveness_constraints : LivenessValues < RegionVid > ,
264319 elements : & Rc < RegionValueElements > ,
265320 ) -> 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+
266326 // Create a RegionDefinition for each inference variable.
267327 let definitions: IndexVec < _ , _ > = var_infos
268328 . iter ( )
@@ -274,6 +334,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
274334 let fr_static = universal_regions. fr_static ;
275335 let constraint_sccs = Rc :: new ( constraints. compute_sccs ( & constraint_graph, fr_static) ) ;
276336
337+ #[ cfg( debug_assertions) ]
338+ {
339+ sccs_info ( _infcx, constraint_sccs. clone ( ) ) ;
340+ }
341+
277342 let mut scc_values =
278343 RegionValues :: new ( elements, universal_regions. len ( ) , & placeholder_indices) ;
279344
0 commit comments