@@ -17,7 +17,7 @@ use rustc_target::abi::{self, Abi};
17
17
use super :: { CompileTimeEvalContext , CompileTimeInterpreter , ConstEvalErr } ;
18
18
use crate :: interpret:: eval_nullary_intrinsic;
19
19
use crate :: interpret:: {
20
- intern_const_alloc_recursive, Allocation , ConstAlloc , ConstValue , CtfeValidationMode , GlobalId ,
20
+ intern_const_alloc_recursive, Allocation , ConstAlloc , ConstValue , CtfeValidationMode ,
21
21
Immediate , InternKind , InterpCx , InterpError , InterpResult , MPlaceTy , MemoryKind , OpTy ,
22
22
RefTracking , StackPopCleanup ,
23
23
} ;
@@ -29,14 +29,14 @@ const NOTE_ON_UNDEFINED_BEHAVIOR_ERROR: &str = "The rules on what exactly is und
29
29
// Returns a pointer to where the result lives
30
30
fn eval_body_using_ecx < ' mir , ' tcx > (
31
31
ecx : & mut CompileTimeEvalContext < ' mir , ' tcx > ,
32
- cid : GlobalId < ' tcx > ,
32
+ instance : ty :: Instance < ' tcx > ,
33
33
body : & ' mir mir:: Body < ' tcx > ,
34
34
) -> InterpResult < ' tcx , MPlaceTy < ' tcx > > {
35
- debug ! ( "eval_body_using_ecx: {:?}, {:?}" , cid , ecx. param_env) ;
35
+ debug ! ( "eval_body_using_ecx: {:?}, {:?}" , instance , ecx. param_env) ;
36
36
let tcx = * ecx. tcx ;
37
37
assert ! (
38
38
matches!(
39
- ecx. tcx. def_kind( cid . instance. def_id( ) ) ,
39
+ ecx. tcx. def_kind( instance. def_id( ) ) ,
40
40
DefKind :: Const
41
41
| DefKind :: Static ( _)
42
42
| DefKind :: ConstParam
@@ -46,29 +46,21 @@ fn eval_body_using_ecx<'mir, 'tcx>(
46
46
| DefKind :: Promoted
47
47
) ,
48
48
"Unexpected DefKind: {:?}" ,
49
- ecx. tcx. def_kind( cid . instance. def_id( ) )
49
+ ecx. tcx. def_kind( instance. def_id( ) )
50
50
) ;
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 ) ) ?;
52
52
assert ! ( layout. is_sized( ) ) ;
53
53
let ret = ecx. allocate ( layout, MemoryKind :: Stack ) ?;
54
54
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( ) ) ;
59
56
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 } ) ?;
66
58
67
59
// The main interpreter loop.
68
60
while ecx. step ( ) ? { }
69
61
70
62
// 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 ( ) ) {
72
64
DefKind :: Promoted => InternKind :: Promoted ,
73
65
DefKind :: Static ( m) => InternKind :: Static ( m) ,
74
66
_ => InternKind :: Constant ,
@@ -196,15 +188,15 @@ pub(super) fn op_to_const<'tcx>(
196
188
pub ( crate ) fn turn_into_const_value < ' tcx > (
197
189
tcx : TyCtxt < ' tcx > ,
198
190
constant : ConstAlloc < ' tcx > ,
199
- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
191
+ key : ty:: ParamEnvAnd < ' tcx , ty :: Instance < ' tcx > > ,
200
192
) -> 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 ( ) ;
203
195
let is_static = tcx. is_static ( def_id) ;
204
196
// This is just accessing an already computed constant, so no need to check alignment here.
205
197
let ecx = mk_eval_cx (
206
198
tcx,
207
- tcx. def_span ( key . value . instance . def_id ( ) ) ,
199
+ tcx. def_span ( def_id) ,
208
200
key. param_env ,
209
201
/*can_access_statics:*/ is_static,
210
202
) ;
@@ -225,7 +217,7 @@ pub(crate) fn turn_into_const_value<'tcx>(
225
217
#[ instrument( skip( tcx) , level = "debug" ) ]
226
218
pub fn eval_to_const_value_raw_provider < ' tcx > (
227
219
tcx : TyCtxt < ' tcx > ,
228
- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
220
+ key : ty:: ParamEnvAnd < ' tcx , ty :: Instance < ' tcx > > ,
229
221
) -> :: rustc_middle:: mir:: interpret:: EvalToConstValueResult < ' tcx > {
230
222
assert ! ( key. param_env. is_const( ) ) ;
231
223
// 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>(
242
234
243
235
// We call `const_eval` for zero arg intrinsics, too, in order to cache their value.
244
236
// 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 ) ;
247
239
let ty:: FnDef ( _, substs) = ty. kind ( ) else {
248
240
bug ! ( "intrinsic with type {:?}" , ty) ;
249
241
} ;
@@ -260,7 +252,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
260
252
#[ instrument( skip( tcx) , level = "debug" ) ]
261
253
pub fn eval_to_allocation_raw_provider < ' tcx > (
262
254
tcx : TyCtxt < ' tcx > ,
263
- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
255
+ key : ty:: ParamEnvAnd < ' tcx , ty :: Instance < ' tcx > > ,
264
256
) -> :: rustc_middle:: mir:: interpret:: EvalToAllocationRawResult < ' tcx > {
265
257
assert ! ( key. param_env. is_const( ) ) ;
266
258
// 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>(
281
273
other => return other,
282
274
}
283
275
}
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) ;
293
277
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 ( ) ;
296
280
let within_static = match tcx. def_kind ( def) {
297
281
DefKind :: Promoted => tcx. is_static ( tcx. parent ( def) ) ,
298
282
DefKind :: Static ( _) => true ,
@@ -316,8 +300,8 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
316
300
) ,
317
301
) ;
318
302
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) ) {
321
305
Err ( error) => {
322
306
let err = ConstEvalErr :: new ( & ecx, error, None ) ;
323
307
let msg = if within_static {
@@ -326,7 +310,6 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
326
310
// If the current item has generics, we'd like to enrich the message with the
327
311
// instance and its substs: to show the actual compile-time values, in addition to
328
312
// the expression, leading to the const eval error.
329
- let instance = & key. value . instance ;
330
313
if !instance. substs . is_empty ( ) {
331
314
let instance = with_no_trimmed_paths ! ( instance. to_string( ) ) ;
332
315
let msg = format ! ( "evaluation of `{}` failed" , instance) ;
0 commit comments