@@ -9,13 +9,15 @@ use rustc::session::{DiagnosticOutput, Session};
9
9
use rustc:: util:: common:: ErrorReported ;
10
10
use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
11
11
use rustc_data_structures:: OnDrop ;
12
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
12
13
use rustc_data_structures:: sync:: Lrc ;
13
- use rustc_data_structures:: fx :: { FxHashSet , FxHashMap } ;
14
+ use rustc_data_structures:: steal :: Steal ;
14
15
use rustc_metadata:: cstore:: CStore ;
15
16
use std:: path:: PathBuf ;
16
17
use std:: result;
17
18
use std:: sync:: { Arc , Mutex } ;
18
19
use syntax;
20
+ use syntax:: parse:: parser:: InterpUserFn ;
19
21
use syntax:: source_map:: { FileLoader , SourceMap } ;
20
22
use syntax_pos:: edition;
21
23
@@ -35,9 +37,19 @@ pub struct Compiler {
35
37
pub ( crate ) queries : Queries ,
36
38
pub ( crate ) cstore : Lrc < CStore > ,
37
39
pub ( crate ) crate_name : Option < String > ,
40
+ /// In interpreter mode, the user fn to use when parsing.
41
+ pub ( crate ) interp_user_fn : Option < Steal < InterpUserFn > > ,
38
42
}
39
43
40
44
impl Compiler {
45
+ pub fn set_interp_user_fn (
46
+ & mut self ,
47
+ interp_user_fn : Option < InterpUserFn > ,
48
+ ) -> & mut Self {
49
+ self . interp_user_fn = interp_user_fn. map ( |user_fn| Steal :: new ( user_fn) ) ;
50
+ self
51
+ }
52
+
41
53
pub fn session ( & self ) -> & Lrc < Session > {
42
54
& self . sess
43
55
}
@@ -61,12 +73,12 @@ impl Compiler {
61
73
}
62
74
}
63
75
64
- /// The compiler configuration
76
+ /// The compiler configuration.
65
77
pub struct Config {
66
- /// Command line options
78
+ /// The command- line options.
67
79
pub opts : config:: Options ,
68
80
69
- /// cfg! configuration in addition to the default ones
81
+ /// ` cfg!` configuration in addition to the default ones.
70
82
pub crate_cfg : FxHashSet < ( String , Option < String > ) > ,
71
83
72
84
pub input : Input ,
@@ -76,17 +88,14 @@ pub struct Config {
76
88
pub file_loader : Option < Box < dyn FileLoader + Send + Sync > > ,
77
89
pub diagnostic_output : DiagnosticOutput ,
78
90
79
- /// Set to capture stderr output during compiler execution
91
+ /// `Some` to capture stderr output during compiler execution.
80
92
pub stderr : Option < Arc < Mutex < Vec < u8 > > > > ,
81
93
82
94
pub crate_name : Option < String > ,
83
95
pub lint_caps : FxHashMap < lint:: LintId , lint:: Level > ,
84
96
}
85
97
86
- pub fn run_compiler_in_existing_thread_pool < F , R > ( config : Config , f : F ) -> R
87
- where
88
- F : FnOnce ( & Compiler ) -> R ,
89
- {
98
+ pub fn create_compiler ( config : Config ) -> Compiler {
90
99
let ( sess, codegen_backend, source_map) = util:: create_session (
91
100
config. opts ,
92
101
config. crate_cfg ,
98
107
99
108
let cstore = Lrc :: new ( CStore :: new ( codegen_backend. metadata_loader ( ) ) ) ;
100
109
101
- let compiler = Compiler {
110
+ Compiler {
102
111
sess,
103
112
codegen_backend,
104
113
source_map,
@@ -109,7 +118,15 @@ where
109
118
output_file : config. output_file ,
110
119
queries : Default :: default ( ) ,
111
120
crate_name : config. crate_name ,
112
- } ;
121
+ interp_user_fn : None ,
122
+ }
123
+ }
124
+
125
+ pub fn run_compiler_in_existing_thread_pool < R > (
126
+ config : Config ,
127
+ f : impl FnOnce ( & Compiler ) -> R ,
128
+ ) -> R {
129
+ let compiler = create_compiler ( config) ;
113
130
114
131
let _sess_abort_error = OnDrop ( || {
115
132
compiler. sess . diagnostic ( ) . print_error_count ( & util:: diagnostics_registry ( ) ) ;
0 commit comments