File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
compiler/rustc_middle/src/ty Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -75,8 +75,13 @@ impl<'tcx> Const<'tcx> {
7575 }
7676
7777 #[ inline]
78- pub fn new_var ( tcx : TyCtxt < ' tcx > , infer : ty:: ConstVid ) -> Const < ' tcx > {
79- Const :: new ( tcx, ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( infer) ) )
78+ pub fn new_var ( tcx : TyCtxt < ' tcx > , v : ty:: ConstVid ) -> Const < ' tcx > {
79+ // Use a pre-interned one when possible.
80+ tcx. consts
81+ . ct_vars
82+ . get ( v. as_usize ( ) )
83+ . copied ( )
84+ . unwrap_or_else ( || Const :: new ( tcx, ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( v) ) ) )
8085 }
8186
8287 #[ inline]
Original file line number Diff line number Diff line change @@ -1014,6 +1014,8 @@ const NUM_PREINTERNED_FRESH_TYS: u32 = 20;
10141014const NUM_PREINTERNED_FRESH_INT_TYS : u32 = 3 ;
10151015const NUM_PREINTERNED_FRESH_FLOAT_TYS : u32 = 3 ;
10161016
1017+ const NUM_PREINTERNED_CT_VARS : u32 = 100 ;
1018+
10171019// This number may seem high, but it is reached in all but the smallest crates.
10181020const NUM_PREINTERNED_RE_VARS : u32 = 500 ;
10191021const NUM_PREINTERNED_RE_LATE_BOUNDS_I : u32 = 2 ;
@@ -1084,6 +1086,8 @@ pub struct CommonConsts<'tcx> {
10841086 pub false_ : Const < ' tcx > ,
10851087 /// Use [`ty::ValTree::zst`] instead.
10861088 pub ( crate ) valtree_zst : ValTree < ' tcx > ,
1089+ /// Pre-interned `ConstKind::Infer(InferConst::Var(n))` for small values of `n`.
1090+ pub ct_vars : Vec < Const < ' tcx > > ,
10871091}
10881092
10891093impl < ' tcx > CommonTypes < ' tcx > {
@@ -1197,6 +1201,10 @@ impl<'tcx> CommonConsts<'tcx> {
11971201 let valtree_true = mk_valtree ( ty:: ValTreeKind :: Leaf ( ty:: ScalarInt :: TRUE ) ) ;
11981202 let valtree_false = mk_valtree ( ty:: ValTreeKind :: Leaf ( ty:: ScalarInt :: FALSE ) ) ;
11991203
1204+ let ct_vars = ( 0 ..NUM_PREINTERNED_CT_VARS )
1205+ . map ( |n| mk_const ( ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( ty:: ConstVid :: from ( n) ) ) ) )
1206+ . collect ( ) ;
1207+
12001208 CommonConsts {
12011209 unit : mk_const ( ty:: ConstKind :: Value ( ty:: Value {
12021210 ty : types. unit ,
@@ -1210,6 +1218,7 @@ impl<'tcx> CommonConsts<'tcx> {
12101218 ty : types. bool ,
12111219 valtree : valtree_false,
12121220 } ) ) ,
1221+ ct_vars,
12131222 valtree_zst,
12141223 }
12151224 }
You can’t perform that action at this time.
0 commit comments