@@ -23,7 +23,7 @@ use infer::InferCtxt;
2323use std:: sync:: atomic:: Ordering ;
2424use ty:: fold:: { TypeFoldable , TypeFolder } ;
2525use ty:: subst:: Kind ;
26- use ty:: { self , CanonicalVar , Lift , List , Ty , TyCtxt , TypeFlags } ;
26+ use ty:: { self , BoundTy , BoundTyIndex , Lift , List , Ty , TyCtxt , TypeFlags } ;
2727
2828use rustc_data_structures:: fx:: FxHashMap ;
2929use rustc_data_structures:: indexed_vec:: Idx ;
@@ -225,7 +225,7 @@ struct Canonicalizer<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
225225 query_state : & ' cx mut OriginalQueryValues < ' tcx > ,
226226 // Note that indices is only used once `var_values` is big enough to be
227227 // heap-allocated.
228- indices : FxHashMap < Kind < ' tcx > , CanonicalVar > ,
228+ indices : FxHashMap < Kind < ' tcx > , BoundTyIndex > ,
229229 canonicalize_region_mode : & ' cx dyn CanonicalizeRegionMode ,
230230 needs_canonical_flags : TypeFlags ,
231231}
@@ -283,7 +283,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
283283 bug ! ( "encountered a fresh type during canonicalization" )
284284 }
285285
286- ty:: Infer ( ty:: CanonicalTy ( _) ) => {
286+ ty:: Infer ( ty:: BoundTy ( _) ) => {
287287 bug ! ( "encountered a canonical type during canonicalization" )
288288 }
289289
@@ -393,7 +393,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
393393 /// or returns an existing variable if `kind` has already been
394394 /// seen. `kind` is expected to be an unbound variable (or
395395 /// 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 {
397397 let Canonicalizer {
398398 variables,
399399 query_state,
@@ -408,12 +408,12 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
408408 // avoid allocations in those cases. We also don't use `indices` to
409409 // determine if a kind has been seen before until the limit of 8 has
410410 // been exceeded, to also avoid allocations for `indices`.
411- if !var_values. spilled ( ) {
411+ let var = if !var_values. spilled ( ) {
412412 // `var_values` is stack-allocated. `indices` isn't used yet. Do a
413413 // direct linear search of `var_values`.
414414 if let Some ( idx) = var_values. iter ( ) . position ( |& k| k == kind) {
415415 // `kind` is already present in `var_values`.
416- CanonicalVar :: new ( idx)
416+ BoundTyIndex :: new ( idx)
417417 } else {
418418 // `kind` isn't present in `var_values`. Append it. Likewise
419419 // for `info` and `variables`.
@@ -428,29 +428,35 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
428428 * indices = var_values
429429 . iter ( )
430430 . enumerate ( )
431- . map ( |( i, & kind) | ( kind, CanonicalVar :: new ( i) ) )
431+ . map ( |( i, & kind) | ( kind, BoundTyIndex :: new ( i) ) )
432432 . collect ( ) ;
433433 }
434434 // The cv is the index of the appended element.
435- CanonicalVar :: new ( var_values. len ( ) - 1 )
435+ BoundTyIndex :: new ( var_values. len ( ) - 1 )
436436 }
437437 } else {
438438 // `var_values` is large. Do a hashmap search via `indices`.
439439 * indices. entry ( kind) . or_insert_with ( || {
440440 variables. push ( info) ;
441441 var_values. push ( kind) ;
442442 assert_eq ! ( variables. len( ) , var_values. len( ) ) ;
443- CanonicalVar :: new ( variables. len ( ) - 1 )
443+ BoundTyIndex :: new ( variables. len ( ) - 1 )
444444 } )
445+ } ;
446+
447+ BoundTy {
448+ level : ty:: INNERMOST ,
449+ var,
445450 }
446451 }
447452
448453 fn canonical_var_for_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
449454 let info = CanonicalVarInfo {
450455 kind : CanonicalVarKind :: Region ,
451456 } ;
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 ) )
454460 }
455461
456462 /// Given a type variable `ty_var` of the given kind, first check
@@ -466,8 +472,9 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
466472 let info = CanonicalVarInfo {
467473 kind : CanonicalVarKind :: Ty ( ty_kind) ,
468474 } ;
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) )
471478 }
472479 }
473480}
0 commit comments