@@ -4,10 +4,9 @@ use std::ops::Index;
4
4
use rustc_data_structures:: captures:: Captures ;
5
5
use rustc_data_structures:: fx:: FxIndexMap ;
6
6
use rustc_index:: { IndexSlice , IndexVec } ;
7
- use rustc_middle:: infer:: MemberConstraint ;
8
7
use rustc_middle:: ty:: { self , Ty } ;
9
8
use rustc_span:: Span ;
10
- use tracing:: debug ;
9
+ use tracing:: instrument ;
11
10
12
11
/// Compactly stores a set of `R0 member of [R1...Rn]` constraints,
13
12
/// indexed by the region `R0`.
23
22
/// Stores the data about each `R0 member of [R1..Rn]` constraint.
24
23
/// These are organized into a linked list, so each constraint
25
24
/// contains the index of the next constraint with the same `R0`.
26
- constraints : IndexVec < NllMemberConstraintIndex , NllMemberConstraint < ' tcx > > ,
25
+ constraints : IndexVec < NllMemberConstraintIndex , MemberConstraint < ' tcx > > ,
27
26
28
27
/// Stores the `R1..Rn` regions for *all* sets. For any given
29
28
/// constraint, we keep two indices so that we can pull out a
33
32
34
33
/// Represents a `R0 member of [R1..Rn]` constraint
35
34
#[ derive( Debug ) ]
36
- pub ( crate ) struct NllMemberConstraint < ' tcx > {
35
+ pub ( crate ) struct MemberConstraint < ' tcx > {
37
36
next_constraint : Option < NllMemberConstraintIndex > ,
38
37
39
38
/// The span where the hidden type was instantiated.
@@ -70,37 +69,34 @@ impl Default for MemberConstraintSet<'_, ty::RegionVid> {
70
69
}
71
70
72
71
impl < ' tcx > MemberConstraintSet < ' tcx , ty:: RegionVid > {
72
+ pub ( crate ) fn is_empty ( & self ) -> bool {
73
+ self . constraints . is_empty ( )
74
+ }
75
+
73
76
/// Pushes a member constraint into the set.
74
- ///
75
- /// The input member constraint `m_c` is in the form produced by
76
- /// the `rustc_middle::infer` code.
77
- ///
78
- /// The `to_region_vid` callback fn is used to convert the regions
79
- /// within into `RegionVid` format -- it typically consults the
80
- /// `UniversalRegions` data structure that is known to the caller
81
- /// (but which this code is unaware of).
82
- pub ( crate ) fn push_constraint (
77
+ #[ instrument( level = "debug" , skip( self ) ) ]
78
+ pub ( crate ) fn add_member_constraint (
83
79
& mut self ,
84
- m_c : & MemberConstraint < ' tcx > ,
85
- mut to_region_vid : impl FnMut ( ty:: Region < ' tcx > ) -> ty:: RegionVid ,
80
+ key : ty:: OpaqueTypeKey < ' tcx > ,
81
+ hidden_ty : Ty < ' tcx > ,
82
+ definition_span : Span ,
83
+ member_region_vid : ty:: RegionVid ,
84
+ choice_regions : & [ ty:: RegionVid ] ,
86
85
) {
87
- debug ! ( "push_constraint(m_c={:?})" , m_c) ;
88
- let member_region_vid: ty:: RegionVid = to_region_vid ( m_c. member_region ) ;
89
86
let next_constraint = self . first_constraints . get ( & member_region_vid) . cloned ( ) ;
90
87
let start_index = self . choice_regions . len ( ) ;
91
- let end_index = start_index + m_c . choice_regions . len ( ) ;
92
- debug ! ( "push_constraint: member_region_vid={:?}" , member_region_vid ) ;
93
- let constraint_index = self . constraints . push ( NllMemberConstraint {
88
+ self . choice_regions . extend ( choice_regions ) ;
89
+ let end_index = self . choice_regions . len ( ) ;
90
+ let constraint_index = self . constraints . push ( MemberConstraint {
94
91
next_constraint,
95
92
member_region_vid,
96
- definition_span : m_c . definition_span ,
97
- hidden_ty : m_c . hidden_ty ,
98
- key : m_c . key ,
93
+ definition_span,
94
+ hidden_ty,
95
+ key,
99
96
start_index,
100
97
end_index,
101
98
} ) ;
102
99
self . first_constraints . insert ( member_region_vid, constraint_index) ;
103
- self . choice_regions . extend ( m_c. choice_regions . iter ( ) . map ( |& r| to_region_vid ( r) ) ) ;
104
100
}
105
101
}
106
102
@@ -182,7 +178,7 @@ where
182
178
/// R0 member of [R1..Rn]
183
179
/// ```
184
180
pub ( crate ) fn choice_regions ( & self , pci : NllMemberConstraintIndex ) -> & [ ty:: RegionVid ] {
185
- let NllMemberConstraint { start_index, end_index, .. } = & self . constraints [ pci] ;
181
+ let MemberConstraint { start_index, end_index, .. } = & self . constraints [ pci] ;
186
182
& self . choice_regions [ * start_index..* end_index]
187
183
}
188
184
}
@@ -191,9 +187,9 @@ impl<'tcx, R> Index<NllMemberConstraintIndex> for MemberConstraintSet<'tcx, R>
191
187
where
192
188
R : Copy + Eq ,
193
189
{
194
- type Output = NllMemberConstraint < ' tcx > ;
190
+ type Output = MemberConstraint < ' tcx > ;
195
191
196
- fn index ( & self , i : NllMemberConstraintIndex ) -> & NllMemberConstraint < ' tcx > {
192
+ fn index ( & self , i : NllMemberConstraintIndex ) -> & MemberConstraint < ' tcx > {
197
193
& self . constraints [ i]
198
194
}
199
195
}
@@ -215,7 +211,7 @@ where
215
211
/// target_list: A -> B -> C -> D -> E -> F -> (None)
216
212
/// ```
217
213
fn append_list (
218
- constraints : & mut IndexSlice < NllMemberConstraintIndex , NllMemberConstraint < ' _ > > ,
214
+ constraints : & mut IndexSlice < NllMemberConstraintIndex , MemberConstraint < ' _ > > ,
219
215
target_list : NllMemberConstraintIndex ,
220
216
source_list : NllMemberConstraintIndex ,
221
217
) {
0 commit comments