@@ -13,13 +13,13 @@ impl<'tcx> TyCtxt<'tcx> {
1313 pub fn const_eval_poly ( self , def_id : DefId ) -> ConstEvalResult < ' tcx > {
1414 // In some situations def_id will have substitutions within scope, but they aren't allowed
1515 // to be used. So we can't use `Instance::mono`, instead we feed unresolved substitutions
16- // into `const_eval` which will return `ErrorHandled::ToGeneric` if any og them are
16+ // into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
1717 // encountered.
1818 let substs = InternalSubsts :: identity_for_item ( self , def_id) ;
1919 let instance = ty:: Instance :: new ( def_id, substs) ;
2020 let cid = GlobalId { instance, promoted : None } ;
2121 let param_env = self . param_env ( def_id) . with_reveal_all ( ) ;
22- self . const_eval_validated ( param_env. and ( cid) )
22+ self . const_eval_global_id ( param_env, cid, None )
2323 }
2424
2525 /// Resolves and evaluates a constant.
@@ -41,11 +41,8 @@ impl<'tcx> TyCtxt<'tcx> {
4141 ) -> ConstEvalResult < ' tcx > {
4242 let instance = ty:: Instance :: resolve ( self , param_env, def_id, substs) ;
4343 if let Some ( instance) = instance {
44- if let Some ( promoted) = promoted {
45- self . const_eval_promoted ( param_env, instance, promoted)
46- } else {
47- self . const_eval_instance ( param_env, instance, span)
48- }
44+ let cid = GlobalId { instance, promoted } ;
45+ self . const_eval_global_id ( param_env, cid, span)
4946 } else {
5047 Err ( ErrorHandled :: TooGeneric )
5148 }
@@ -57,22 +54,23 @@ impl<'tcx> TyCtxt<'tcx> {
5754 instance : ty:: Instance < ' tcx > ,
5855 span : Option < Span > ,
5956 ) -> ConstEvalResult < ' tcx > {
60- let cid = GlobalId { instance, promoted : None } ;
61- if let Some ( span) = span {
62- self . at ( span) . const_eval_validated ( param_env. and ( cid) )
63- } else {
64- self . const_eval_validated ( param_env. and ( cid) )
65- }
57+ self . const_eval_global_id ( param_env, GlobalId { instance, promoted : None } , span)
6658 }
6759
68- /// Evaluate a promoted constant.
69- pub fn const_eval_promoted (
60+ /// Evaluate a constant.
61+ pub fn const_eval_global_id (
7062 self ,
7163 param_env : ty:: ParamEnv < ' tcx > ,
72- instance : ty :: Instance < ' tcx > ,
73- promoted : mir :: Promoted ,
64+ cid : GlobalId < ' tcx > ,
65+ span : Option < Span > ,
7466 ) -> ConstEvalResult < ' tcx > {
75- let cid = GlobalId { instance, promoted : Some ( promoted) } ;
76- self . const_eval_validated ( param_env. and ( cid) )
67+ // Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
68+ // improve caching of queries.
69+ let inputs = self . erase_regions ( & param_env. and ( cid) ) ;
70+ if let Some ( span) = span {
71+ self . at ( span) . const_eval_validated ( inputs)
72+ } else {
73+ self . const_eval_validated ( inputs)
74+ }
7775 }
7876}
0 commit comments