@@ -18,8 +18,8 @@ use session::EarlyDiagCtxt;
1818use std:: env;
1919use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
2020use std:: path:: { Path , PathBuf } ;
21- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
22- use std:: sync:: OnceLock ;
21+ use std:: sync:: atomic:: { AtomicBool , AtomicPtr , Ordering } ;
22+ use std:: sync:: { Arc , OnceLock } ;
2323use std:: thread;
2424
2525/// Function pointer type that constructs a new CodegenBackend.
@@ -90,6 +90,7 @@ pub(crate) fn run_in_thread_with_globals<F: FnOnce() -> R + Send, R: Send>(
9090pub ( crate ) fn run_in_thread_pool_with_globals < F : FnOnce ( ) -> R + Send , R : Send > (
9191 edition : Edition ,
9292 _threads : usize ,
93+ _compiler : Arc < AtomicPtr < ( ) > > ,
9394 f : F ,
9495) -> R {
9596 run_in_thread_with_globals ( edition, f)
@@ -99,10 +100,11 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
99100pub ( crate ) fn run_in_thread_pool_with_globals < F : FnOnce ( ) -> R + Send , R : Send > (
100101 edition : Edition ,
101102 threads : usize ,
103+ compiler : Arc < AtomicPtr < ( ) > > ,
102104 f : F ,
103105) -> R {
104106 use rustc_data_structures:: { jobserver, sync:: FromDyn } ;
105- use rustc_middle:: ty:: tls ;
107+ use rustc_middle:: ty:: GlobalCtxt ;
106108 use rustc_query_impl:: QueryCtxt ;
107109 use rustc_query_system:: query:: { deadlock, QueryContext } ;
108110
@@ -122,11 +124,15 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
122124 . acquire_thread_handler ( jobserver:: acquire_thread)
123125 . release_thread_handler ( jobserver:: release_thread)
124126 . num_threads ( threads)
125- . deadlock_handler ( || {
127+ . deadlock_handler ( move || {
128+ let compiler = compiler. load ( Ordering :: Relaxed ) ;
129+ assert ! ( !compiler. is_null( ) ) ;
130+ let compiler = compiler as * const GlobalCtxt < ' _ > ;
126131 // On deadlock, creates a new thread and forwards information in thread
127132 // locals to it. The new thread runs the deadlock handler.
128- let query_map =
129- FromDyn :: from ( tls:: with ( |tcx| QueryCtxt :: new ( tcx) . collect_active_jobs ( ) ) ) ;
133+ let query_map = FromDyn :: from ( unsafe {
134+ ( * compiler) . enter ( |tcx| QueryCtxt :: new ( tcx) . collect_active_jobs ( ) )
135+ } ) ;
130136 let registry = rayon_core:: Registry :: current ( ) ;
131137 thread:: spawn ( move || deadlock ( query_map. into_inner ( ) , & registry) ) ;
132138 } ) ;
0 commit comments