23
23
24
24
use rustc_macros:: HashStable ;
25
25
use rustc_type_ir:: Canonical as IrCanonical ;
26
+ use rustc_type_ir:: CanonicalVarInfo as IrCanonicalVarInfo ;
27
+ pub use rustc_type_ir:: { CanonicalTyVarKind , CanonicalVarKind } ;
26
28
use smallvec:: SmallVec ;
27
29
use std:: ops:: Index ;
28
30
@@ -33,6 +35,8 @@ use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
33
35
34
36
pub type Canonical < ' tcx , V > = IrCanonical < TyCtxt < ' tcx > , V > ;
35
37
38
+ pub type CanonicalVarInfo < ' tcx > = IrCanonicalVarInfo < TyCtxt < ' tcx > > ;
39
+
36
40
pub type CanonicalVarInfos < ' tcx > = & ' tcx List < CanonicalVarInfo < ' tcx > > ;
37
41
38
42
impl < ' tcx > ty:: TypeFoldable < TyCtxt < ' tcx > > for CanonicalVarInfos < ' tcx > {
@@ -138,158 +142,6 @@ impl<'tcx> Default for OriginalQueryValues<'tcx> {
138
142
}
139
143
}
140
144
141
- /// Information about a canonical variable that is included with the
142
- /// canonical value. This is sufficient information for code to create
143
- /// a copy of the canonical value in some other inference context,
144
- /// with fresh inference variables replacing the canonical values.
145
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TyDecodable , TyEncodable , HashStable ) ]
146
- #[ derive( TypeFoldable , TypeVisitable ) ]
147
- pub struct CanonicalVarInfo < ' tcx > {
148
- pub kind : CanonicalVarKind < ' tcx > ,
149
- }
150
-
151
- impl < ' tcx > CanonicalVarInfo < ' tcx > {
152
- pub fn universe ( & self ) -> ty:: UniverseIndex {
153
- self . kind . universe ( )
154
- }
155
-
156
- #[ must_use]
157
- pub fn with_updated_universe ( self , ui : ty:: UniverseIndex ) -> CanonicalVarInfo < ' tcx > {
158
- CanonicalVarInfo { kind : self . kind . with_updated_universe ( ui) }
159
- }
160
-
161
- pub fn is_existential ( & self ) -> bool {
162
- match self . kind {
163
- CanonicalVarKind :: Ty ( _) => true ,
164
- CanonicalVarKind :: PlaceholderTy ( _) => false ,
165
- CanonicalVarKind :: Region ( _) => true ,
166
- CanonicalVarKind :: PlaceholderRegion ( ..) => false ,
167
- CanonicalVarKind :: Const ( ..) => true ,
168
- CanonicalVarKind :: PlaceholderConst ( _, _) => false ,
169
- CanonicalVarKind :: Effect => true ,
170
- }
171
- }
172
-
173
- pub fn is_region ( & self ) -> bool {
174
- match self . kind {
175
- CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => true ,
176
- CanonicalVarKind :: Ty ( _)
177
- | CanonicalVarKind :: PlaceholderTy ( _)
178
- | CanonicalVarKind :: Const ( _, _)
179
- | CanonicalVarKind :: PlaceholderConst ( _, _)
180
- | CanonicalVarKind :: Effect => false ,
181
- }
182
- }
183
-
184
- pub fn expect_placeholder_index ( self ) -> usize {
185
- match self . kind {
186
- CanonicalVarKind :: Ty ( _)
187
- | CanonicalVarKind :: Region ( _)
188
- | CanonicalVarKind :: Const ( _, _)
189
- | CanonicalVarKind :: Effect => bug ! ( "expected placeholder: {self:?}" ) ,
190
-
191
- CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. bound . var . as_usize ( ) ,
192
- CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. bound . var . as_usize ( ) ,
193
- CanonicalVarKind :: PlaceholderConst ( placeholder, _) => placeholder. bound . as_usize ( ) ,
194
- }
195
- }
196
- }
197
-
198
- /// Describes the "kind" of the canonical variable. This is a "kind"
199
- /// in the type-theory sense of the term -- i.e., a "meta" type system
200
- /// that analyzes type-like values.
201
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TyDecodable , TyEncodable , HashStable ) ]
202
- #[ derive( TypeFoldable , TypeVisitable ) ]
203
- pub enum CanonicalVarKind < ' tcx > {
204
- /// Some kind of type inference variable.
205
- Ty ( CanonicalTyVarKind ) ,
206
-
207
- /// A "placeholder" that represents "any type".
208
- PlaceholderTy ( ty:: PlaceholderType ) ,
209
-
210
- /// Region variable `'?R`.
211
- Region ( ty:: UniverseIndex ) ,
212
-
213
- /// A "placeholder" that represents "any region". Created when you
214
- /// are solving a goal like `for<'a> T: Foo<'a>` to represent the
215
- /// bound region `'a`.
216
- PlaceholderRegion ( ty:: PlaceholderRegion ) ,
217
-
218
- /// Some kind of const inference variable.
219
- Const ( ty:: UniverseIndex , Ty < ' tcx > ) ,
220
-
221
- /// Effect variable `'?E`.
222
- Effect ,
223
-
224
- /// A "placeholder" that represents "any const".
225
- PlaceholderConst ( ty:: PlaceholderConst , Ty < ' tcx > ) ,
226
- }
227
-
228
- impl < ' tcx > CanonicalVarKind < ' tcx > {
229
- pub fn universe ( self ) -> ty:: UniverseIndex {
230
- match self {
231
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) ) => ui,
232
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float | CanonicalTyVarKind :: Int ) => {
233
- ty:: UniverseIndex :: ROOT
234
- }
235
- CanonicalVarKind :: Effect => ty:: UniverseIndex :: ROOT ,
236
- CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. universe ,
237
- CanonicalVarKind :: Region ( ui) => ui,
238
- CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. universe ,
239
- CanonicalVarKind :: Const ( ui, _) => ui,
240
- CanonicalVarKind :: PlaceholderConst ( placeholder, _) => placeholder. universe ,
241
- }
242
- }
243
-
244
- /// Replaces the universe of this canonical variable with `ui`.
245
- ///
246
- /// In case this is a float or int variable, this causes an ICE if
247
- /// the updated universe is not the root.
248
- pub fn with_updated_universe ( self , ui : ty:: UniverseIndex ) -> CanonicalVarKind < ' tcx > {
249
- match self {
250
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( _) ) => {
251
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
252
- }
253
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float )
254
- | CanonicalVarKind :: Effect => {
255
- assert_eq ! ( ui, ty:: UniverseIndex :: ROOT ) ;
256
- self
257
- }
258
- CanonicalVarKind :: PlaceholderTy ( placeholder) => {
259
- CanonicalVarKind :: PlaceholderTy ( ty:: Placeholder { universe : ui, ..placeholder } )
260
- }
261
- CanonicalVarKind :: Region ( _) => CanonicalVarKind :: Region ( ui) ,
262
- CanonicalVarKind :: PlaceholderRegion ( placeholder) => {
263
- CanonicalVarKind :: PlaceholderRegion ( ty:: Placeholder { universe : ui, ..placeholder } )
264
- }
265
- CanonicalVarKind :: Const ( _, ty) => CanonicalVarKind :: Const ( ui, ty) ,
266
- CanonicalVarKind :: PlaceholderConst ( placeholder, ty) => {
267
- CanonicalVarKind :: PlaceholderConst (
268
- ty:: Placeholder { universe : ui, ..placeholder } ,
269
- ty,
270
- )
271
- }
272
- }
273
- }
274
- }
275
-
276
- /// Rust actually has more than one category of type variables;
277
- /// notably, the type variables we create for literals (e.g., 22 or
278
- /// 22.) can only be instantiated with integral/float types (e.g.,
279
- /// usize or f32). In order to faithfully reproduce a type, we need to
280
- /// know what set of types a given type variable can be unified with.
281
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TyDecodable , TyEncodable , HashStable ) ]
282
- pub enum CanonicalTyVarKind {
283
- /// General type variable `?T` that can be unified with arbitrary types.
284
- General ( ty:: UniverseIndex ) ,
285
-
286
- /// Integral type variable `?I` (that can only be unified with integral types).
287
- Int ,
288
-
289
- /// Floating-point type variable `?F` (that can only be unified with float types).
290
- Float ,
291
- }
292
-
293
145
/// After we execute a query with a canonicalized key, we get back a
294
146
/// `Canonical<QueryResponse<..>>`. You can use
295
147
/// `instantiate_query_result` to access the data in this result.
@@ -366,7 +218,6 @@ pub type QueryOutlivesConstraint<'tcx> =
366
218
367
219
TrivialTypeTraversalImpls ! {
368
220
crate :: infer:: canonical:: Certainty ,
369
- crate :: infer:: canonical:: CanonicalTyVarKind ,
370
221
}
371
222
372
223
impl < ' tcx > CanonicalVarValues < ' tcx > {
0 commit comments