@@ -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,34 +314,34 @@ 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 frame), 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 , 
354-         t :  T , 
355-     )  -> InterpResult < ' tcx ,  T >  { 
356-         match  self . stack . last ( )  { 
357-             Some ( frame)  => Ok ( self . monomorphize_with_substs ( t,  frame. instance . substs ) ?) , 
358-             None  => if  t. needs_subst ( )  { 
359-                 throw_inval ! ( TooGeneric ) 
360-             }  else  { 
361-                 Ok ( t) 
362-             } , 
363-         } 
321+         value :  T , 
322+     )  -> T  { 
323+         self . tcx . subst_and_normalize_erasing_regions ( 
324+             self . frame ( ) . instance . substs , 
325+             self . param_env , 
326+             & value, 
327+         ) 
364328    } 
365329
366-     fn  monomorphize_with_substs < T :  TypeFoldable < ' tcx >  + Subst < ' tcx > > ( 
330+     /// The `substs` are assumed to already be in our interpreter "universe" (param_env). 
331+      pub ( super )  fn  resolve ( 
367332        & self , 
368-         t :   T , 
333+         def_id :   DefId , 
369334        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 ) ) 
335+     )  -> InterpResult < ' tcx ,  ty :: Instance < ' tcx > >  { 
336+         trace ! ( "resolve: {:?}, {:#?}" ,  def_id ,  substs ) ; 
337+         trace ! ( "param_env: {:#?}" ,   self . param_env ) ; 
338+         trace ! ( "substs: {:#?}" ,  substs) ; 
339+         ty :: Instance :: resolve ( 
340+              * self . tcx , 
341+             self . param_env , 
342+             def_id , 
343+             substs , 
344+         ) . ok_or_else ( ||  err_inval ! ( TooGeneric ) . into ( ) ) 
380345    } 
381346
382347    pub  fn  layout_of_local ( 
@@ -391,7 +356,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
391356            None  => { 
392357                let  layout = crate :: interpret:: operand:: from_known_layout ( layout,  || { 
393358                    let  local_ty = frame. body . local_decls [ local] . ty ; 
394-                     let  local_ty = self . monomorphize_with_substs ( local_ty,  frame. instance . substs ) ?; 
359+                     let  local_ty = self . tcx . subst_and_normalize_erasing_regions ( 
360+                         frame. instance . substs , 
361+                         self . param_env , 
362+                         & local_ty, 
363+                     ) ; 
395364                    self . layout_of ( local_ty) 
396365                } ) ?; 
397366                if  let  Some ( state)  = frame. locals . get ( local)  { 
0 commit comments