@@ -21,8 +21,8 @@ use crate::middle::lang_items;
2121use crate :: middle:: resolve_lifetime:: { self , ObjectLifetimeDefault } ;
2222use crate :: middle:: stability;
2323use 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 } ;
2626use crate :: ty:: ReprOptions ;
2727use crate :: traits;
2828use crate :: traits:: { Clause , Clauses , GoalKind , Goal , Goals } ;
@@ -31,8 +31,9 @@ use crate::ty::{TyS, TyKind, List};
3131use crate :: ty:: { AdtKind , AdtDef , ClosureSubsts , GeneratorSubsts , Region , Const , LazyConst } ;
3232use crate :: ty:: { PolyFnSig , InferTy , ParamTy , ProjectionTy , ExistentialPredicate , Predicate } ;
3333use crate :: ty:: RegionKind ;
34- use crate :: ty:: { TyVar , TyVid , IntVar , IntVid , FloatVar , FloatVid } ;
34+ use crate :: ty:: { TyVar , TyVid , IntVar , IntVid , FloatVar , FloatVid , ConstVid } ;
3535use crate :: ty:: TyKind :: * ;
36+ use crate :: ty:: { InferConst , ParamConst } ;
3637use crate :: ty:: GenericParamDefKind ;
3738use crate :: ty:: layout:: { LayoutDetails , TargetDataLayout , VariantIdx } ;
3839use crate :: ty:: query;
@@ -872,6 +873,18 @@ impl CanonicalUserType<'gcx> {
872873 }
873874 _ => false ,
874875 } ,
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+ } ,
875888 }
876889 } )
877890 } ,
@@ -2120,15 +2133,19 @@ macro_rules! sty_debug_print {
21202133 #[ derive( Copy , Clone ) ]
21212134 struct DebugStat {
21222135 total: usize ,
2123- region_infer : usize ,
2136+ lt_infer : usize ,
21242137 ty_infer: usize ,
2125- both_infer: usize ,
2138+ ct_infer: usize ,
2139+ all_infer: usize ,
21262140 }
21272141
21282142 pub fn go( tcx: TyCtxt <' _, ' _, ' _>) {
21292143 let mut total = DebugStat {
21302144 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 ,
21322149 } ;
21332150 $( let mut $variant = total; ) *
21342151
@@ -2139,31 +2156,35 @@ macro_rules! sty_debug_print {
21392156 ty:: Error => /* unimportant */ continue ,
21402157 $( ty:: $variant( ..) => & mut $variant, ) *
21412158 } ;
2142- let region = t. flags. intersects( ty:: TypeFlags :: HAS_RE_INFER ) ;
2159+ let lt = t. flags. intersects( ty:: TypeFlags :: HAS_RE_INFER ) ;
21432160 let ty = t. flags. intersects( ty:: TypeFlags :: HAS_TY_INFER ) ;
2161+ let ct = t. flags. intersects( ty:: TypeFlags :: HAS_CT_INFER ) ;
21442162
21452163 variant. total += 1 ;
21462164 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 }
21482166 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 }
21502169 }
2151- println!( "Ty interner total ty region both " ) ;
2170+ println!( "Ty interner total ty lt ct all " ) ;
21522171 $( 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+ ) *
21612181 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 )
21672188 }
21682189 }
21692190
@@ -2518,7 +2539,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25182539 let adt_def = self . adt_def ( def_id) ;
25192540 let substs = InternalSubsts :: for_item ( self , def_id, |param, substs| {
25202541 match param. kind {
2521- GenericParamDefKind :: Lifetime => bug ! ( ) ,
2542+ GenericParamDefKind :: Lifetime |
2543+ GenericParamDefKind :: Const => {
2544+ bug ! ( )
2545+ }
25222546 GenericParamDefKind :: Type { has_default, .. } => {
25232547 if param. index == 0 {
25242548 ty. into ( )
@@ -2659,10 +2683,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26592683 }
26602684
26612685 #[ inline]
2662- pub fn mk_var ( self , v : TyVid ) -> Ty < ' tcx > {
2686+ pub fn mk_ty_var ( self , v : TyVid ) -> Ty < ' tcx > {
26632687 self . mk_infer ( TyVar ( v) )
26642688 }
26652689
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+
26662698 #[ inline]
26672699 pub fn mk_int_var ( self , v : IntVid ) -> Ty < ' tcx > {
26682700 self . mk_infer ( IntVar ( v) )
@@ -2685,6 +2717,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26852717 self . mk_ty ( Param ( ParamTy { idx : index, name : name } ) )
26862718 }
26872719
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+
26882733 #[ inline]
26892734 pub fn mk_self_type ( self ) -> Ty < ' tcx > {
26902735 self . mk_ty_param ( 0 , keywords:: SelfUpper . name ( ) . as_interned_str ( ) )
@@ -2695,7 +2740,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26952740 GenericParamDefKind :: Lifetime => {
26962741 self . mk_region ( ty:: ReEarlyBound ( param. to_early_bound_region_data ( ) ) ) . into ( )
26972742 }
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+ }
26992747 }
27002748 }
27012749
0 commit comments