@@ -9,7 +9,7 @@ use rustc::mir;
9
9
use rustc:: ty:: layout:: {
10
10
self , Size , Align , HasDataLayout , LayoutOf , TyLayout
11
11
} ;
12
- use rustc:: ty:: subst:: { Subst , SubstsRef } ;
12
+ use rustc:: ty:: subst:: SubstsRef ;
13
13
use rustc:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
14
14
use rustc:: ty:: query:: TyCtxtAt ;
15
15
use rustc_data_structures:: indexed_vec:: IndexVec ;
@@ -291,41 +291,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
291
291
ty. is_freeze ( * self . tcx , self . param_env , DUMMY_SP )
292
292
}
293
293
294
- pub ( super ) fn subst_and_normalize_erasing_regions < T : TypeFoldable < ' tcx > > (
295
- & self ,
296
- substs : T ,
297
- ) -> InterpResult < ' tcx , T > {
298
- match self . stack . last ( ) {
299
- Some ( frame) => Ok ( self . tcx . subst_and_normalize_erasing_regions (
300
- frame. instance . substs ,
301
- self . param_env ,
302
- & substs,
303
- ) ) ,
304
- None => if substs. needs_subst ( ) {
305
- throw_inval ! ( TooGeneric )
306
- } else {
307
- Ok ( substs)
308
- } ,
309
- }
310
- }
311
-
312
- pub ( super ) fn resolve (
313
- & self ,
314
- def_id : DefId ,
315
- substs : SubstsRef < ' tcx >
316
- ) -> InterpResult < ' tcx , ty:: Instance < ' tcx > > {
317
- trace ! ( "resolve: {:?}, {:#?}" , def_id, substs) ;
318
- trace ! ( "param_env: {:#?}" , self . param_env) ;
319
- let substs = self . subst_and_normalize_erasing_regions ( substs) ?;
320
- trace ! ( "substs: {:#?}" , substs) ;
321
- ty:: Instance :: resolve (
322
- * self . tcx ,
323
- self . param_env ,
324
- def_id,
325
- substs,
326
- ) . ok_or_else ( || err_inval ! ( TooGeneric ) . into ( ) )
327
- }
328
-
329
294
pub fn load_mir (
330
295
& self ,
331
296
instance : ty:: InstanceDef < ' tcx > ,
@@ -349,12 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
349
314
}
350
315
}
351
316
352
- pub ( super ) fn monomorphize < T : TypeFoldable < ' tcx > + Subst < ' tcx > > (
317
+ /// Call this on things you got out of the MIR (so it is as generic as the current
318
+ /// stack rameframe), to bring it into the proper environment for this interpreter.
319
+ pub ( super ) fn subst_from_frame_and_normalize_erasing_regions < T : TypeFoldable < ' tcx > > (
353
320
& self ,
354
321
t : T ,
355
322
) -> InterpResult < ' tcx , T > {
356
323
match self . stack . last ( ) {
357
- Some ( frame) => Ok ( self . monomorphize_with_substs ( t, frame. instance . substs ) ?) ,
324
+ Some ( frame) => Ok ( self . tcx . subst_and_normalize_erasing_regions (
325
+ frame. instance . substs ,
326
+ self . param_env ,
327
+ & t,
328
+ ) ) ,
358
329
None => if t. needs_subst ( ) {
359
330
throw_inval ! ( TooGeneric )
360
331
} else {
@@ -363,20 +334,21 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
363
334
}
364
335
}
365
336
366
- fn monomorphize_with_substs < T : TypeFoldable < ' tcx > + Subst < ' tcx > > (
337
+ /// The `substs` are assumed to already be in our interpreter "universe" (param_env).
338
+ pub ( super ) fn resolve (
367
339
& self ,
368
- t : T ,
340
+ def_id : DefId ,
369
341
substs : SubstsRef < ' tcx >
370
- ) -> InterpResult < ' tcx , T > {
371
- // miri doesn't care about lifetimes, and will choke on some crazy ones
372
- // let's simply get rid of them
373
- let substituted = t . subst ( * self . tcx , substs) ;
374
-
375
- if substituted . needs_subst ( ) {
376
- throw_inval ! ( TooGeneric )
377
- }
378
-
379
- Ok ( self . tcx . normalize_erasing_regions ( ty :: ParamEnv :: reveal_all ( ) , substituted ) )
342
+ ) -> InterpResult < ' tcx , ty :: Instance < ' tcx > > {
343
+ trace ! ( "resolve: {:?}, {:#?}" , def_id , substs ) ;
344
+ trace ! ( "param_env: {:#?}" , self . param_env ) ;
345
+ trace ! ( "substs: {:#?}" , substs) ;
346
+ ty :: Instance :: resolve (
347
+ * self . tcx ,
348
+ self . param_env ,
349
+ def_id ,
350
+ substs ,
351
+ ) . ok_or_else ( || err_inval ! ( TooGeneric ) . into ( ) )
380
352
}
381
353
382
354
pub fn layout_of_local (
@@ -391,7 +363,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
391
363
None => {
392
364
let layout = crate :: interpret:: operand:: from_known_layout ( layout, || {
393
365
let local_ty = frame. body . local_decls [ local] . ty ;
394
- let local_ty = self . monomorphize_with_substs ( local_ty, frame. instance . substs ) ?;
366
+ let local_ty = self . tcx . subst_and_normalize_erasing_regions (
367
+ frame. instance . substs ,
368
+ self . param_env ,
369
+ & local_ty,
370
+ ) ;
395
371
self . layout_of ( local_ty)
396
372
} ) ?;
397
373
if let Some ( state) = frame. locals . get ( local) {
0 commit comments