@@ -29,7 +29,7 @@ use rand::rngs::StdRng;
29
29
use rand:: SeedableRng ;
30
30
31
31
use rustc_target:: spec:: PanicStrategy ;
32
- use rustc:: ty:: { ExistentialPredicate , ExistentialTraitRef , RegionKind , List } ;
32
+ use rustc:: ty:: { ExistentialPredicate , ExistentialTraitRef , RegionKind , List , ParamEnv } ;
33
33
use rustc:: ty:: { self , TyCtxt , query:: TyCtxtAt } ;
34
34
use rustc:: ty:: layout:: { LayoutOf , Size , Align , TyLayout } ;
35
35
use rustc:: hir:: { self , def_id:: DefId } ;
@@ -72,16 +72,40 @@ pub struct MiriConfig {
72
72
pub seed : Option < u64 > ,
73
73
}
74
74
75
+
75
76
// Used by priroda.
76
77
pub fn create_ecx < ' a , ' mir : ' a , ' tcx : ' mir > (
77
78
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
78
79
main_id : DefId ,
79
80
config : MiriConfig ,
80
81
) -> 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
+
81
105
let mut ecx = InterpretCx :: new (
82
106
tcx. at ( syntax:: source_map:: DUMMY_SP ) ,
83
107
ty:: ParamEnv :: reveal_all ( ) ,
84
- Evaluator :: new ( config. validate , config. seed ) ,
108
+ Evaluator :: new ( config. validate , config. seed , cached_types ) ,
85
109
) ;
86
110
87
111
let main_instance = ty:: Instance :: mono ( ecx. tcx . tcx , main_id) ;
@@ -211,25 +235,6 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
211
235
// Cache some data used by unwinding
212
236
if ecx. tcx . tcx . sess . panic_strategy ( ) == PanicStrategy :: Unwind {
213
237
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
- } ) ;
233
238
}
234
239
235
240
assert ! ( args. next( ) . is_none( ) , "start lang item has more arguments than expected" ) ;
@@ -374,8 +379,10 @@ pub struct Evaluator<'tcx> {
374
379
pub ( crate ) rng : Option < StdRng > ,
375
380
376
381
/// 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 > ,
379
386
380
387
/// Whether or not we are currently unwinding from
381
388
/// a panic
@@ -389,7 +396,7 @@ pub struct CachedTypes<'tcx> {
389
396
}
390
397
391
398
impl < ' 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 {
393
400
Evaluator {
394
401
env_vars : HashMap :: default ( ) ,
395
402
argc : None ,
@@ -399,7 +406,7 @@ impl<'tcx> Evaluator<'tcx> {
399
406
tls : TlsData :: default ( ) ,
400
407
validate,
401
408
rng : seed. map ( |s| StdRng :: seed_from_u64 ( s) ) ,
402
- cached_data : None ,
409
+ cached_data,
403
410
unwinding : false ,
404
411
box_me_up_tmp_ptr : None
405
412
}
0 commit comments