@@ -17,7 +17,7 @@ use rustc_target::abi::{self, Abi};
1717use super :: { CompileTimeEvalContext , CompileTimeInterpreter , ConstEvalErr } ;
1818use crate :: interpret:: eval_nullary_intrinsic;
1919use crate :: interpret:: {
20- intern_const_alloc_recursive, Allocation , ConstAlloc , ConstValue , CtfeValidationMode , GlobalId ,
20+ intern_const_alloc_recursive, Allocation , ConstAlloc , ConstValue , CtfeValidationMode ,
2121 Immediate , InternKind , InterpCx , InterpError , InterpResult , MPlaceTy , MemoryKind , OpTy ,
2222 RefTracking , StackPopCleanup ,
2323} ;
@@ -29,14 +29,14 @@ const NOTE_ON_UNDEFINED_BEHAVIOR_ERROR: &str = "The rules on what exactly is und
2929// Returns a pointer to where the result lives
3030fn eval_body_using_ecx < ' mir , ' tcx > (
3131 ecx : & mut CompileTimeEvalContext < ' mir , ' tcx > ,
32- cid : GlobalId < ' tcx > ,
32+ instance : ty :: Instance < ' tcx > ,
3333 body : & ' mir mir:: Body < ' tcx > ,
3434) -> InterpResult < ' tcx , MPlaceTy < ' tcx > > {
35- debug ! ( "eval_body_using_ecx: {:?}, {:?}" , cid , ecx. param_env) ;
35+ debug ! ( "eval_body_using_ecx: {:?}, {:?}" , instance , ecx. param_env) ;
3636 let tcx = * ecx. tcx ;
3737 assert ! (
3838 matches!(
39- ecx. tcx. def_kind( cid . instance. def_id( ) ) ,
39+ ecx. tcx. def_kind( instance. def_id( ) ) ,
4040 DefKind :: Const
4141 | DefKind :: Static ( _)
4242 | DefKind :: ConstParam
@@ -46,29 +46,21 @@ fn eval_body_using_ecx<'mir, 'tcx>(
4646 | DefKind :: Promoted
4747 ) ,
4848 "Unexpected DefKind: {:?}" ,
49- ecx. tcx. def_kind( cid . instance. def_id( ) )
49+ ecx. tcx. def_kind( instance. def_id( ) )
5050 ) ;
51- let layout = ecx. layout_of ( body. bound_return_ty ( ) . subst ( tcx, cid . instance . substs ) ) ?;
51+ let layout = ecx. layout_of ( body. bound_return_ty ( ) . subst ( tcx, instance. substs ) ) ?;
5252 assert ! ( layout. is_sized( ) ) ;
5353 let ret = ecx. allocate ( layout, MemoryKind :: Stack ) ?;
5454
55- trace ! (
56- "eval_body_using_ecx: pushing stack frame for global: {}" ,
57- with_no_trimmed_paths!( ecx. tcx. def_path_str( cid. instance. def_id( ) ) ) ,
58- ) ;
55+ trace ! ( "eval_body_using_ecx: pushing stack frame for global: {:?}" , instance. def_id( ) ) ;
5956
60- ecx. push_stack_frame (
61- cid. instance ,
62- body,
63- & ret. into ( ) ,
64- StackPopCleanup :: Root { cleanup : false } ,
65- ) ?;
57+ ecx. push_stack_frame ( instance, body, & ret. into ( ) , StackPopCleanup :: Root { cleanup : false } ) ?;
6658
6759 // The main interpreter loop.
6860 while ecx. step ( ) ? { }
6961
7062 // Intern the result
71- let intern_kind = match tcx. def_kind ( cid . instance . def_id ( ) ) {
63+ let intern_kind = match tcx. def_kind ( instance. def_id ( ) ) {
7264 DefKind :: Promoted => InternKind :: Promoted ,
7365 DefKind :: Static ( m) => InternKind :: Static ( m) ,
7466 _ => InternKind :: Constant ,
@@ -196,15 +188,15 @@ pub(super) fn op_to_const<'tcx>(
196188pub ( crate ) fn turn_into_const_value < ' tcx > (
197189 tcx : TyCtxt < ' tcx > ,
198190 constant : ConstAlloc < ' tcx > ,
199- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
191+ key : ty:: ParamEnvAnd < ' tcx , ty :: Instance < ' tcx > > ,
200192) -> ConstValue < ' tcx > {
201- let cid = key. value ;
202- let def_id = cid . instance . def . def_id ( ) ;
193+ let instance = key. value ;
194+ let def_id = instance. def . def_id ( ) ;
203195 let is_static = tcx. is_static ( def_id) ;
204196 // This is just accessing an already computed constant, so no need to check alignment here.
205197 let ecx = mk_eval_cx (
206198 tcx,
207- tcx. def_span ( key . value . instance . def_id ( ) ) ,
199+ tcx. def_span ( def_id) ,
208200 key. param_env ,
209201 /*can_access_statics:*/ is_static,
210202 ) ;
@@ -225,7 +217,7 @@ pub(crate) fn turn_into_const_value<'tcx>(
225217#[ instrument( skip( tcx) , level = "debug" ) ]
226218pub fn eval_to_const_value_raw_provider < ' tcx > (
227219 tcx : TyCtxt < ' tcx > ,
228- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
220+ key : ty:: ParamEnvAnd < ' tcx , ty :: Instance < ' tcx > > ,
229221) -> :: rustc_middle:: mir:: interpret:: EvalToConstValueResult < ' tcx > {
230222 assert ! ( key. param_env. is_const( ) ) ;
231223 // see comment in eval_to_allocation_raw_provider for what we're doing here
@@ -242,8 +234,8 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
242234
243235 // We call `const_eval` for zero arg intrinsics, too, in order to cache their value.
244236 // Catch such calls and evaluate them instead of trying to load a constant's MIR.
245- if let ty:: InstanceDef :: Intrinsic ( def_id) = key. value . instance . def {
246- let ty = key. value . instance . ty ( tcx, key. param_env ) ;
237+ if let ty:: InstanceDef :: Intrinsic ( def_id) = key. value . def {
238+ let ty = key. value . ty ( tcx, key. param_env ) ;
247239 let ty:: FnDef ( _, substs) = ty. kind ( ) else {
248240 bug ! ( "intrinsic with type {:?}" , ty) ;
249241 } ;
@@ -260,7 +252,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
260252#[ instrument( skip( tcx) , level = "debug" ) ]
261253pub fn eval_to_allocation_raw_provider < ' tcx > (
262254 tcx : TyCtxt < ' tcx > ,
263- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
255+ key : ty:: ParamEnvAnd < ' tcx , ty :: Instance < ' tcx > > ,
264256) -> :: rustc_middle:: mir:: interpret:: EvalToAllocationRawResult < ' tcx > {
265257 assert ! ( key. param_env. is_const( ) ) ;
266258 // Because the constant is computed twice (once per value of `Reveal`), we are at risk of
@@ -281,18 +273,10 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
281273 other => return other,
282274 }
283275 }
284- if cfg ! ( debug_assertions) {
285- // Make sure we format the instance even if we do not print it.
286- // This serves as a regression test against an ICE on printing.
287- // The next two lines concatenated contain some discussion:
288- // https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/
289- // subject/anon_const_instance_printing/near/135980032
290- let instance = with_no_trimmed_paths ! ( key. value. instance. to_string( ) ) ;
291- trace ! ( "const eval: {:?} ({})" , key, instance) ;
292- }
276+ trace ! ( "const eval: {:?}" , key) ;
293277
294- let cid = key. value ;
295- let def = cid . instance . def . def_id ( ) ;
278+ let instance = key. value ;
279+ let def = instance. def . def_id ( ) ;
296280 let within_static = match tcx. def_kind ( def) {
297281 DefKind :: Promoted => tcx. is_static ( tcx. parent ( def) ) ,
298282 DefKind :: Static ( _) => true ,
@@ -316,8 +300,8 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
316300 ) ,
317301 ) ;
318302
319- let res = ecx. load_mir ( cid . instance . def ) ;
320- match res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid , & body) ) {
303+ let res = ecx. load_mir ( instance. def ) ;
304+ match res. and_then ( |body| eval_body_using_ecx ( & mut ecx, instance , & body) ) {
321305 Err ( error) => {
322306 let err = ConstEvalErr :: new ( & ecx, error, None ) ;
323307 let msg = if within_static {
@@ -326,7 +310,6 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
326310 // If the current item has generics, we'd like to enrich the message with the
327311 // instance and its substs: to show the actual compile-time values, in addition to
328312 // the expression, leading to the const eval error.
329- let instance = & key. value . instance ;
330313 if !instance. substs . is_empty ( ) {
331314 let instance = with_no_trimmed_paths ! ( instance. to_string( ) ) ;
332315 let msg = format ! ( "evaluation of `{}` failed" , instance) ;
0 commit comments