@@ -35,6 +35,7 @@ extern crate graphviz;
3535extern crate env_logger;
3636#[ cfg( unix) ]
3737extern crate libc;
38+ extern crate rustc_rayon as rayon;
3839extern crate rustc;
3940extern crate rustc_allocator;
4041extern crate rustc_target;
@@ -53,6 +54,7 @@ extern crate rustc_save_analysis;
5354extern crate rustc_traits;
5455extern crate rustc_trans_utils;
5556extern crate rustc_typeck;
57+ extern crate scoped_tls;
5658extern crate serialize;
5759#[ macro_use]
5860extern crate log;
@@ -66,7 +68,7 @@ use pretty::{PpMode, UserIdentifiedItem};
6668use rustc_resolve as resolve;
6769use rustc_save_analysis as save;
6870use rustc_save_analysis:: DumpHandler ;
69- use rustc_data_structures:: sync:: Lrc ;
71+ use rustc_data_structures:: sync:: { self , Lrc } ;
7072use rustc_data_structures:: OnDrop ;
7173use rustc:: session:: { self , config, Session , build_session, CompileResult } ;
7274use rustc:: session:: CompileIncomplete ;
@@ -450,36 +452,40 @@ fn get_trans_sysroot(backend_name: &str) -> fn() -> Box<TransCrate> {
450452// See comments on CompilerCalls below for details about the callbacks argument.
451453// The FileLoader provides a way to load files from sources other than the file system.
452454pub fn run_compiler < ' a > ( args : & [ String ] ,
453- callbacks : & mut CompilerCalls < ' a > ,
455+ callbacks : & mut ( CompilerCalls < ' a > + sync :: Send ) ,
454456 file_loader : Option < Box < FileLoader + Send + Sync + ' static > > ,
455457 emitter_dest : Option < Box < Write + Send > > )
456458 -> ( CompileResult , Option < Session > )
457459{
458460 syntax:: with_globals ( || {
459- run_compiler_impl ( args, callbacks, file_loader, emitter_dest)
461+ let matches = match handle_options ( args) {
462+ Some ( matches) => matches,
463+ None => return ( Ok ( ( ) ) , None ) ,
464+ } ;
465+
466+ let ( sopts, cfg) = config:: build_session_options_and_crate_config ( & matches) ;
467+
468+ driver:: spawn_thread_pool ( sopts, |sopts| {
469+ run_compiler_with_pool ( matches, sopts, cfg, callbacks, file_loader, emitter_dest)
470+ } )
460471 } )
461472}
462473
463- fn run_compiler_impl < ' a > ( args : & [ String ] ,
464- callbacks : & mut CompilerCalls < ' a > ,
465- file_loader : Option < Box < FileLoader + Send + Sync + ' static > > ,
466- emitter_dest : Option < Box < Write + Send > > )
467- -> ( CompileResult , Option < Session > )
468- {
474+ fn run_compiler_with_pool < ' a > (
475+ matches : getopts:: Matches ,
476+ sopts : config:: Options ,
477+ cfg : ast:: CrateConfig ,
478+ callbacks : & mut ( CompilerCalls < ' a > + sync:: Send ) ,
479+ file_loader : Option < Box < FileLoader + Send + Sync + ' static > > ,
480+ emitter_dest : Option < Box < Write + Send > >
481+ ) -> ( CompileResult , Option < Session > ) {
469482 macro_rules! do_or_return { ( $expr: expr, $sess: expr) => {
470483 match $expr {
471484 Compilation :: Stop => return ( Ok ( ( ) ) , $sess) ,
472485 Compilation :: Continue => { }
473486 }
474487 } }
475488
476- let matches = match handle_options ( args) {
477- Some ( matches) => matches,
478- None => return ( Ok ( ( ) ) , None ) ,
479- } ;
480-
481- let ( sopts, cfg) = config:: build_session_options_and_crate_config ( & matches) ;
482-
483489 let descriptions = diagnostics_registry ( ) ;
484490
485491 do_or_return ! ( callbacks. early_callback( & matches,
0 commit comments