@@ -12,8 +12,6 @@ use rustc::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable};
12
12
use rustc_data_structures:: binary_search_util;
13
13
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
14
14
use rustc_data_structures:: graph:: scc:: Sccs ;
15
- use rustc_data_structures:: graph:: vec_graph:: VecGraph ;
16
- use rustc_data_structures:: graph:: WithSuccessors ;
17
15
use rustc_hir:: def_id:: DefId ;
18
16
use rustc_index:: bit_set:: BitSet ;
19
17
use rustc_index:: vec:: IndexVec ;
@@ -26,6 +24,7 @@ use crate::borrow_check::{
26
24
diagnostics:: { RegionErrorKind , RegionErrors } ,
27
25
member_constraints:: { MemberConstraintSet , NllMemberConstraintIndex } ,
28
26
nll:: { PoloniusOutput , ToRegionVid } ,
27
+ region_infer:: reverse_sccs:: ReverseSccGraph ,
29
28
region_infer:: values:: {
30
29
LivenessValues , PlaceholderIndices , RegionElement , RegionValueElements , RegionValues ,
31
30
ToElementIndex ,
@@ -37,6 +36,7 @@ use crate::borrow_check::{
37
36
mod dump_mir;
38
37
mod graphviz;
39
38
mod opaque_types;
39
+ mod reverse_sccs;
40
40
41
41
pub mod values;
42
42
@@ -66,9 +66,10 @@ pub struct RegionInferenceContext<'tcx> {
66
66
/// compute the values of each region.
67
67
constraint_sccs : Rc < Sccs < RegionVid , ConstraintSccIndex > > ,
68
68
69
- /// Reverse of the SCC constraint graph -- i.e., an edge `A -> B`
70
- /// exists if `B: A`. Computed lazilly.
71
- rev_constraint_graph : Option < Rc < VecGraph < ConstraintSccIndex > > > ,
69
+ /// Reverse of the SCC constraint graph -- i.e., an edge `A -> B` exists if
70
+ /// `B: A`. This is used to compute the universal regions that are required
71
+ /// to outlive a given SCC. Computed lazily.
72
+ rev_scc_graph : Option < Rc < ReverseSccGraph > > ,
72
73
73
74
/// The "R0 member of [R1..Rn]" constraints, indexed by SCC.
74
75
member_constraints : Rc < MemberConstraintSet < ' tcx , ConstraintSccIndex > > ,
@@ -288,7 +289,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
288
289
constraints,
289
290
constraint_graph,
290
291
constraint_sccs,
291
- rev_constraint_graph : None ,
292
+ rev_scc_graph : None ,
292
293
member_constraints,
293
294
member_constraints_applied : Vec :: new ( ) ,
294
295
closure_bounds_mapping,
@@ -680,15 +681,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
680
681
// free region that must outlive the member region `R0` (`UB:
681
682
// R0`). Therefore, we need only keep an option `O` if `UB: O`
682
683
// for all UB.
683
- if choice_regions. len ( ) > 1 {
684
- let universal_region_relations = self . universal_region_relations . clone ( ) ;
685
- let rev_constraint_graph = self . rev_constraint_graph ( ) ;
686
- for ub in self . upper_bounds ( scc, & rev_constraint_graph) {
687
- debug ! ( "apply_member_constraint: ub={:?}" , ub) ;
688
- choice_regions. retain ( |& o_r| universal_region_relations. outlives ( ub, o_r) ) ;
689
- }
690
- debug ! ( "apply_member_constraint: after ub, choice_regions={:?}" , choice_regions) ;
684
+ let rev_scc_graph = self . reverse_scc_graph ( ) ;
685
+ let universal_region_relations = & self . universal_region_relations ;
686
+ for ub in rev_scc_graph. upper_bounds ( scc) {
687
+ debug ! ( "apply_member_constraint: ub={:?}" , ub) ;
688
+ choice_regions. retain ( |& o_r| universal_region_relations. outlives ( ub, o_r) ) ;
691
689
}
690
+ debug ! ( "apply_member_constraint: after ub, choice_regions={:?}" , choice_regions) ;
692
691
693
692
// If we ruled everything out, we're done.
694
693
if choice_regions. is_empty ( ) {
@@ -744,32 +743,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
744
743
}
745
744
}
746
745
747
- /// Compute and return the reverse SCC-based constraint graph (lazilly).
748
- fn upper_bounds (
749
- & ' a mut self ,
750
- scc0 : ConstraintSccIndex ,
751
- rev_constraint_graph : & ' a VecGraph < ConstraintSccIndex > ,
752
- ) -> impl Iterator < Item = RegionVid > + ' a {
753
- let scc_values = & self . scc_values ;
754
- let mut duplicates = FxHashSet :: default ( ) ;
755
- rev_constraint_graph
756
- . depth_first_search ( scc0)
757
- . skip ( 1 )
758
- . flat_map ( move |scc1| scc_values. universal_regions_outlived_by ( scc1) )
759
- . filter ( move |& r| duplicates. insert ( r) )
760
- }
761
-
762
- /// Compute and return the reverse SCC-based constraint graph (lazilly).
763
- fn rev_constraint_graph ( & mut self ) -> Rc < VecGraph < ConstraintSccIndex > > {
764
- if let Some ( g) = & self . rev_constraint_graph {
765
- return g. clone ( ) ;
766
- }
767
-
768
- let rev_graph = Rc :: new ( self . constraint_sccs . reverse ( ) ) ;
769
- self . rev_constraint_graph = Some ( rev_graph. clone ( ) ) ;
770
- rev_graph
771
- }
772
-
773
746
/// Returns `true` if all the elements in the value of `scc_b` are nameable
774
747
/// in `scc_a`. Used during constraint propagation, and only once
775
748
/// the value of `scc_b` has been computed.
0 commit comments