@@ -7,7 +7,6 @@ use rustc_middle::bug;
77use rustc_middle:: mir:: interpret:: { AllocId , ErrorHandled , InterpErrorInfo } ;
88use rustc_middle:: mir:: { self , ConstAlloc , ConstValue } ;
99use rustc_middle:: query:: TyCtxtAt ;
10- use rustc_middle:: traits:: Reveal ;
1110use rustc_middle:: ty:: layout:: LayoutOf ;
1211use rustc_middle:: ty:: print:: with_no_trimmed_paths;
1312use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
@@ -31,7 +30,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
3130 cid : GlobalId < ' tcx > ,
3231 body : & ' tcx mir:: Body < ' tcx > ,
3332) -> InterpResult < ' tcx , R > {
34- trace ! ( ?ecx. param_env ) ;
33+ trace ! ( ?ecx. typing_env ) ;
3534 let tcx = * ecx. tcx ;
3635 assert ! (
3736 cid. promoted. is_some( )
@@ -126,14 +125,14 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
126125pub ( crate ) fn mk_eval_cx_to_read_const_val < ' tcx > (
127126 tcx : TyCtxt < ' tcx > ,
128127 root_span : Span ,
129- param_env : ty:: ParamEnv < ' tcx > ,
128+ typing_env : ty:: TypingEnv < ' tcx > ,
130129 can_access_mut_global : CanAccessMutGlobal ,
131130) -> CompileTimeInterpCx < ' tcx > {
132- debug ! ( "mk_eval_cx: {:?}" , param_env ) ;
131+ debug ! ( "mk_eval_cx: {:?}" , typing_env ) ;
133132 InterpCx :: new (
134133 tcx,
135134 root_span,
136- param_env ,
135+ typing_env ,
137136 CompileTimeMachine :: new ( can_access_mut_global, CheckAlignment :: No ) ,
138137 )
139138}
@@ -142,11 +141,11 @@ pub(crate) fn mk_eval_cx_to_read_const_val<'tcx>(
142141/// Returns both the context and an `OpTy` that represents the constant.
143142pub fn mk_eval_cx_for_const_val < ' tcx > (
144143 tcx : TyCtxtAt < ' tcx > ,
145- param_env : ty:: ParamEnv < ' tcx > ,
144+ typing_env : ty:: TypingEnv < ' tcx > ,
146145 val : mir:: ConstValue < ' tcx > ,
147146 ty : Ty < ' tcx > ,
148147) -> 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 ) ;
150149 // FIXME: is it a problem to discard the error here?
151150 let op = ecx. const_val_to_op ( val, ty, None ) . discard_err ( ) ?;
152151 Some ( ( ecx, op) )
@@ -221,7 +220,7 @@ pub(super) fn op_to_const<'tcx>(
221220 let pointee_ty = imm. layout . ty . builtin_deref ( false ) . unwrap ( ) ; // `false` = no raw ptrs
222221 debug_assert ! (
223222 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( ) ,
225224 ty:: Str | ty:: Slice ( ..) ,
226225 ) ,
227226 "`ConstValue::Slice` is for slice-tailed types only, but got {}" ,
@@ -245,7 +244,7 @@ pub(super) fn op_to_const<'tcx>(
245244pub ( crate ) fn turn_into_const_value < ' tcx > (
246245 tcx : TyCtxt < ' tcx > ,
247246 constant : ConstAlloc < ' tcx > ,
248- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
247+ key : ty:: PseudoCanonicalInput < ' tcx , GlobalId < ' tcx > > ,
249248) -> ConstValue < ' tcx > {
250249 let cid = key. value ;
251250 let def_id = cid. instance . def . def_id ( ) ;
@@ -254,7 +253,7 @@ pub(crate) fn turn_into_const_value<'tcx>(
254253 let ecx = mk_eval_cx_to_read_const_val (
255254 tcx,
256255 tcx. def_span ( key. value . instance . def_id ( ) ) ,
257- key. param_env ,
256+ key. typing_env ,
258257 CanAccessMutGlobal :: from ( is_static) ,
259258 ) ;
260259
@@ -274,23 +273,16 @@ pub(crate) fn turn_into_const_value<'tcx>(
274273#[ instrument( skip( tcx) , level = "debug" ) ]
275274pub fn eval_to_const_value_raw_provider < ' tcx > (
276275 tcx : TyCtxt < ' tcx > ,
277- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
276+ key : ty:: PseudoCanonicalInput < ' tcx , GlobalId < ' tcx > > ,
278277) -> :: 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-
286278 // We call `const_eval` for zero arg intrinsics, too, in order to cache their value.
287279 // Catch such calls and evaluate them instead of trying to load a constant's MIR.
288280 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 ) ;
290282 let ty:: FnDef ( _, args) = ty. kind ( ) else {
291283 bug ! ( "intrinsic with type {:?}" , ty) ;
292284 } ;
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 (
294286 |error| {
295287 let span = tcx. def_span ( def_id) ;
296288
@@ -317,7 +309,7 @@ pub fn eval_static_initializer_provider<'tcx>(
317309
318310 let instance = ty:: Instance :: mono ( tcx, def_id. to_def_id ( ) ) ;
319311 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 ( ) )
321313}
322314
323315pub trait InterpretationResult < ' tcx > {
@@ -342,16 +334,14 @@ impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> {
342334#[ instrument( skip( tcx) , level = "debug" ) ]
343335pub fn eval_to_allocation_raw_provider < ' tcx > (
344336 tcx : TyCtxt < ' tcx > ,
345- key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
337+ key : ty:: PseudoCanonicalInput < ' tcx , GlobalId < ' tcx > > ,
346338) -> :: rustc_middle:: mir:: interpret:: EvalToAllocationRawResult < ' tcx > {
347339 // This shouldn't be used for statics, since statics are conceptually places,
348340 // not values -- so what we do here could break pointer identity.
349341 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 ) ;
355345 if cfg ! ( debug_assertions) {
356346 // Make sure we format the instance even if we do not print it.
357347 // This serves as a regression test against an ICE on printing.
@@ -362,21 +352,21 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
362352 trace ! ( "const eval: {:?} ({})" , key, instance) ;
363353 }
364354
365- eval_in_interpreter ( tcx, key. value , key. param_env )
355+ eval_in_interpreter ( tcx, key. value , key. typing_env )
366356}
367357
368358fn eval_in_interpreter < ' tcx , R : InterpretationResult < ' tcx > > (
369359 tcx : TyCtxt < ' tcx > ,
370360 cid : GlobalId < ' tcx > ,
371- param_env : ty:: ParamEnv < ' tcx > ,
361+ typing_env : ty:: TypingEnv < ' tcx > ,
372362) -> Result < R , ErrorHandled > {
373363 let def = cid. instance . def . def_id ( ) ;
374364 let is_static = tcx. is_static ( def) ;
375365
376366 let mut ecx = InterpCx :: new (
377367 tcx,
378368 tcx. def_span ( def) ,
379- param_env ,
369+ typing_env ,
380370 // Statics (and promoteds inside statics) may access mutable global memory, because unlike consts
381371 // they do not have to behave "as if" they were evaluated at runtime.
382372 // For consts however we want to ensure they behave "as if" they were evaluated at runtime,
0 commit comments