@@ -9,7 +9,7 @@ use rustc::mir;
99use rustc:: ty:: layout:: {
1010 self , Size , Align , HasDataLayout , LayoutOf , TyLayout
1111} ;
12- use rustc:: ty:: subst:: { Subst , SubstsRef } ;
12+ use rustc:: ty:: subst:: SubstsRef ;
1313use rustc:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
1414use rustc:: ty:: query:: TyCtxtAt ;
1515use rustc_data_structures:: indexed_vec:: IndexVec ;
@@ -291,41 +291,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
291291 ty. is_freeze ( * self . tcx , self . param_env , DUMMY_SP )
292292 }
293293
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-
329294 pub fn load_mir (
330295 & self ,
331296 instance : ty:: InstanceDef < ' tcx > ,
@@ -349,12 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
349314 }
350315 }
351316
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 > > (
353320 & self ,
354321 t : T ,
355322 ) -> InterpResult < ' tcx , T > {
356323 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+ ) ) ,
358329 None => if t. needs_subst ( ) {
359330 throw_inval ! ( TooGeneric )
360331 } else {
@@ -363,20 +334,21 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
363334 }
364335 }
365336
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 (
367339 & self ,
368- t : T ,
340+ def_id : DefId ,
369341 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 ( ) )
380352 }
381353
382354 pub fn layout_of_local (
@@ -391,7 +363,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
391363 None => {
392364 let layout = crate :: interpret:: operand:: from_known_layout ( layout, || {
393365 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+ ) ;
395371 self . layout_of ( local_ty)
396372 } ) ?;
397373 if let Some ( state) = frame. locals . get ( local) {
0 commit comments