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> {
75
75
}
76
76
77
77
#[ 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) ) ) )
80
85
}
81
86
82
87
#[ inline]
Original file line number Diff line number Diff line change @@ -1014,6 +1014,8 @@ const NUM_PREINTERNED_FRESH_TYS: u32 = 20;
1014
1014
const NUM_PREINTERNED_FRESH_INT_TYS : u32 = 3 ;
1015
1015
const NUM_PREINTERNED_FRESH_FLOAT_TYS : u32 = 3 ;
1016
1016
1017
+ const NUM_PREINTERNED_CT_VARS : u32 = 100 ;
1018
+
1017
1019
// This number may seem high, but it is reached in all but the smallest crates.
1018
1020
const NUM_PREINTERNED_RE_VARS : u32 = 500 ;
1019
1021
const NUM_PREINTERNED_RE_LATE_BOUNDS_I : u32 = 2 ;
@@ -1084,6 +1086,8 @@ pub struct CommonConsts<'tcx> {
1084
1086
pub false_ : Const < ' tcx > ,
1085
1087
/// Use [`ty::ValTree::zst`] instead.
1086
1088
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 > > ,
1087
1091
}
1088
1092
1089
1093
impl < ' tcx > CommonTypes < ' tcx > {
@@ -1197,6 +1201,10 @@ impl<'tcx> CommonConsts<'tcx> {
1197
1201
let valtree_true = mk_valtree ( ty:: ValTreeKind :: Leaf ( ty:: ScalarInt :: TRUE ) ) ;
1198
1202
let valtree_false = mk_valtree ( ty:: ValTreeKind :: Leaf ( ty:: ScalarInt :: FALSE ) ) ;
1199
1203
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
+
1200
1208
CommonConsts {
1201
1209
unit : mk_const ( ty:: ConstKind :: Value ( ty:: Value {
1202
1210
ty : types. unit ,
@@ -1210,6 +1218,7 @@ impl<'tcx> CommonConsts<'tcx> {
1210
1218
ty : types. bool ,
1211
1219
valtree : valtree_false,
1212
1220
} ) ) ,
1221
+ ct_vars,
1213
1222
valtree_zst,
1214
1223
}
1215
1224
}
You can’t perform that action at this time.
0 commit comments