@@ -20,7 +20,7 @@ impl<'tcx> Rollback<sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>> for TypeVariabl
20
20
}
21
21
22
22
#[ derive( Clone ) ]
23
- pub struct TypeVariableStorage < ' tcx > {
23
+ pub ( crate ) struct TypeVariableStorage < ' tcx > {
24
24
/// The origins of each type variable.
25
25
values : IndexVec < TyVid , TypeVariableData > ,
26
26
/// Two variables are unified in `eq_relations` when we have a
@@ -29,7 +29,7 @@ pub struct TypeVariableStorage<'tcx> {
29
29
eq_relations : ut:: UnificationTableStorage < TyVidEqKey < ' tcx > > ,
30
30
}
31
31
32
- pub struct TypeVariableTable < ' a , ' tcx > {
32
+ pub ( crate ) struct TypeVariableTable < ' a , ' tcx > {
33
33
storage : & ' a mut TypeVariableStorage < ' tcx > ,
34
34
35
35
undo_log : & ' a mut InferCtxtUndoLogs < ' tcx > ,
@@ -50,22 +50,22 @@ pub(crate) struct TypeVariableData {
50
50
}
51
51
52
52
#[ derive( Copy , Clone , Debug ) ]
53
- pub enum TypeVariableValue < ' tcx > {
53
+ pub ( crate ) enum TypeVariableValue < ' tcx > {
54
54
Known { value : Ty < ' tcx > } ,
55
55
Unknown { universe : ty:: UniverseIndex } ,
56
56
}
57
57
58
58
impl < ' tcx > TypeVariableValue < ' tcx > {
59
59
/// If this value is known, returns the type it is known to be.
60
60
/// Otherwise, `None`.
61
- pub fn known ( & self ) -> Option < Ty < ' tcx > > {
61
+ pub ( crate ) fn known ( & self ) -> Option < Ty < ' tcx > > {
62
62
match * self {
63
63
TypeVariableValue :: Unknown { .. } => None ,
64
64
TypeVariableValue :: Known { value } => Some ( value) ,
65
65
}
66
66
}
67
67
68
- pub fn is_unknown ( & self ) -> bool {
68
+ pub ( crate ) fn is_unknown ( & self ) -> bool {
69
69
match * self {
70
70
TypeVariableValue :: Unknown { .. } => true ,
71
71
TypeVariableValue :: Known { .. } => false ,
@@ -74,7 +74,7 @@ impl<'tcx> TypeVariableValue<'tcx> {
74
74
}
75
75
76
76
impl < ' tcx > TypeVariableStorage < ' tcx > {
77
- pub fn new ( ) -> TypeVariableStorage < ' tcx > {
77
+ pub ( crate ) fn new ( ) -> TypeVariableStorage < ' tcx > {
78
78
TypeVariableStorage {
79
79
values : Default :: default ( ) ,
80
80
eq_relations : ut:: UnificationTableStorage :: new ( ) ,
@@ -105,14 +105,14 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
105
105
///
106
106
/// Note that this function does not return care whether
107
107
/// `vid` has been unified with something else or not.
108
- pub fn var_origin ( & self , vid : ty:: TyVid ) -> TypeVariableOrigin {
108
+ pub ( crate ) fn var_origin ( & self , vid : ty:: TyVid ) -> TypeVariableOrigin {
109
109
self . storage . values [ vid] . origin
110
110
}
111
111
112
112
/// Records that `a == b`, depending on `dir`.
113
113
///
114
114
/// Precondition: neither `a` nor `b` are known.
115
- pub fn equate ( & mut self , a : ty:: TyVid , b : ty:: TyVid ) {
115
+ pub ( crate ) fn equate ( & mut self , a : ty:: TyVid , b : ty:: TyVid ) {
116
116
debug_assert ! ( self . probe( a) . is_unknown( ) ) ;
117
117
debug_assert ! ( self . probe( b) . is_unknown( ) ) ;
118
118
self . eq_relations ( ) . union ( a, b) ;
@@ -121,7 +121,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
121
121
/// Instantiates `vid` with the type `ty`.
122
122
///
123
123
/// Precondition: `vid` must not have been previously instantiated.
124
- pub fn instantiate ( & mut self , vid : ty:: TyVid , ty : Ty < ' tcx > ) {
124
+ pub ( crate ) fn instantiate ( & mut self , vid : ty:: TyVid , ty : Ty < ' tcx > ) {
125
125
let vid = self . root_var ( vid) ;
126
126
debug_assert ! ( !ty. is_ty_var( ) , "instantiating ty var with var: {vid:?} {ty:?}" ) ;
127
127
debug_assert ! ( self . probe( vid) . is_unknown( ) ) ;
@@ -143,7 +143,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
143
143
/// - `origin`: indicates *why* the type variable was created.
144
144
/// The code in this module doesn't care, but it can be useful
145
145
/// for improving error messages.
146
- pub fn new_var (
146
+ pub ( crate ) fn new_var (
147
147
& mut self ,
148
148
universe : ty:: UniverseIndex ,
149
149
origin : TypeVariableOrigin ,
@@ -158,7 +158,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
158
158
}
159
159
160
160
/// Returns the number of type variables created thus far.
161
- pub fn num_vars ( & self ) -> usize {
161
+ pub ( crate ) fn num_vars ( & self ) -> usize {
162
162
self . storage . values . len ( )
163
163
}
164
164
@@ -167,42 +167,29 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
167
167
/// will yield the same root variable (per the union-find
168
168
/// algorithm), so `root_var(a) == root_var(b)` implies that `a ==
169
169
/// b` (transitively).
170
- pub fn root_var ( & mut self , vid : ty:: TyVid ) -> ty:: TyVid {
170
+ pub ( crate ) fn root_var ( & mut self , vid : ty:: TyVid ) -> ty:: TyVid {
171
171
self . eq_relations ( ) . find ( vid) . vid
172
172
}
173
173
174
174
/// Retrieves the type to which `vid` has been instantiated, if
175
175
/// any.
176
- pub fn probe ( & mut self , vid : ty:: TyVid ) -> TypeVariableValue < ' tcx > {
176
+ pub ( crate ) fn probe ( & mut self , vid : ty:: TyVid ) -> TypeVariableValue < ' tcx > {
177
177
self . inlined_probe ( vid)
178
178
}
179
179
180
180
/// An always-inlined variant of `probe`, for very hot call sites.
181
181
#[ inline( always) ]
182
- pub fn inlined_probe ( & mut self , vid : ty:: TyVid ) -> TypeVariableValue < ' tcx > {
182
+ pub ( crate ) fn inlined_probe ( & mut self , vid : ty:: TyVid ) -> TypeVariableValue < ' tcx > {
183
183
self . eq_relations ( ) . inlined_probe_value ( vid)
184
184
}
185
185
186
- /// If `t` is a type-inference variable, and it has been
187
- /// instantiated, then return the with which it was
188
- /// instantiated. Otherwise, returns `t`.
189
- pub fn replace_if_possible ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
190
- match * t. kind ( ) {
191
- ty:: Infer ( ty:: TyVar ( v) ) => match self . probe ( v) {
192
- TypeVariableValue :: Unknown { .. } => t,
193
- TypeVariableValue :: Known { value } => value,
194
- } ,
195
- _ => t,
196
- }
197
- }
198
-
199
186
#[ inline]
200
187
fn eq_relations ( & mut self ) -> super :: UnificationTable < ' _ , ' tcx , TyVidEqKey < ' tcx > > {
201
188
self . storage . eq_relations . with_log ( self . undo_log )
202
189
}
203
190
204
191
/// Returns a range of the type variables created during the snapshot.
205
- pub fn vars_since_snapshot (
192
+ pub ( crate ) fn vars_since_snapshot (
206
193
& mut self ,
207
194
value_count : usize ,
208
195
) -> ( Range < TyVid > , Vec < TypeVariableOrigin > ) {
@@ -215,7 +202,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
215
202
216
203
/// Returns indices of all variables that are not yet
217
204
/// instantiated.
218
- pub fn unresolved_variables ( & mut self ) -> Vec < ty:: TyVid > {
205
+ pub ( crate ) fn unresolved_variables ( & mut self ) -> Vec < ty:: TyVid > {
219
206
( 0 ..self . num_vars ( ) )
220
207
. filter_map ( |i| {
221
208
let vid = ty:: TyVid :: from_usize ( i) ;
0 commit comments