@@ -20,7 +20,7 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
20
20
use rustc:: session:: search_paths:: PathKind ;
21
21
use rustc:: lint;
22
22
use rustc:: middle:: { self , reachable, resolve_lifetime, stability} ;
23
- use rustc:: middle:: cstore:: CrateStore ;
23
+ use rustc:: middle:: cstore:: CrateStoreDyn ;
24
24
use rustc:: middle:: privacy:: AccessLevels ;
25
25
use rustc:: ty:: { self , AllArenas , Resolutions , TyCtxt } ;
26
26
use rustc:: traits;
@@ -49,7 +49,7 @@ use std::fs;
49
49
use std:: io:: { self , Write } ;
50
50
use std:: iter;
51
51
use std:: path:: { Path , PathBuf } ;
52
- use rustc_data_structures:: sync:: Lrc ;
52
+ use rustc_data_structures:: sync:: { self , Lrc } ;
53
53
use std:: sync:: mpsc;
54
54
use syntax:: { self , ast, attr, diagnostics, visit} ;
55
55
use syntax:: ext:: base:: ExtCtxt ;
@@ -64,6 +64,51 @@ use pretty::ReplaceBodyWithLoop;
64
64
65
65
use profile;
66
66
67
+ #[ cfg( not( parallel_queries) ) ]
68
+ pub fn spawn_thread_pool < F : FnOnce ( config:: Options ) -> R + sync:: Send , R : sync:: Send > (
69
+ opts : config:: Options ,
70
+ f : F
71
+ ) -> R {
72
+ f ( opts)
73
+ }
74
+
75
+ #[ cfg( parallel_queries) ]
76
+ pub fn spawn_thread_pool < F : FnOnce ( config:: Options ) -> R + sync:: Send , R : sync:: Send > (
77
+ opts : config:: Options ,
78
+ f : F
79
+ ) -> R {
80
+ use syntax;
81
+ use syntax_pos;
82
+ use rayon:: { ThreadPoolBuilder , ThreadPool } ;
83
+
84
+ let config = ThreadPoolBuilder :: new ( ) . num_threads ( Session :: query_threads_from_opts ( & opts) )
85
+ . stack_size ( 16 * 1024 * 1024 ) ;
86
+
87
+ let with_pool = move |pool : & ThreadPool | {
88
+ pool. install ( move || f ( opts) )
89
+ } ;
90
+
91
+ syntax:: GLOBALS . with ( |syntax_globals| {
92
+ syntax_pos:: GLOBALS . with ( |syntax_pos_globals| {
93
+ // The main handler run for each Rayon worker thread and sets up
94
+ // the thread local rustc uses. syntax_globals and syntax_pos_globals are
95
+ // captured and set on the new threads. ty::tls::with_thread_locals sets up
96
+ // thread local callbacks from libsyntax
97
+ let main_handler = move |worker : & mut FnMut ( ) | {
98
+ syntax:: GLOBALS . set ( syntax_globals, || {
99
+ syntax_pos:: GLOBALS . set ( syntax_pos_globals, || {
100
+ ty:: tls:: with_thread_locals ( || {
101
+ worker ( )
102
+ } )
103
+ } )
104
+ } )
105
+ } ;
106
+
107
+ ThreadPool :: scoped_pool ( config, main_handler, with_pool) . unwrap ( )
108
+ } )
109
+ } )
110
+ }
111
+
67
112
pub fn compile_input (
68
113
trans : Box < TransCrate > ,
69
114
sess : & Session ,
@@ -1047,7 +1092,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
1047
1092
trans : & TransCrate ,
1048
1093
control : & CompileController ,
1049
1094
sess : & ' tcx Session ,
1050
- cstore : & ' tcx CrateStore ,
1095
+ cstore : & ' tcx CrateStoreDyn ,
1051
1096
hir_map : hir_map:: Map < ' tcx > ,
1052
1097
mut analysis : ty:: CrateAnalysis ,
1053
1098
resolutions : Resolutions ,
0 commit comments