@@ -11,7 +11,6 @@ use log::trace;
1111use rustc_data_structures:: fx:: FxHashMap ;
1212use rustc_hir:: def_id:: DefId ;
1313use rustc_index:: vec:: { Idx , IndexVec } ;
14- use rustc_middle:: ty:: { self , Instance } ;
1514
1615use crate :: sync:: SynchronizationState ;
1716use crate :: * ;
@@ -497,9 +496,6 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mi
497496pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
498497 /// Get a thread-specific allocation id for the given thread-local static.
499498 /// 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.
503499 fn get_or_create_thread_local_alloc_id ( & self , def_id : DefId ) -> InterpResult < ' tcx , AllocId > {
504500 let this = self . eval_context_ref ( ) ;
505501 let tcx = this. tcx ;
@@ -511,29 +507,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
511507 // We need to allocate a thread-specific allocation id for this
512508 // thread-local static.
513509 //
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.
518511 // Then we store the retrieved allocation back into the `alloc_map`
519512 // to get a fresh allocation id, which we can use as a
520513 // 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.
521515 if tcx. is_foreign_item ( def_id) {
522516 throw_unsup_format ! ( "foreign thread-local statics are not supported" ) ;
523517 }
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) ?;
537519 // Create a new allocation id for the same allocation in this hacky
538520 // way. Internally, `alloc_map` deduplicates allocations, but this
539521 // is fine because Miri will make a copy before a first mutable
0 commit comments