@@ -23,7 +23,7 @@ use infer::InferCtxt;
23
23
use std:: sync:: atomic:: Ordering ;
24
24
use ty:: fold:: { TypeFoldable , TypeFolder } ;
25
25
use ty:: subst:: Kind ;
26
- use ty:: { self , CanonicalVar , Lift , List , Ty , TyCtxt , TypeFlags } ;
26
+ use ty:: { self , BoundTy , BoundTyIndex , Lift , List , Ty , TyCtxt , TypeFlags } ;
27
27
28
28
use rustc_data_structures:: fx:: FxHashMap ;
29
29
use rustc_data_structures:: indexed_vec:: Idx ;
@@ -225,7 +225,7 @@ struct Canonicalizer<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
225
225
query_state : & ' cx mut OriginalQueryValues < ' tcx > ,
226
226
// Note that indices is only used once `var_values` is big enough to be
227
227
// heap-allocated.
228
- indices : FxHashMap < Kind < ' tcx > , CanonicalVar > ,
228
+ indices : FxHashMap < Kind < ' tcx > , BoundTyIndex > ,
229
229
canonicalize_region_mode : & ' cx dyn CanonicalizeRegionMode ,
230
230
needs_canonical_flags : TypeFlags ,
231
231
}
@@ -283,7 +283,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
283
283
bug ! ( "encountered a fresh type during canonicalization" )
284
284
}
285
285
286
- ty:: Infer ( ty:: CanonicalTy ( _) ) => {
286
+ ty:: Infer ( ty:: BoundTy ( _) ) => {
287
287
bug ! ( "encountered a canonical type during canonicalization" )
288
288
}
289
289
@@ -393,7 +393,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
393
393
/// or returns an existing variable if `kind` has already been
394
394
/// seen. `kind` is expected to be an unbound variable (or
395
395
/// potentially a free region).
396
- fn canonical_var ( & mut self , info : CanonicalVarInfo , kind : Kind < ' tcx > ) -> CanonicalVar {
396
+ fn canonical_var ( & mut self , info : CanonicalVarInfo , kind : Kind < ' tcx > ) -> BoundTy {
397
397
let Canonicalizer {
398
398
variables,
399
399
query_state,
@@ -408,12 +408,12 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
408
408
// avoid allocations in those cases. We also don't use `indices` to
409
409
// determine if a kind has been seen before until the limit of 8 has
410
410
// been exceeded, to also avoid allocations for `indices`.
411
- if !var_values. spilled ( ) {
411
+ let var = if !var_values. spilled ( ) {
412
412
// `var_values` is stack-allocated. `indices` isn't used yet. Do a
413
413
// direct linear search of `var_values`.
414
414
if let Some ( idx) = var_values. iter ( ) . position ( |& k| k == kind) {
415
415
// `kind` is already present in `var_values`.
416
- CanonicalVar :: new ( idx)
416
+ BoundTyIndex :: new ( idx)
417
417
} else {
418
418
// `kind` isn't present in `var_values`. Append it. Likewise
419
419
// for `info` and `variables`.
@@ -428,29 +428,35 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
428
428
* indices = var_values
429
429
. iter ( )
430
430
. enumerate ( )
431
- . map ( |( i, & kind) | ( kind, CanonicalVar :: new ( i) ) )
431
+ . map ( |( i, & kind) | ( kind, BoundTyIndex :: new ( i) ) )
432
432
. collect ( ) ;
433
433
}
434
434
// The cv is the index of the appended element.
435
- CanonicalVar :: new ( var_values. len ( ) - 1 )
435
+ BoundTyIndex :: new ( var_values. len ( ) - 1 )
436
436
}
437
437
} else {
438
438
// `var_values` is large. Do a hashmap search via `indices`.
439
439
* indices. entry ( kind) . or_insert_with ( || {
440
440
variables. push ( info) ;
441
441
var_values. push ( kind) ;
442
442
assert_eq ! ( variables. len( ) , var_values. len( ) ) ;
443
- CanonicalVar :: new ( variables. len ( ) - 1 )
443
+ BoundTyIndex :: new ( variables. len ( ) - 1 )
444
444
} )
445
+ } ;
446
+
447
+ BoundTy {
448
+ level : ty:: INNERMOST ,
449
+ var,
445
450
}
446
451
}
447
452
448
453
fn canonical_var_for_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
449
454
let info = CanonicalVarInfo {
450
455
kind : CanonicalVarKind :: Region ,
451
456
} ;
452
- let cvar = self . canonical_var ( info, r. into ( ) ) ;
453
- self . tcx ( ) . mk_region ( ty:: ReCanonical ( cvar) )
457
+ let b = self . canonical_var ( info, r. into ( ) ) ;
458
+ debug_assert_eq ! ( ty:: INNERMOST , b. level) ;
459
+ self . tcx ( ) . mk_region ( ty:: ReCanonical ( b. var ) )
454
460
}
455
461
456
462
/// Given a type variable `ty_var` of the given kind, first check
@@ -466,8 +472,9 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
466
472
let info = CanonicalVarInfo {
467
473
kind : CanonicalVarKind :: Ty ( ty_kind) ,
468
474
} ;
469
- let cvar = self . canonical_var ( info, ty_var. into ( ) ) ;
470
- self . tcx ( ) . mk_infer ( ty:: InferTy :: CanonicalTy ( cvar) )
475
+ let b = self . canonical_var ( info, ty_var. into ( ) ) ;
476
+ debug_assert_eq ! ( ty:: INNERMOST , b. level) ;
477
+ self . tcx ( ) . mk_infer ( ty:: InferTy :: BoundTy ( b) )
471
478
}
472
479
}
473
480
}
0 commit comments