@@ -210,7 +210,7 @@ pub struct MemoryData<'tcx> {
210
210
/// The entry is created when allocating the memory and deleted after deallocation.
211
211
locks : HashMap < AllocId , RangeMap < LockInfo < ' tcx > > > ,
212
212
213
- mut_statics : HashMap < GlobalId < ' tcx > , AllocId > ,
213
+ statics : HashMap < GlobalId < ' tcx > , AllocId > ,
214
214
}
215
215
216
216
impl < ' mir , ' tcx : ' mir > Machine < ' mir , ' tcx > for Evaluator < ' tcx > {
@@ -252,25 +252,24 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
252
252
}
253
253
254
254
fn mark_static_initialized < ' a > (
255
- _mem : & mut Memory < ' a , ' mir , ' tcx , Self > ,
256
- _id : AllocId ,
255
+ mem : & mut Memory < ' a , ' mir , ' tcx , Self > ,
256
+ id : AllocId ,
257
257
_mutability : Mutability ,
258
258
) -> EvalResult < ' tcx , bool > {
259
- /* use memory::MemoryKind::*;
260
- match m {
259
+ use memory:: MemoryKind :: * ;
260
+ match mem . get_alloc_kind ( id ) {
261
261
// FIXME: This could be allowed, but not for env vars set during miri execution
262
- Env => err!(Unimplemented("statics can't refer to env vars".to_owned())),
262
+ Some ( MemoryKind :: Machine ( Env ) ) => err ! ( Unimplemented ( "statics can't refer to env vars" . to_owned( ) ) ) ,
263
263
_ => Ok ( false ) , // TODO: What does the bool mean?
264
- }*/
265
- Ok ( false )
264
+ }
266
265
}
267
266
268
267
fn init_static < ' a > (
269
268
ecx : & mut EvalContext < ' a , ' mir , ' tcx , Self > ,
270
269
cid : GlobalId < ' tcx > ,
271
270
) -> EvalResult < ' tcx , AllocId > {
272
271
// Step 1: If the static has already been evaluated return the cached version
273
- if let Some ( alloc_id) = ecx. memory . data . mut_statics . get ( & cid) {
272
+ if let Some ( alloc_id) = ecx. memory . data . statics . get ( & cid) {
274
273
return Ok ( * alloc_id) ;
275
274
}
276
275
@@ -293,7 +292,7 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
293
292
) ?;
294
293
295
294
// Step 4: Cache allocation id for recursive statics
296
- assert ! ( ecx. memory. data. mut_statics . insert( cid, ptr. alloc_id) . is_none( ) ) ;
295
+ assert ! ( ecx. memory. data. statics . insert( cid, ptr. alloc_id) . is_none( ) ) ;
297
296
298
297
// Step 5: Push stackframe to evaluate static
299
298
let cleanup = StackPopCleanup :: None ;
@@ -325,6 +324,8 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
325
324
}
326
325
}
327
326
327
+ // TODO: Freeze immutable statics without copying them to the global static cache
328
+
328
329
// Step 7: Return the alloc
329
330
Ok ( ptr. alloc_id )
330
331
}
0 commit comments