@@ -5,7 +5,6 @@ use rustc::session::CrateDisambiguator;
5
5
use rustc:: ty;
6
6
use rustc:: lint;
7
7
use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
8
- #[ cfg( parallel_compiler) ]
9
8
use rustc_data_structures:: jobserver;
10
9
use rustc_data_structures:: sync:: { Lock , Lrc } ;
11
10
use rustc_data_structures:: stable_hasher:: StableHasher ;
@@ -38,8 +37,6 @@ use syntax::util::lev_distance::find_best_match_for_name;
38
37
use syntax:: source_map:: { FileLoader , RealFileLoader , SourceMap } ;
39
38
use syntax:: symbol:: Symbol ;
40
39
use syntax:: { self , ast, attr} ;
41
- #[ cfg( not( parallel_compiler) ) ]
42
- use std:: { thread, panic} ;
43
40
44
41
pub fn diagnostics_registry ( ) -> Registry {
45
42
let mut all_errors = Vec :: new ( ) ;
@@ -140,54 +137,6 @@ impl Write for Sink {
140
137
fn flush ( & mut self ) -> io:: Result < ( ) > { Ok ( ( ) ) }
141
138
}
142
139
143
- #[ cfg( not( parallel_compiler) ) ]
144
- pub fn scoped_thread < F : FnOnce ( ) -> R + Send , R : Send > ( cfg : thread:: Builder , f : F ) -> R {
145
- struct Ptr ( * mut ( ) ) ;
146
- unsafe impl Send for Ptr { }
147
- unsafe impl Sync for Ptr { }
148
-
149
- let mut f = Some ( f) ;
150
- let run = Ptr ( & mut f as * mut _ as * mut ( ) ) ;
151
- let mut result = None ;
152
- let result_ptr = Ptr ( & mut result as * mut _ as * mut ( ) ) ;
153
-
154
- let thread = cfg. spawn ( move || {
155
- let run = unsafe { ( * ( run. 0 as * mut Option < F > ) ) . take ( ) . unwrap ( ) } ;
156
- let result = unsafe { & mut * ( result_ptr. 0 as * mut Option < R > ) } ;
157
- * result = Some ( run ( ) ) ;
158
- } ) ;
159
-
160
- match thread. unwrap ( ) . join ( ) {
161
- Ok ( ( ) ) => result. unwrap ( ) ,
162
- Err ( p) => panic:: resume_unwind ( p) ,
163
- }
164
- }
165
-
166
- #[ cfg( not( parallel_compiler) ) ]
167
- pub fn spawn_thread_pool < F : FnOnce ( ) -> R + Send , R : Send > (
168
- _threads : Option < usize > ,
169
- stderr : & Option < Arc < Mutex < Vec < u8 > > > > ,
170
- f : F ,
171
- ) -> R {
172
- let mut cfg = thread:: Builder :: new ( ) . name ( "rustc" . to_string ( ) ) ;
173
-
174
- if let Some ( size) = get_stack_size ( ) {
175
- cfg = cfg. stack_size ( size) ;
176
- }
177
-
178
- scoped_thread ( cfg, || {
179
- syntax:: with_globals ( || {
180
- ty:: tls:: GCX_PTR . set ( & Lock :: new ( 0 ) , || {
181
- if let Some ( stderr) = stderr {
182
- io:: set_panic ( Some ( box Sink ( stderr. clone ( ) ) ) ) ;
183
- }
184
- ty:: tls:: with_thread_locals ( || f ( ) )
185
- } )
186
- } )
187
- } )
188
- }
189
-
190
- #[ cfg( parallel_compiler) ]
191
140
pub fn spawn_thread_pool < F : FnOnce ( ) -> R + Send , R : Send > (
192
141
threads : Option < usize > ,
193
142
stderr : & Option < Arc < Mutex < Vec < u8 > > > > ,
@@ -197,44 +146,33 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
197
146
use syntax;
198
147
use syntax_pos;
199
148
200
- let gcx_ptr = & Lock :: new ( 0 ) ;
201
-
202
149
let mut config = ThreadPoolBuilder :: new ( )
203
150
. acquire_thread_handler ( jobserver:: acquire_thread)
204
151
. release_thread_handler ( jobserver:: release_thread)
205
- . num_threads ( Session :: threads_from_count ( threads) )
206
- . deadlock_handler ( || unsafe { ty:: query:: handle_deadlock ( ) } ) ;
152
+ . num_threads ( Session :: threads_from_count ( threads) ) ;
207
153
208
154
if let Some ( size) = get_stack_size ( ) {
209
155
config = config. stack_size ( size) ;
210
156
}
211
157
212
158
let with_pool = move |pool : & ThreadPool | pool. install ( move || f ( ) ) ;
213
159
214
- syntax:: with_globals ( || {
215
- syntax:: GLOBALS . with ( |syntax_globals| {
216
- syntax_pos:: GLOBALS . with ( |syntax_pos_globals| {
217
- // The main handler runs for each Rayon worker thread and sets up
218
- // the thread local rustc uses. syntax_globals and syntax_pos_globals are
219
- // captured and set on the new threads. ty::tls::with_thread_locals sets up
220
- // thread local callbacks from libsyntax
221
- let main_handler = move |worker : & mut dyn FnMut ( ) | {
222
- syntax:: GLOBALS . set ( syntax_globals, || {
223
- syntax_pos:: GLOBALS . set ( syntax_pos_globals, || {
224
- if let Some ( stderr) = stderr {
225
- io:: set_panic ( Some ( box Sink ( stderr. clone ( ) ) ) ) ;
226
- }
227
- ty:: tls:: with_thread_locals ( || {
228
- ty:: tls:: GCX_PTR . set ( gcx_ptr, || worker ( ) )
229
- } )
230
- } )
231
- } )
232
- } ;
233
-
234
- ThreadPool :: scoped_pool ( config, main_handler, with_pool) . unwrap ( )
160
+ // The main handler runs for each Rayon worker thread and sets up
161
+ // the thread local rustc uses. syntax_globals and syntax_pos_globals are
162
+ // captured and set on the new threads. ty::tls::with_thread_locals sets up
163
+ // thread local callbacks from libsyntax
164
+ let main_handler = move |worker : & mut dyn FnMut ( ) | {
165
+ syntax:: with_globals ( || {
166
+ if let Some ( stderr) = stderr {
167
+ io:: set_panic ( Some ( box Sink ( stderr. clone ( ) ) ) ) ;
168
+ }
169
+ ty:: tls:: with_thread_locals ( || {
170
+ ty:: tls:: GCX_PTR . set ( & Lock :: new ( 0 ) , || worker ( ) )
235
171
} )
236
172
} )
237
- } )
173
+ } ;
174
+
175
+ ThreadPool :: scoped_pool ( config, main_handler, with_pool) . unwrap ( )
238
176
}
239
177
240
178
fn load_backend_from_dylib ( path : & Path ) -> fn ( ) -> Box < dyn CodegenBackend > {
0 commit comments