@@ -47,12 +47,13 @@ mod reverse_sccs;
47
47
48
48
pub ( crate ) mod values;
49
49
50
- pub ( crate ) type ConstraintSccs = Sccs < RegionVid , ConstraintSccIndex , RegionTracker > ;
50
+ pub ( crate ) type ConstraintSccs = Sccs < RegionVid , ConstraintSccIndex > ;
51
+ pub ( crate ) type AnnotatedSccs = ( ConstraintSccs , IndexVec < ConstraintSccIndex , RegionTracker > ) ;
51
52
52
53
/// An annotation for region graph SCCs that tracks
53
- /// the values of its elements.
54
+ /// the values of its elements. This annotates a single SCC.
54
55
#[ derive( Copy , Debug , Clone ) ]
55
- pub struct RegionTracker {
56
+ pub ( crate ) struct RegionTracker {
56
57
/// The largest universe of a placeholder reached from this SCC.
57
58
/// This includes placeholders within this SCC.
58
59
max_placeholder_universe_reached : UniverseIndex ,
@@ -97,6 +98,32 @@ impl scc::Annotation for RegionTracker {
97
98
}
98
99
}
99
100
101
+ /// A Visitor for SCC annotation construction.
102
+ pub ( crate ) struct SccAnnotations < ' d , ' tcx , A : scc:: Annotation > {
103
+ pub ( crate ) scc_to_annotation : IndexVec < ConstraintSccIndex , A > ,
104
+ definitions : & ' d IndexVec < RegionVid , RegionDefinition < ' tcx > > ,
105
+ }
106
+
107
+ impl < ' d , ' tcx , A : scc:: Annotation > SccAnnotations < ' d , ' tcx , A > {
108
+ pub ( crate ) fn new ( definitions : & ' d IndexVec < RegionVid , RegionDefinition < ' tcx > > ) -> Self {
109
+ Self { scc_to_annotation : IndexVec :: new ( ) , definitions }
110
+ }
111
+ }
112
+
113
+ impl scc:: Annotations < RegionVid > for SccAnnotations < ' _ , ' _ , RegionTracker > {
114
+ fn new ( & self , element : RegionVid ) -> RegionTracker {
115
+ RegionTracker :: new ( element, & self . definitions [ element] )
116
+ }
117
+
118
+ fn annotate_scc ( & mut self , scc : ConstraintSccIndex , annotation : RegionTracker ) {
119
+ let idx = self . scc_to_annotation . push ( annotation) ;
120
+ assert ! ( idx == scc) ;
121
+ }
122
+
123
+ type Ann = RegionTracker ;
124
+ type SccIdx = ConstraintSccIndex ;
125
+ }
126
+
100
127
impl RegionTracker {
101
128
pub ( crate ) fn new ( rvid : RegionVid , definition : & RegionDefinition < ' _ > ) -> Self {
102
129
let ( representative_is_placeholder, representative_is_existential) = match definition. origin
@@ -166,6 +193,8 @@ pub struct RegionInferenceContext<'tcx> {
166
193
/// compute the values of each region.
167
194
constraint_sccs : ConstraintSccs ,
168
195
196
+ scc_annotations : IndexVec < ConstraintSccIndex , RegionTracker > ,
197
+
169
198
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B` exists if
170
199
/// `B: A`. This is used to compute the universal regions that are required
171
200
/// to outlive a given SCC. Computed lazily.
@@ -446,7 +475,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
446
475
447
476
let definitions = create_definitions ( infcx, & universal_regions) ;
448
477
449
- let constraint_sccs =
478
+ let ( constraint_sccs, scc_annotations ) =
450
479
outlives_constraints. add_outlives_static ( & universal_regions, & definitions) ;
451
480
let constraints = Frozen :: freeze ( outlives_constraints) ;
452
481
let constraint_graph = Frozen :: freeze ( constraints. graph ( definitions. len ( ) ) ) ;
@@ -472,6 +501,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
472
501
constraints,
473
502
constraint_graph,
474
503
constraint_sccs,
504
+ scc_annotations,
475
505
rev_scc_graph : None ,
476
506
member_constraints,
477
507
member_constraints_applied : Vec :: new ( ) ,
@@ -798,7 +828,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
798
828
799
829
// If the member region lives in a higher universe, we currently choose
800
830
// the most conservative option by leaving it unchanged.
801
- if !self . constraint_sccs ( ) . annotation ( scc) . min_universe ( ) . is_root ( ) {
831
+ if !self . scc_universe ( scc) . is_root ( ) {
802
832
return ;
803
833
}
804
834
@@ -874,8 +904,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
874
904
/// in `scc_a`. Used during constraint propagation, and only once
875
905
/// the value of `scc_b` has been computed.
876
906
fn universe_compatible ( & self , scc_b : ConstraintSccIndex , scc_a : ConstraintSccIndex ) -> bool {
877
- let a_annotation = self . constraint_sccs ( ) . annotation ( scc_a) ;
878
- let b_annotation = self . constraint_sccs ( ) . annotation ( scc_b) ;
907
+ let a_annotation = self . scc_annotations [ scc_a] ;
908
+ let b_annotation = self . scc_annotations [ scc_b] ;
879
909
let a_universe = a_annotation. min_universe ( ) ;
880
910
881
911
// If scc_b's declared universe is a subset of
@@ -991,7 +1021,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
991
1021
"lower_bound = {:?} r_scc={:?} universe={:?}" ,
992
1022
lower_bound,
993
1023
r_scc,
994
- self . constraint_sccs . annotation ( r_scc) . min_universe ( )
1024
+ self . scc_universe ( r_scc)
995
1025
) ;
996
1026
// If the type test requires that `T: 'a` where `'a` is a
997
1027
// placeholder from another universe, that effectively requires
@@ -1472,7 +1502,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1472
1502
/// The minimum universe of any variable reachable from this
1473
1503
/// SCC, inside or outside of it.
1474
1504
fn scc_universe ( & self , scc : ConstraintSccIndex ) -> UniverseIndex {
1475
- self . constraint_sccs ( ) . annotation ( scc) . min_universe ( )
1505
+ self . scc_annotations [ scc] . min_universe ( )
1476
1506
}
1477
1507
1478
1508
/// Checks the final value for the free region `fr` to see if it
@@ -2216,7 +2246,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2216
2246
/// they *must* be equal (though not having the same repr does not
2217
2247
/// mean they are unequal).
2218
2248
fn scc_representative ( & self , scc : ConstraintSccIndex ) -> RegionVid {
2219
- self . constraint_sccs . annotation ( scc) . representative
2249
+ self . scc_annotations [ scc] . representative
2220
2250
}
2221
2251
2222
2252
pub ( crate ) fn liveness_constraints ( & self ) -> & LivenessValues {
0 commit comments