@@ -21,8 +21,8 @@ use crate::middle::lang_items;
21
21
use crate :: middle:: resolve_lifetime:: { self , ObjectLifetimeDefault } ;
22
22
use crate :: middle:: stability;
23
23
use crate :: mir:: { self , Mir , interpret, ProjectionKind } ;
24
- use crate :: mir:: interpret:: Allocation ;
25
- use crate :: ty:: subst:: { Kind , InternalSubsts , Subst , SubstsRef } ;
24
+ use crate :: mir:: interpret:: { ConstValue , Allocation } ;
25
+ use crate :: ty:: subst:: { Kind , InternalSubsts , SubstsRef , Subst } ;
26
26
use crate :: ty:: ReprOptions ;
27
27
use crate :: traits;
28
28
use crate :: traits:: { Clause , Clauses , GoalKind , Goal , Goals } ;
@@ -31,8 +31,9 @@ use crate::ty::{TyS, TyKind, List};
31
31
use crate :: ty:: { AdtKind , AdtDef , ClosureSubsts , GeneratorSubsts , Region , Const , LazyConst } ;
32
32
use crate :: ty:: { PolyFnSig , InferTy , ParamTy , ProjectionTy , ExistentialPredicate , Predicate } ;
33
33
use crate :: ty:: RegionKind ;
34
- use crate :: ty:: { TyVar , TyVid , IntVar , IntVid , FloatVar , FloatVid } ;
34
+ use crate :: ty:: { TyVar , TyVid , IntVar , IntVid , FloatVar , FloatVid , ConstVid } ;
35
35
use crate :: ty:: TyKind :: * ;
36
+ use crate :: ty:: { InferConst , ParamConst } ;
36
37
use crate :: ty:: GenericParamDefKind ;
37
38
use crate :: ty:: layout:: { LayoutDetails , TargetDataLayout , VariantIdx } ;
38
39
use crate :: ty:: query;
@@ -872,6 +873,18 @@ impl CanonicalUserType<'gcx> {
872
873
}
873
874
_ => false ,
874
875
} ,
876
+
877
+ UnpackedKind :: Const ( ct) => match ct {
878
+ ty:: LazyConst :: Evaluated ( ty:: Const {
879
+ val : ConstValue :: Infer ( InferConst :: Canonical ( debruijn, b) ) ,
880
+ ..
881
+ } ) => {
882
+ // We only allow a `ty::INNERMOST` index in substitutions.
883
+ assert_eq ! ( * debruijn, ty:: INNERMOST ) ;
884
+ cvar == * b
885
+ }
886
+ _ => false ,
887
+ } ,
875
888
}
876
889
} )
877
890
} ,
@@ -2120,15 +2133,19 @@ macro_rules! sty_debug_print {
2120
2133
#[ derive( Copy , Clone ) ]
2121
2134
struct DebugStat {
2122
2135
total: usize ,
2123
- region_infer : usize ,
2136
+ lt_infer : usize ,
2124
2137
ty_infer: usize ,
2125
- both_infer: usize ,
2138
+ ct_infer: usize ,
2139
+ all_infer: usize ,
2126
2140
}
2127
2141
2128
2142
pub fn go( tcx: TyCtxt <' _, ' _, ' _>) {
2129
2143
let mut total = DebugStat {
2130
2144
total: 0 ,
2131
- region_infer: 0 , ty_infer: 0 , both_infer: 0 ,
2145
+ lt_infer: 0 ,
2146
+ ty_infer: 0 ,
2147
+ ct_infer: 0 ,
2148
+ all_infer: 0 ,
2132
2149
} ;
2133
2150
$( let mut $variant = total; ) *
2134
2151
@@ -2139,31 +2156,35 @@ macro_rules! sty_debug_print {
2139
2156
ty:: Error => /* unimportant */ continue ,
2140
2157
$( ty:: $variant( ..) => & mut $variant, ) *
2141
2158
} ;
2142
- let region = t. flags. intersects( ty:: TypeFlags :: HAS_RE_INFER ) ;
2159
+ let lt = t. flags. intersects( ty:: TypeFlags :: HAS_RE_INFER ) ;
2143
2160
let ty = t. flags. intersects( ty:: TypeFlags :: HAS_TY_INFER ) ;
2161
+ let ct = t. flags. intersects( ty:: TypeFlags :: HAS_CT_INFER ) ;
2144
2162
2145
2163
variant. total += 1 ;
2146
2164
total. total += 1 ;
2147
- if region { total. region_infer += 1 ; variant. region_infer += 1 }
2165
+ if lt { total. lt_infer += 1 ; variant. lt_infer += 1 }
2148
2166
if ty { total. ty_infer += 1 ; variant. ty_infer += 1 }
2149
- if region && ty { total. both_infer += 1 ; variant. both_infer += 1 }
2167
+ if ct { total. ct_infer += 1 ; variant. ct_infer += 1 }
2168
+ if lt && ty && ct { total. all_infer += 1 ; variant. all_infer += 1 }
2150
2169
}
2151
- println!( "Ty interner total ty region both " ) ;
2170
+ println!( "Ty interner total ty lt ct all " ) ;
2152
2171
$( println!( " {:18}: {uses:6} {usespc:4.1}%, \
2153
- {ty:4.1}% {region:5.1}% {both:4.1}%",
2154
- stringify!( $variant) ,
2155
- uses = $variant. total,
2156
- usespc = $variant. total as f64 * 100.0 / total. total as f64 ,
2157
- ty = $variant. ty_infer as f64 * 100.0 / total. total as f64 ,
2158
- region = $variant. region_infer as f64 * 100.0 / total. total as f64 ,
2159
- both = $variant. both_infer as f64 * 100.0 / total. total as f64 ) ;
2160
- ) *
2172
+ {ty:4.1}% {lt:5.1}% {ct:4.1}% {all:4.1}%",
2173
+ stringify!( $variant) ,
2174
+ uses = $variant. total,
2175
+ usespc = $variant. total as f64 * 100.0 / total. total as f64 ,
2176
+ ty = $variant. ty_infer as f64 * 100.0 / total. total as f64 ,
2177
+ lt = $variant. lt_infer as f64 * 100.0 / total. total as f64 ,
2178
+ ct = $variant. ct_infer as f64 * 100.0 / total. total as f64 ,
2179
+ all = $variant. all_infer as f64 * 100.0 / total. total as f64 ) ;
2180
+ ) *
2161
2181
println!( " total {uses:6} \
2162
- {ty:4.1}% {region:5.1}% {both:4.1}%",
2163
- uses = total. total,
2164
- ty = total. ty_infer as f64 * 100.0 / total. total as f64 ,
2165
- region = total. region_infer as f64 * 100.0 / total. total as f64 ,
2166
- both = total. both_infer as f64 * 100.0 / total. total as f64 )
2182
+ {ty:4.1}% {lt:5.1}% {ct:4.1}% {all:4.1}%",
2183
+ uses = total. total,
2184
+ ty = total. ty_infer as f64 * 100.0 / total. total as f64 ,
2185
+ lt = total. lt_infer as f64 * 100.0 / total. total as f64 ,
2186
+ ct = total. ct_infer as f64 * 100.0 / total. total as f64 ,
2187
+ all = total. all_infer as f64 * 100.0 / total. total as f64 )
2167
2188
}
2168
2189
}
2169
2190
@@ -2518,7 +2539,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2518
2539
let adt_def = self . adt_def ( def_id) ;
2519
2540
let substs = InternalSubsts :: for_item ( self , def_id, |param, substs| {
2520
2541
match param. kind {
2521
- GenericParamDefKind :: Lifetime => bug ! ( ) ,
2542
+ GenericParamDefKind :: Lifetime |
2543
+ GenericParamDefKind :: Const => {
2544
+ bug ! ( )
2545
+ }
2522
2546
GenericParamDefKind :: Type { has_default, .. } => {
2523
2547
if param. index == 0 {
2524
2548
ty. into ( )
@@ -2659,10 +2683,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2659
2683
}
2660
2684
2661
2685
#[ inline]
2662
- pub fn mk_var ( self , v : TyVid ) -> Ty < ' tcx > {
2686
+ pub fn mk_ty_var ( self , v : TyVid ) -> Ty < ' tcx > {
2663
2687
self . mk_infer ( TyVar ( v) )
2664
2688
}
2665
2689
2690
+ #[ inline]
2691
+ pub fn mk_const_var ( self , v : ConstVid < ' tcx > , ty : Ty < ' tcx > ) -> & ' tcx LazyConst < ' tcx > {
2692
+ self . mk_lazy_const ( LazyConst :: Evaluated ( ty:: Const {
2693
+ val : ConstValue :: Infer ( InferConst :: Var ( v) ) ,
2694
+ ty,
2695
+ } ) )
2696
+ }
2697
+
2666
2698
#[ inline]
2667
2699
pub fn mk_int_var ( self , v : IntVid ) -> Ty < ' tcx > {
2668
2700
self . mk_infer ( IntVar ( v) )
@@ -2685,6 +2717,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2685
2717
self . mk_ty ( Param ( ParamTy { idx : index, name : name } ) )
2686
2718
}
2687
2719
2720
+ #[ inline]
2721
+ pub fn mk_const_param (
2722
+ self ,
2723
+ index : u32 ,
2724
+ name : InternedString ,
2725
+ ty : Ty < ' tcx >
2726
+ ) -> & ' tcx LazyConst < ' tcx > {
2727
+ self . mk_lazy_const ( LazyConst :: Evaluated ( ty:: Const {
2728
+ val : ConstValue :: Param ( ParamConst { index, name } ) ,
2729
+ ty,
2730
+ } ) )
2731
+ }
2732
+
2688
2733
#[ inline]
2689
2734
pub fn mk_self_type ( self ) -> Ty < ' tcx > {
2690
2735
self . mk_ty_param ( 0 , keywords:: SelfUpper . name ( ) . as_interned_str ( ) )
@@ -2695,7 +2740,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2695
2740
GenericParamDefKind :: Lifetime => {
2696
2741
self . mk_region ( ty:: ReEarlyBound ( param. to_early_bound_region_data ( ) ) ) . into ( )
2697
2742
}
2698
- GenericParamDefKind :: Type { ..} => self . mk_ty_param ( param. index , param. name ) . into ( ) ,
2743
+ GenericParamDefKind :: Type { .. } => self . mk_ty_param ( param. index , param. name ) . into ( ) ,
2744
+ GenericParamDefKind :: Const => {
2745
+ self . mk_const_param ( param. index , param. name , self . type_of ( param. def_id ) ) . into ( )
2746
+ }
2699
2747
}
2700
2748
}
2701
2749
0 commit comments