@@ -6,10 +6,12 @@ use std::{env, iter, thread};
66
77use rustc_ast as ast;
88use rustc_codegen_ssa:: traits:: CodegenBackend ;
9+ use rustc_data_structures:: fx:: FxHashMap ;
910use rustc_data_structures:: sync;
1011use rustc_metadata:: { DylibError , load_symbol_from_dylib} ;
1112use rustc_middle:: ty:: CurrentGcx ;
1213use rustc_parse:: validate_attr;
14+ use rustc_query_system:: query:: { QueryJobId , QueryJobInfo , QueryStackDeferred } ;
1315use rustc_session:: config:: { Cfg , OutFileName , OutputFilenames , OutputTypes , host_tuple} ;
1416use rustc_session:: filesearch:: sysroot_candidates;
1517use rustc_session:: lint:: { self , BuiltinLintDiag , LintBuffer } ;
@@ -18,7 +20,7 @@ use rustc_session::{EarlyDiagCtxt, Session, filesearch};
1820use rustc_span:: edit_distance:: find_best_match_for_name;
1921use rustc_span:: edition:: Edition ;
2022use rustc_span:: source_map:: SourceMapInputs ;
21- use rustc_span:: { SessionGlobals , Symbol , sym} ;
23+ use rustc_span:: { Symbol , sym} ;
2224use rustc_target:: spec:: Target ;
2325use tracing:: info;
2426
@@ -188,11 +190,26 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
188190 // On deadlock, creates a new thread and forwards information in thread
189191 // locals to it. The new thread runs the deadlock handler.
190192
191- let current_gcx2 = current_gcx2. clone ( ) ;
192- let registry = rayon_core:: Registry :: current ( ) ;
193- let session_globals = rustc_span:: with_session_globals ( |session_globals| {
194- session_globals as * const SessionGlobals as usize
193+ // Get a `GlobalCtxt` reference from `CurrentGcx` as we cannot rely on having a
194+ // `TyCtxt` TLS reference here.
195+ let query_map = current_gcx2. access ( |gcx| {
196+ tls:: enter_context ( & tls:: ImplicitCtxt :: new ( gcx) , || {
197+ tls:: with ( |tcx| {
198+ let ( query_map, complete) = QueryCtxt :: new ( tcx) . collect_active_jobs ( ) ;
199+ if !complete {
200+ // There was an unexpected error collecting all active jobs, which we need
201+ // to find cycles to break.
202+ // We want to avoid panicking in the deadlock handler, so we abort instead.
203+ eprintln ! ( "internal compiler error: failed to get query map in deadlock handler, aborting process" ) ;
204+ process:: abort ( ) ;
205+ }
206+ let query_map: FxHashMap < QueryJobId , QueryJobInfo < QueryStackDeferred < ' static > > > = unsafe { std:: mem:: transmute ( query_map) } ;
207+ query_map
208+ } )
209+ } )
195210 } ) ;
211+ let query_map = FromDyn :: from ( query_map) ;
212+ let registry = rayon_core:: Registry :: current ( ) ;
196213 thread:: Builder :: new ( )
197214 . name ( "rustc query cycle handler" . to_string ( ) )
198215 . spawn ( move || {
@@ -202,26 +219,8 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
202219 // otherwise the compiler could just hang,
203220 process:: abort ( ) ;
204221 } ) ;
205-
206- // Get a `GlobalCtxt` reference from `CurrentGcx` as we cannot rely on having a
207- // `TyCtxt` TLS reference here.
208- current_gcx2. access ( |gcx| {
209- tls:: enter_context ( & tls:: ImplicitCtxt :: new ( gcx) , || {
210- tls:: with ( |tcx| {
211- let ( query_map, complete) = rustc_span:: set_session_globals_then ( unsafe { & * ( session_globals as * const SessionGlobals ) } , || {
212- QueryCtxt :: new ( tcx) . collect_active_jobs ( )
213- } ) ;
214- if !complete {
215- // There was an unexpected error collecting all active jobs, which we need
216- // to find cycles to break.
217- // We want to avoid panicking in the deadlock handler, so we abort instead.
218- panic ! ( "failed to get query map in deadlock handler, aborting process" ) ;
219- }
220- break_query_cycles ( query_map, & registry) ;
221- } )
222- } )
223- } ) ;
224-
222+ let query_map: FxHashMap < QueryJobId , QueryJobInfo < QueryStackDeferred < ' _ > > > = unsafe { std:: mem:: transmute ( query_map. into_inner ( ) ) } ;
223+ break_query_cycles ( query_map, & registry) ;
225224 on_panic. disable ( ) ;
226225 } )
227226 . unwrap ( ) ;
0 commit comments