@@ -29,7 +29,7 @@ use rand::rngs::StdRng;
2929use rand:: SeedableRng ;
3030
3131use rustc_target:: spec:: PanicStrategy ;
32- use rustc:: ty:: { ExistentialPredicate , ExistentialTraitRef , RegionKind , List } ;
32+ use rustc:: ty:: { ExistentialPredicate , ExistentialTraitRef , RegionKind , List , ParamEnv } ;
3333use rustc:: ty:: { self , TyCtxt , query:: TyCtxtAt } ;
3434use rustc:: ty:: layout:: { LayoutOf , Size , Align , TyLayout } ;
3535use rustc:: hir:: { self , def_id:: DefId } ;
@@ -72,16 +72,40 @@ pub struct MiriConfig {
7272 pub seed : Option < u64 > ,
7373}
7474
75+
7576// Used by priroda.
7677pub fn create_ecx < ' a , ' mir : ' a , ' tcx : ' mir > (
7778 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
7879 main_id : DefId ,
7980 config : MiriConfig ,
8081) -> EvalResult < ' tcx , InterpretCx < ' a , ' mir , ' tcx , Evaluator < ' tcx > > > {
82+
83+
84+ // We build up the layout of '*mut &mut dyn core::panic::BoxMeUp'
85+ let box_me_up_did = helpers:: resolve_did ( tcx, & [ "core" , "panic" , "BoxMeUp" ] ) ?;
86+ let traits = & [ ExistentialPredicate :: Trait ( ExistentialTraitRef {
87+ def_id : box_me_up_did,
88+ substs : List :: empty ( )
89+ } ) ] ;
90+
91+ let me_mut_dyn = tcx. mk_dynamic (
92+ ty:: Binder :: dummy ( tcx. intern_existential_predicates ( traits) ) ,
93+ & RegionKind :: ReErased
94+ ) ;
95+
96+ let me_mut_ref = tcx. mk_mut_ref ( & RegionKind :: ReErased , me_mut_dyn) ;
97+ let me_mut_raw = tcx. mk_mut_ptr ( me_mut_ref) ;
98+ let box_me_up_layout = tcx. layout_of ( ParamEnv :: empty ( ) . and ( me_mut_raw) )
99+ . map_err ( |layout| InterpError :: Layout ( layout) ) ?;
100+
101+ let cached_types = CachedTypes {
102+ box_me_up_layout
103+ } ;
104+
81105 let mut ecx = InterpretCx :: new (
82106 tcx. at ( syntax:: source_map:: DUMMY_SP ) ,
83107 ty:: ParamEnv :: reveal_all ( ) ,
84- Evaluator :: new ( config. validate , config. seed ) ,
108+ Evaluator :: new ( config. validate , config. seed , cached_types ) ,
85109 ) ;
86110
87111 let main_instance = ty:: Instance :: mono ( ecx. tcx . tcx , main_id) ;
@@ -211,25 +235,6 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
211235 // Cache some data used by unwinding
212236 if ecx. tcx . tcx . sess . panic_strategy ( ) == PanicStrategy :: Unwind {
213237
214- // We build up the layout of '*mut &mut dyn core::panic::BoxMeUp'
215- let box_me_up_did = ecx. resolve_did ( & [ "core" , "panic" , "BoxMeUp" ] ) ?;
216- let traits = & [ ExistentialPredicate :: Trait ( ExistentialTraitRef {
217- def_id : box_me_up_did,
218- substs : List :: empty ( )
219- } ) ] ;
220-
221- let me_mut_dyn = ecx. tcx . tcx . mk_dynamic (
222- ty:: Binder :: dummy ( ecx. tcx . tcx . intern_existential_predicates ( traits) ) ,
223- & RegionKind :: ReErased
224- ) ;
225-
226- let me_mut_ref = ecx. tcx . tcx . mk_mut_ref ( & RegionKind :: ReErased , me_mut_dyn) ;
227- let me_mut_raw = ecx. tcx . tcx . mk_mut_ptr ( me_mut_ref) ;
228- let box_me_up_layout = ecx. layout_of ( me_mut_raw) ?;
229-
230- ecx. machine . cached_data = Some ( CachedTypes {
231- box_me_up_layout
232- } ) ;
233238 }
234239
235240 assert ! ( args. next( ) . is_none( ) , "start lang item has more arguments than expected" ) ;
@@ -374,8 +379,10 @@ pub struct Evaluator<'tcx> {
374379 pub ( crate ) rng : Option < StdRng > ,
375380
376381 /// Extra information needed for unwinding
377- /// This is 'None' when we're running in abort mode
378- pub ( crate ) cached_data : Option < CachedTypes < ' tcx > > ,
382+ /// We create this even in abort mode, so
383+ /// that we can perform some basic validation
384+ /// during panics
385+ pub ( crate ) cached_data : CachedTypes < ' tcx > ,
379386
380387 /// Whether or not we are currently unwinding from
381388 /// a panic
@@ -389,7 +396,7 @@ pub struct CachedTypes<'tcx> {
389396}
390397
391398impl < ' tcx > Evaluator < ' tcx > {
392- fn new ( validate : bool , seed : Option < u64 > ) -> Self {
399+ fn new ( validate : bool , seed : Option < u64 > , cached_data : CachedTypes < ' tcx > ) -> Self {
393400 Evaluator {
394401 env_vars : HashMap :: default ( ) ,
395402 argc : None ,
@@ -399,7 +406,7 @@ impl<'tcx> Evaluator<'tcx> {
399406 tls : TlsData :: default ( ) ,
400407 validate,
401408 rng : seed. map ( |s| StdRng :: seed_from_u64 ( s) ) ,
402- cached_data : None ,
409+ cached_data,
403410 unwinding : false ,
404411 box_me_up_tmp_ptr : None
405412 }
0 commit comments