@@ -8,7 +8,6 @@ use rustc::ty::{GlobalCtxt, ResolverOutputs, TyCtxt};
8
8
use rustc:: util:: common:: ErrorReported ;
9
9
use rustc_ast:: { self , ast} ;
10
10
use rustc_codegen_ssa:: traits:: CodegenBackend ;
11
- use rustc_coverage:: coverage;
12
11
use rustc_data_structures:: sync:: { Lrc , Once , WorkerLocal } ;
13
12
use rustc_hir:: def_id:: LOCAL_CRATE ;
14
13
use rustc_hir:: Crate ;
@@ -18,7 +17,6 @@ use rustc_session::config::{OutputFilenames, OutputType};
18
17
use rustc_session:: { output:: find_crate_name, Session } ;
19
18
use rustc_span:: symbol:: sym;
20
19
21
- use log:: debug;
22
20
use std:: any:: Any ;
23
21
use std:: cell:: { Ref , RefCell , RefMut } ;
24
22
use std:: mem;
@@ -77,8 +75,9 @@ pub struct Queries<'tcx> {
77
75
parse : Query < ast:: Crate > ,
78
76
crate_name : Query < String > ,
79
77
register_plugins : Query < ( ast:: Crate , Lrc < LintStore > ) > ,
80
- expansion : Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > ,
78
+ unresolved_expansion : Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > ,
81
79
instrument : Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > ,
80
+ expansion : Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > ,
82
81
dep_graph : Query < DepGraph > ,
83
82
lower_to_hir : Query < ( & ' tcx Crate < ' tcx > , Steal < ResolverOutputs > ) > ,
84
83
prepare_outputs : Query < OutputFilenames > ,
@@ -97,6 +96,7 @@ impl<'tcx> Queries<'tcx> {
97
96
parse : Default :: default ( ) ,
98
97
crate_name : Default :: default ( ) ,
99
98
register_plugins : Default :: default ( ) ,
99
+ unresolved_expansion : Default :: default ( ) ,
100
100
expansion : Default :: default ( ) ,
101
101
instrument : Default :: default ( ) ,
102
102
dep_graph : Default :: default ( ) ,
@@ -115,9 +115,7 @@ impl<'tcx> Queries<'tcx> {
115
115
}
116
116
117
117
pub fn dep_graph_future ( & self ) -> Result < & Query < Option < DepGraphFuture > > > {
118
- debug ! ( "query dep_graph_future" ) ;
119
118
self . dep_graph_future . compute ( || {
120
- debug ! ( "compute query dep_graph_future" ) ;
121
119
Ok ( self
122
120
. session ( )
123
121
. opts
@@ -127,9 +125,7 @@ impl<'tcx> Queries<'tcx> {
127
125
}
128
126
129
127
pub fn parse ( & self ) -> Result < & Query < ast:: Crate > > {
130
- debug ! ( "query parse" ) ;
131
128
self . parse . compute ( || {
132
- debug ! ( "compute query parse" ) ;
133
129
passes:: parse ( self . session ( ) , & self . compiler . input ) . map_err ( |mut parse_error| {
134
130
parse_error. emit ( ) ;
135
131
ErrorReported
@@ -138,9 +134,7 @@ impl<'tcx> Queries<'tcx> {
138
134
}
139
135
140
136
pub fn register_plugins ( & self ) -> Result < & Query < ( ast:: Crate , Lrc < LintStore > ) > > {
141
- debug ! ( "query register_plugins" ) ;
142
137
self . register_plugins . compute ( || {
143
- debug ! ( "compute query register_plugins" ) ;
144
138
let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
145
139
let krate = self . parse ( ) ?. take ( ) ;
146
140
@@ -165,9 +159,7 @@ impl<'tcx> Queries<'tcx> {
165
159
}
166
160
167
161
pub fn crate_name ( & self ) -> Result < & Query < String > > {
168
- debug ! ( "query crate_name" ) ;
169
162
self . crate_name . compute ( || {
170
- debug ! ( "compute query crate_name" ) ;
171
163
Ok ( match self . compiler . crate_name {
172
164
Some ( ref crate_name) => crate_name. clone ( ) ,
173
165
None => {
@@ -179,16 +171,15 @@ impl<'tcx> Queries<'tcx> {
179
171
} )
180
172
}
181
173
182
- pub fn expansion (
174
+ /// Expands built-ins and other macros, but does not perform name resolution, pending potential
175
+ /// instrumentation.
176
+ pub fn unresolved_expansion (
183
177
& self ,
184
178
) -> Result < & Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > > {
185
- debug ! ( "query expansion" ) ;
186
- self . expansion . compute ( || {
187
- debug ! ( "compute query expansion" ) ;
179
+ self . unresolved_expansion . compute ( || {
188
180
let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
189
181
let ( krate, lint_store) = self . register_plugins ( ) ?. take ( ) ;
190
182
let _timer = self . session ( ) . timer ( "configure_and_expand" ) ;
191
- debug ! ( "just before death" ) ;
192
183
passes:: configure_and_expand (
193
184
self . session ( ) . clone ( ) ,
194
185
lint_store. clone ( ) ,
@@ -197,16 +188,53 @@ debug!("just before death");
197
188
& crate_name,
198
189
)
199
190
. map ( |( krate, resolver) | {
200
- debug ! ( "NEVER GET HERE" ) ;
201
191
( krate, Steal :: new ( Rc :: new ( RefCell :: new ( resolver) ) ) , lint_store)
202
192
} )
203
193
} )
204
194
}
205
195
196
+ /// Returns a modified ast::Crate with injected instrumentation code, if requested by command
197
+ /// line option.
198
+ ///
199
+ /// The `instrument` pass/query depends on (and implies) `unresolved_expansion`.
200
+ pub fn instrument (
201
+ & self ,
202
+ ) -> Result < & Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > > {
203
+ self . instrument . compute ( || {
204
+ let ( krate, boxed_resolver, lint_store) = self . unresolved_expansion ( ) ?. take ( ) ;
205
+ let instrument_coverage = match self . session ( ) . opts . debugging_opts . instrument_coverage {
206
+ Some ( opt) => opt,
207
+ None => false ,
208
+ } ;
209
+ if instrument_coverage {
210
+ boxed_resolver. borrow ( ) . borrow_mut ( ) . access ( |resolver| {
211
+ let _timer = self . session ( ) . timer ( "instrument_coverage" ) ;
212
+ passes:: instrument ( krate, resolver)
213
+ } )
214
+ } else {
215
+ Ok ( krate)
216
+ }
217
+ . map ( |krate| ( krate, boxed_resolver, lint_store) )
218
+ } )
219
+ }
220
+
221
+ /// Updates the ast::Crate, first querying `instrument`, which queries `unresolved_expansion`.
222
+ /// After all expansions and instrumentation, performs name resolution on the final AST.
223
+ pub fn expansion (
224
+ & self ,
225
+ ) -> Result < & Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > > {
226
+ self . expansion . compute ( || {
227
+ let ( krate, boxed_resolver, lint_store) = self . instrument ( ) ?. take ( ) ;
228
+ let result = boxed_resolver. borrow ( ) . borrow_mut ( ) . access ( |resolver| {
229
+ let _timer = self . session ( ) . timer ( "resolve_expansion" ) ;
230
+ passes:: resolve_crate ( self . session ( ) . clone ( ) , krate, resolver)
231
+ } ) ;
232
+ result. map ( |krate| ( krate, boxed_resolver, lint_store) )
233
+ } )
234
+ }
235
+
206
236
pub fn dep_graph ( & self ) -> Result < & Query < DepGraph > > {
207
- debug ! ( "query dep_graph" ) ;
208
237
self . dep_graph . compute ( || {
209
- debug ! ( "compute query dep_graph" ) ;
210
238
Ok ( match self . dep_graph_future ( ) ?. take ( ) {
211
239
None => DepGraph :: new_disabled ( ) ,
212
240
Some ( future) => {
@@ -225,42 +253,10 @@ debug!("NEVER GET HERE");
225
253
} )
226
254
}
227
255
228
- /// Instrumentation is optional (typically included based on `rustc` option). The
229
- /// `instrument` pass/query depends on (and implies) `expansion`. To ensure the instrumentation
230
- /// pass is executed (if requested), replace queries to `expansion` with queries to
231
- /// `instrument`. The query results are the same. If instrumentation is not requested,
232
- /// `expansion` will be queried and returned. If instrumentation is requested, `instrument`
233
- /// will query `expansion`, inject instrumentation code (modifying the crate and updating the
234
- /// `next_node_id()` in the resolver), and then return the query result from `expansion`, with
235
- /// the changes to crate and resolver.
236
- pub fn instrument ( & ' tcx self ) -> Result < & Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > > {
237
- debug ! ( "query instrument (depends on expansion), will instrument coverage if requested" ) ;
238
- let expansion = self . expansion ( ) ;
239
- let instrument_coverage = match self . session ( ) . opts . debugging_opts . instrument_coverage {
240
- Some ( opt) => opt,
241
- None => false ,
242
- } ;
243
- if instrument_coverage {
244
- self . instrument . compute ( || {
245
- debug ! ( "compute query instrument (depends on expansion), will instrument coverage if requested" ) ;
246
- let ( mut krate, boxed_resolver, lint_store) = expansion?. take ( ) ;
247
- let resolver = boxed_resolver. steal ( ) ;
248
- resolver. borrow_mut ( ) . access ( |resolver| {
249
- coverage:: instrument ( & mut krate, resolver)
250
- } ) ;
251
- Ok ( ( krate, Steal :: new ( resolver) , lint_store) )
252
- } )
253
- } else {
254
- expansion
255
- }
256
- }
257
-
258
256
pub fn lower_to_hir ( & ' tcx self ) -> Result < & Query < ( & ' tcx Crate < ' tcx > , Steal < ResolverOutputs > ) > > {
259
- debug ! ( "query lower_to_hir" ) ;
260
257
self . lower_to_hir . compute ( || {
261
- debug ! ( "compute query lower_to_hir" ) ;
262
- let instrument_result = self . instrument ( ) ?;
263
- let peeked = instrument_result. peek ( ) ;
258
+ let expansion_result = self . expansion ( ) ?;
259
+ let peeked = expansion_result. peek ( ) ;
264
260
let krate = & peeked. 0 ;
265
261
let resolver = peeked. 1 . steal ( ) ;
266
262
let lint_store = & peeked. 2 ;
@@ -280,9 +276,7 @@ debug!("NEVER GET HERE");
280
276
}
281
277
282
278
pub fn prepare_outputs ( & self ) -> Result < & Query < OutputFilenames > > {
283
- debug ! ( "query prepare_outputs" ) ;
284
279
self . prepare_outputs . compute ( || {
285
- debug ! ( "compute query prepare_outputs" ) ;
286
280
let expansion_result = self . expansion ( ) ?;
287
281
let ( krate, boxed_resolver, _) = & * expansion_result. peek ( ) ;
288
282
let crate_name = self . crate_name ( ) ?;
@@ -298,9 +292,7 @@ debug!("NEVER GET HERE");
298
292
}
299
293
300
294
pub fn global_ctxt ( & ' tcx self ) -> Result < & Query < QueryContext < ' tcx > > > {
301
- debug ! ( "query global_ctxt" ) ;
302
295
self . global_ctxt . compute ( || {
303
- debug ! ( "compute query global_ctxt" ) ;
304
296
let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
305
297
let outputs = self . prepare_outputs ( ) ?. peek ( ) . clone ( ) ;
306
298
let lint_store = self . expansion ( ) ?. peek ( ) . 2 . clone ( ) ;
@@ -323,9 +315,7 @@ debug!("NEVER GET HERE");
323
315
}
324
316
325
317
pub fn ongoing_codegen ( & ' tcx self ) -> Result < & Query < Box < dyn Any > > > {
326
- debug ! ( "query ongoing_codegen" ) ;
327
318
self . ongoing_codegen . compute ( || {
328
- debug ! ( "compute query ongoing_codegen" ) ;
329
319
let outputs = self . prepare_outputs ( ) ?;
330
320
self . global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
331
321
tcx. analysis ( LOCAL_CRATE ) . ok ( ) ;
@@ -413,7 +403,6 @@ pub struct Linker {
413
403
414
404
impl Linker {
415
405
pub fn link ( self ) -> Result < ( ) > {
416
- debug ! ( "Linker::link" ) ;
417
406
let codegen_results =
418
407
self . codegen_backend . join_codegen ( self . ongoing_codegen , & self . sess , & self . dep_graph ) ?;
419
408
let prof = self . sess . prof . clone ( ) ;
0 commit comments