@@ -13,13 +13,13 @@ impl<'tcx> TyCtxt<'tcx> {
13
13
pub fn const_eval_poly ( self , def_id : DefId ) -> ConstEvalResult < ' tcx > {
14
14
// In some situations def_id will have substitutions within scope, but they aren't allowed
15
15
// 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
17
17
// encountered.
18
18
let substs = InternalSubsts :: identity_for_item ( self , def_id) ;
19
19
let instance = ty:: Instance :: new ( def_id, substs) ;
20
20
let cid = GlobalId { instance, promoted : None } ;
21
21
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 )
23
23
}
24
24
25
25
/// Resolves and evaluates a constant.
@@ -41,11 +41,8 @@ impl<'tcx> TyCtxt<'tcx> {
41
41
) -> ConstEvalResult < ' tcx > {
42
42
let instance = ty:: Instance :: resolve ( self , param_env, def_id, substs) ;
43
43
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)
49
46
} else {
50
47
Err ( ErrorHandled :: TooGeneric )
51
48
}
@@ -57,22 +54,23 @@ impl<'tcx> TyCtxt<'tcx> {
57
54
instance : ty:: Instance < ' tcx > ,
58
55
span : Option < Span > ,
59
56
) -> 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)
66
58
}
67
59
68
- /// Evaluate a promoted constant.
69
- pub fn const_eval_promoted (
60
+ /// Evaluate a constant.
61
+ pub fn const_eval_global_id (
70
62
self ,
71
63
param_env : ty:: ParamEnv < ' tcx > ,
72
- instance : ty :: Instance < ' tcx > ,
73
- promoted : mir :: Promoted ,
64
+ cid : GlobalId < ' tcx > ,
65
+ span : Option < Span > ,
74
66
) -> 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
+ }
77
75
}
78
76
}
0 commit comments