@@ -11,7 +11,6 @@ use log::trace;
11
11
use rustc_data_structures:: fx:: FxHashMap ;
12
12
use rustc_hir:: def_id:: DefId ;
13
13
use rustc_index:: vec:: { Idx , IndexVec } ;
14
- use rustc_middle:: ty:: { self , Instance } ;
15
14
16
15
use crate :: sync:: SynchronizationState ;
17
16
use crate :: * ;
@@ -497,9 +496,6 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mi
497
496
pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
498
497
/// Get a thread-specific allocation id for the given thread-local static.
499
498
/// If needed, allocate a new one.
500
- ///
501
- /// FIXME: This method should be replaced as soon as
502
- /// https://github.com/rust-lang/rust/issues/70685 gets fixed.
503
499
fn get_or_create_thread_local_alloc_id ( & self , def_id : DefId ) -> InterpResult < ' tcx , AllocId > {
504
500
let this = self . eval_context_ref ( ) ;
505
501
let tcx = this. tcx ;
@@ -511,29 +507,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
511
507
// We need to allocate a thread-specific allocation id for this
512
508
// thread-local static.
513
509
//
514
- // At first, we invoke the `const_eval_raw` query and extract the
515
- // allocation from it. Unfortunately, we have to duplicate the code
516
- // from `Memory::get_global_alloc` that does this.
517
- //
510
+ // At first, we compute the initial value for this static.
518
511
// Then we store the retrieved allocation back into the `alloc_map`
519
512
// to get a fresh allocation id, which we can use as a
520
513
// thread-specific allocation id for the thread-local static.
514
+ // On first access to that allocation, it will be copied over to the machine memory.
521
515
if tcx. is_foreign_item ( def_id) {
522
516
throw_unsup_format ! ( "foreign thread-local statics are not supported" ) ;
523
517
}
524
- // Invoke the `const_eval_raw` query.
525
- let instance = Instance :: mono ( tcx. tcx , def_id) ;
526
- let gid = GlobalId { instance, promoted : None } ;
527
- let raw_const =
528
- tcx. const_eval_raw ( ty:: ParamEnv :: reveal_all ( ) . and ( gid) ) . map_err ( |err| {
529
- // no need to report anything, the const_eval call takes care of that
530
- // for statics
531
- assert ! ( tcx. is_static( def_id) ) ;
532
- err
533
- } ) ?;
534
- let id = raw_const. alloc_id ;
535
- // Extract the allocation from the query result.
536
- let allocation = tcx. global_alloc ( id) . unwrap_memory ( ) ;
518
+ let allocation = interpret:: get_static ( * tcx, def_id) ?;
537
519
// Create a new allocation id for the same allocation in this hacky
538
520
// way. Internally, `alloc_map` deduplicates allocations, but this
539
521
// is fine because Miri will make a copy before a first mutable
0 commit comments