@@ -7,7 +7,6 @@ use rustc_middle::bug;
7
7
use rustc_middle:: mir:: interpret:: { AllocId , ErrorHandled , InterpErrorInfo } ;
8
8
use rustc_middle:: mir:: { self , ConstAlloc , ConstValue } ;
9
9
use rustc_middle:: query:: TyCtxtAt ;
10
- use rustc_middle:: traits:: Reveal ;
11
10
use rustc_middle:: ty:: layout:: LayoutOf ;
12
11
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
13
12
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
@@ -31,7 +30,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
31
30
cid : GlobalId < ' tcx > ,
32
31
body : & ' tcx mir:: Body < ' tcx > ,
33
32
) -> InterpResult < ' tcx , R > {
34
- trace ! ( ?ecx. param_env ) ;
33
+ trace ! ( ?ecx. typing_env ) ;
35
34
let tcx = * ecx. tcx ;
36
35
assert ! (
37
36
cid. promoted. is_some( )
@@ -126,14 +125,14 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
126
125
pub ( crate ) fn mk_eval_cx_to_read_const_val < ' tcx > (
127
126
tcx : TyCtxt < ' tcx > ,
128
127
root_span : Span ,
129
- param_env : ty:: ParamEnv < ' tcx > ,
128
+ typing_env : ty:: TypingEnv < ' tcx > ,
130
129
can_access_mut_global : CanAccessMutGlobal ,
131
130
) -> CompileTimeInterpCx < ' tcx > {
132
- debug ! ( "mk_eval_cx: {:?}" , param_env ) ;
131
+ debug ! ( "mk_eval_cx: {:?}" , typing_env ) ;
133
132
InterpCx :: new (
134
133
tcx,
135
134
root_span,
136
- param_env ,
135
+ typing_env ,
137
136
CompileTimeMachine :: new ( can_access_mut_global, CheckAlignment :: No ) ,
138
137
)
139
138
}
@@ -142,11 +141,11 @@ pub(crate) fn mk_eval_cx_to_read_const_val<'tcx>(
142
141
/// Returns both the context and an `OpTy` that represents the constant.
143
142
pub fn mk_eval_cx_for_const_val < ' tcx > (
144
143
tcx : TyCtxtAt < ' tcx > ,
145
- param_env : ty:: ParamEnv < ' tcx > ,
144
+ typing_env : ty:: TypingEnv < ' tcx > ,
146
145
val : mir:: ConstValue < ' tcx > ,
147
146
ty : Ty < ' tcx > ,
148
147
) -> Option < ( CompileTimeInterpCx < ' tcx > , OpTy < ' tcx > ) > {
149
- let ecx = mk_eval_cx_to_read_const_val ( tcx. tcx , tcx. span , param_env , CanAccessMutGlobal :: No ) ;
148
+ let ecx = mk_eval_cx_to_read_const_val ( tcx. tcx , tcx. span , typing_env , CanAccessMutGlobal :: No ) ;
150
149
// FIXME: is it a problem to discard the error here?
151
150
let op = ecx. const_val_to_op ( val, ty, None ) . discard_err ( ) ?;
152
151
Some ( ( ecx, op) )
@@ -221,7 +220,7 @@ pub(super) fn op_to_const<'tcx>(
221
220
let pointee_ty = imm. layout . ty . builtin_deref ( false ) . unwrap ( ) ; // `false` = no raw ptrs
222
221
debug_assert ! (
223
222
matches!(
224
- ecx. tcx. struct_tail_for_codegen( pointee_ty, ecx. typing_env( ) ) . kind( ) ,
223
+ ecx. tcx. struct_tail_for_codegen( pointee_ty, ecx. typing_env) . kind( ) ,
225
224
ty:: Str | ty:: Slice ( ..) ,
226
225
) ,
227
226
"`ConstValue::Slice` is for slice-tailed types only, but got {}" ,
@@ -245,7 +244,7 @@ pub(super) fn op_to_const<'tcx>(
245
244
pub ( crate ) fn turn_into_const_value < ' tcx > (
246
245
tcx : TyCtxt < ' tcx > ,
247
246
constant : ConstAlloc < ' tcx > ,
248
- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
247
+ key : ty:: PseudoCanonicalInput < ' tcx , GlobalId < ' tcx > > ,
249
248
) -> ConstValue < ' tcx > {
250
249
let cid = key. value ;
251
250
let def_id = cid. instance . def . def_id ( ) ;
@@ -254,7 +253,7 @@ pub(crate) fn turn_into_const_value<'tcx>(
254
253
let ecx = mk_eval_cx_to_read_const_val (
255
254
tcx,
256
255
tcx. def_span ( key. value . instance . def_id ( ) ) ,
257
- key. param_env ,
256
+ key. typing_env ,
258
257
CanAccessMutGlobal :: from ( is_static) ,
259
258
) ;
260
259
@@ -274,23 +273,16 @@ pub(crate) fn turn_into_const_value<'tcx>(
274
273
#[ instrument( skip( tcx) , level = "debug" ) ]
275
274
pub fn eval_to_const_value_raw_provider < ' tcx > (
276
275
tcx : TyCtxt < ' tcx > ,
277
- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
276
+ key : ty:: PseudoCanonicalInput < ' tcx , GlobalId < ' tcx > > ,
278
277
) -> :: rustc_middle:: mir:: interpret:: EvalToConstValueResult < ' tcx > {
279
- // Const eval always happens in Reveal::All mode in order to be able to use the hidden types of
280
- // opaque types. This is needed for trivial things like `size_of`, but also for using associated
281
- // types that are not specified in the opaque type.
282
- assert_eq ! ( key. param_env. reveal( ) , Reveal :: All ) ;
283
- let typing_env =
284
- ty:: TypingEnv { typing_mode : ty:: TypingMode :: PostAnalysis , param_env : key. param_env } ;
285
-
286
278
// We call `const_eval` for zero arg intrinsics, too, in order to cache their value.
287
279
// Catch such calls and evaluate them instead of trying to load a constant's MIR.
288
280
if let ty:: InstanceKind :: Intrinsic ( def_id) = key. value . instance . def {
289
- let ty = key. value . instance . ty ( tcx, typing_env) ;
281
+ let ty = key. value . instance . ty ( tcx, key . typing_env ) ;
290
282
let ty:: FnDef ( _, args) = ty. kind ( ) else {
291
283
bug ! ( "intrinsic with type {:?}" , ty) ;
292
284
} ;
293
- return eval_nullary_intrinsic ( tcx, key. param_env , def_id, args) . report_err ( ) . map_err (
285
+ return eval_nullary_intrinsic ( tcx, key. typing_env , def_id, args) . report_err ( ) . map_err (
294
286
|error| {
295
287
let span = tcx. def_span ( def_id) ;
296
288
@@ -317,7 +309,7 @@ pub fn eval_static_initializer_provider<'tcx>(
317
309
318
310
let instance = ty:: Instance :: mono ( tcx, def_id. to_def_id ( ) ) ;
319
311
let cid = rustc_middle:: mir:: interpret:: GlobalId { instance, promoted : None } ;
320
- eval_in_interpreter ( tcx, cid, ty:: ParamEnv :: reveal_all ( ) )
312
+ eval_in_interpreter ( tcx, cid, ty:: TypingEnv :: fully_monomorphized ( ) )
321
313
}
322
314
323
315
pub trait InterpretationResult < ' tcx > {
@@ -342,16 +334,14 @@ impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> {
342
334
#[ instrument( skip( tcx) , level = "debug" ) ]
343
335
pub fn eval_to_allocation_raw_provider < ' tcx > (
344
336
tcx : TyCtxt < ' tcx > ,
345
- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
337
+ key : ty:: PseudoCanonicalInput < ' tcx , GlobalId < ' tcx > > ,
346
338
) -> :: rustc_middle:: mir:: interpret:: EvalToAllocationRawResult < ' tcx > {
347
339
// This shouldn't be used for statics, since statics are conceptually places,
348
340
// not values -- so what we do here could break pointer identity.
349
341
assert ! ( key. value. promoted. is_some( ) || !tcx. is_static( key. value. instance. def_id( ) ) ) ;
350
- // Const eval always happens in Reveal::All mode in order to be able to use the hidden types of
351
- // opaque types. This is needed for trivial things like `size_of`, but also for using associated
352
- // types that are not specified in the opaque type.
353
-
354
- assert_eq ! ( key. param_env. reveal( ) , Reveal :: All ) ;
342
+ // Const eval always happens in PostAnalysis mode . See the comment in
343
+ // `InterpCx::new` for more details.
344
+ debug_assert_eq ! ( key. typing_env. typing_mode, ty:: TypingMode :: PostAnalysis ) ;
355
345
if cfg ! ( debug_assertions) {
356
346
// Make sure we format the instance even if we do not print it.
357
347
// This serves as a regression test against an ICE on printing.
@@ -362,21 +352,21 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
362
352
trace ! ( "const eval: {:?} ({})" , key, instance) ;
363
353
}
364
354
365
- eval_in_interpreter ( tcx, key. value , key. param_env )
355
+ eval_in_interpreter ( tcx, key. value , key. typing_env )
366
356
}
367
357
368
358
fn eval_in_interpreter < ' tcx , R : InterpretationResult < ' tcx > > (
369
359
tcx : TyCtxt < ' tcx > ,
370
360
cid : GlobalId < ' tcx > ,
371
- param_env : ty:: ParamEnv < ' tcx > ,
361
+ typing_env : ty:: TypingEnv < ' tcx > ,
372
362
) -> Result < R , ErrorHandled > {
373
363
let def = cid. instance . def . def_id ( ) ;
374
364
let is_static = tcx. is_static ( def) ;
375
365
376
366
let mut ecx = InterpCx :: new (
377
367
tcx,
378
368
tcx. def_span ( def) ,
379
- param_env ,
369
+ typing_env ,
380
370
// Statics (and promoteds inside statics) may access mutable global memory, because unlike consts
381
371
// they do not have to behave "as if" they were evaluated at runtime.
382
372
// For consts however we want to ensure they behave "as if" they were evaluated at runtime,
0 commit comments