@@ -42,15 +42,15 @@ impl<'tcx> Rollback<sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>> for TypeVariabl
42
42
43
43
impl < ' tcx > Rollback < sv:: UndoLog < ut:: Delegate < TyVidSubKey > > > for TypeVariableStorage < ' tcx > {
44
44
fn reverse ( & mut self , undo : sv:: UndoLog < ut:: Delegate < TyVidSubKey > > ) {
45
- self . sub_relations . reverse ( undo)
45
+ self . sub_unification_table . reverse ( undo)
46
46
}
47
47
}
48
48
49
49
impl < ' tcx > Rollback < UndoLog < ' tcx > > for TypeVariableStorage < ' tcx > {
50
50
fn reverse ( & mut self , undo : UndoLog < ' tcx > ) {
51
51
match undo {
52
52
UndoLog :: EqRelation ( undo) => self . eq_relations . reverse ( undo) ,
53
- UndoLog :: SubRelation ( undo) => self . sub_relations . reverse ( undo) ,
53
+ UndoLog :: SubRelation ( undo) => self . sub_unification_table . reverse ( undo) ,
54
54
}
55
55
}
56
56
}
@@ -63,7 +63,9 @@ pub(crate) struct TypeVariableStorage<'tcx> {
63
63
/// constraint `?X == ?Y`. This table also stores, for each key,
64
64
/// the known value.
65
65
eq_relations : ut:: UnificationTableStorage < TyVidEqKey < ' tcx > > ,
66
- /// Only used by `-Znext-solver` and for diagnostics.
66
+ /// Only used by `-Znext-solver` and for diagnostics. Tracks whether
67
+ /// type variables are related via subtyping at all, ignoring which of
68
+ /// the two is the subtype.
67
69
///
68
70
/// When reporting ambiguity errors, we sometimes want to
69
71
/// treat all inference vars which are subtypes of each
@@ -79,7 +81,7 @@ pub(crate) struct TypeVariableStorage<'tcx> {
79
81
/// Even for something like `let x = returns_arg(); x.method();` the
80
82
/// type of `x` is only a supertype of the argument of `returns_arg`. We
81
83
/// still want to suggest specifying the type of the argument.
82
- sub_relations : ut:: UnificationTableStorage < TyVidSubKey > ,
84
+ sub_unification_table : ut:: UnificationTableStorage < TyVidSubKey > ,
83
85
}
84
86
85
87
pub ( crate ) struct TypeVariableTable < ' a , ' tcx > {
@@ -155,23 +157,24 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
155
157
self . storage . values [ vid] . origin
156
158
}
157
159
158
- /// Records that `a == b`, depending on `dir` .
160
+ /// Records that `a == b`.
159
161
///
160
162
/// Precondition: neither `a` nor `b` are known.
161
163
pub ( crate ) fn equate ( & mut self , a : ty:: TyVid , b : ty:: TyVid ) {
162
164
debug_assert ! ( self . probe( a) . is_unknown( ) ) ;
163
165
debug_assert ! ( self . probe( b) . is_unknown( ) ) ;
164
166
self . eq_relations ( ) . union ( a, b) ;
165
- self . sub_relations ( ) . union ( a, b) ;
167
+ self . sub_unification_table ( ) . union ( a, b) ;
166
168
}
167
169
168
- /// Records that `a <: b`, depending on `dir`.
170
+ /// Records that `a` and `b` are related via subtyping. We don't track
171
+ /// which of the two is the subtype.
169
172
///
170
173
/// Precondition: neither `a` nor `b` are known.
171
- pub ( crate ) fn sub ( & mut self , a : ty:: TyVid , b : ty:: TyVid ) {
174
+ pub ( crate ) fn sub_unify ( & mut self , a : ty:: TyVid , b : ty:: TyVid ) {
172
175
debug_assert ! ( self . probe( a) . is_unknown( ) ) ;
173
176
debug_assert ! ( self . probe( b) . is_unknown( ) ) ;
174
- self . sub_relations ( ) . union ( a, b) ;
177
+ self . sub_unification_table ( ) . union ( a, b) ;
175
178
}
176
179
177
180
/// Instantiates `vid` with the type `ty`.
@@ -206,7 +209,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
206
209
) -> ty:: TyVid {
207
210
let eq_key = self . eq_relations ( ) . new_key ( TypeVariableValue :: Unknown { universe } ) ;
208
211
209
- let sub_key = self . sub_relations ( ) . new_key ( ( ) ) ;
212
+ let sub_key = self . sub_unification_table ( ) . new_key ( ( ) ) ;
210
213
debug_assert_eq ! ( eq_key. vid, sub_key. vid) ;
211
214
212
215
let index = self . storage . values . push ( TypeVariableData { origin } ) ;
@@ -231,16 +234,16 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
231
234
self . eq_relations ( ) . find ( vid) . vid
232
235
}
233
236
234
- /// Returns the "root" variable of `vid` in the `sub_relations `
235
- /// equivalence table. All type variables that have been are
236
- /// related via equality or subtyping will yield the same root
237
- /// variable (per the union-find algorithm), so `sub_root_var (a)
238
- /// == sub_root_var (b)` implies that:
237
+ /// Returns the "root" variable of `vid` in the `sub_unification_table `
238
+ /// equivalence table. All type variables that have been are related via
239
+ /// equality or subtyping will yield the same root variable (per the
240
+ /// union-find algorithm), so `sub_unification_table_root_var (a)
241
+ /// == sub_unification_table_root_var (b)` implies that:
239
242
/// ```text
240
243
/// exists X. (a <: X || X <: a) && (b <: X || X <: b)
241
244
/// ```
242
- pub ( crate ) fn sub_root_var ( & mut self , vid : ty:: TyVid ) -> ty:: TyVid {
243
- self . sub_relations ( ) . find ( vid) . vid
245
+ pub ( crate ) fn sub_unification_table_root_var ( & mut self , vid : ty:: TyVid ) -> ty:: TyVid {
246
+ self . sub_unification_table ( ) . find ( vid) . vid
244
247
}
245
248
246
249
/// Retrieves the type to which `vid` has been instantiated, if
@@ -261,8 +264,8 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
261
264
}
262
265
263
266
#[ inline]
264
- fn sub_relations ( & mut self ) -> super :: UnificationTable < ' _ , ' tcx , TyVidSubKey > {
265
- self . storage . sub_relations . with_log ( self . undo_log )
267
+ fn sub_unification_table ( & mut self ) -> super :: UnificationTable < ' _ , ' tcx , TyVidSubKey > {
268
+ self . storage . sub_unification_table . with_log ( self . undo_log )
266
269
}
267
270
268
271
/// Returns a range of the type variables created during the snapshot.
0 commit comments