@@ -6,10 +6,12 @@ use std::{env, iter, thread};
6
6
7
7
use rustc_ast as ast;
8
8
use rustc_codegen_ssa:: traits:: CodegenBackend ;
9
+ use rustc_data_structures:: fx:: FxHashMap ;
9
10
use rustc_data_structures:: sync;
10
11
use rustc_metadata:: { DylibError , load_symbol_from_dylib} ;
11
12
use rustc_middle:: ty:: CurrentGcx ;
12
13
use rustc_parse:: validate_attr;
14
+ use rustc_query_system:: query:: { QueryJobId , QueryJobInfo , QueryStackDeferred } ;
13
15
use rustc_session:: config:: { Cfg , OutFileName , OutputFilenames , OutputTypes , host_tuple} ;
14
16
use rustc_session:: filesearch:: sysroot_candidates;
15
17
use rustc_session:: lint:: { self , BuiltinLintDiag , LintBuffer } ;
@@ -18,7 +20,7 @@ use rustc_session::{EarlyDiagCtxt, Session, filesearch};
18
20
use rustc_span:: edit_distance:: find_best_match_for_name;
19
21
use rustc_span:: edition:: Edition ;
20
22
use rustc_span:: source_map:: SourceMapInputs ;
21
- use rustc_span:: { SessionGlobals , Symbol , sym} ;
23
+ use rustc_span:: { Symbol , sym} ;
22
24
use rustc_target:: spec:: Target ;
23
25
use tracing:: info;
24
26
@@ -188,11 +190,26 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
188
190
// On deadlock, creates a new thread and forwards information in thread
189
191
// locals to it. The new thread runs the deadlock handler.
190
192
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
+ } )
195
210
} ) ;
211
+ let query_map = FromDyn :: from ( query_map) ;
212
+ let registry = rayon_core:: Registry :: current ( ) ;
196
213
thread:: Builder :: new ( )
197
214
. name ( "rustc query cycle handler" . to_string ( ) )
198
215
. spawn ( move || {
@@ -202,26 +219,8 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
202
219
// otherwise the compiler could just hang,
203
220
process:: abort ( ) ;
204
221
} ) ;
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) ;
225
224
on_panic. disable ( ) ;
226
225
} )
227
226
. unwrap ( ) ;
0 commit comments