@@ -2,7 +2,7 @@ use crate::interface::{Compiler, Result};
2
2
use crate :: passes:: { self , BoxedResolver , BoxedGlobalCtxt } ;
3
3
4
4
use rustc_incremental:: DepGraphFuture ;
5
- use rustc_data_structures:: sync:: Lrc ;
5
+ use rustc_data_structures:: sync:: { Lrc , Once } ;
6
6
use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
7
7
use rustc:: session:: config:: { OutputFilenames , OutputType } ;
8
8
use rustc:: util:: common:: { time, ErrorReported } ;
@@ -12,7 +12,7 @@ use rustc::session::Session;
12
12
use rustc:: lint:: LintStore ;
13
13
use rustc:: hir:: def_id:: LOCAL_CRATE ;
14
14
use rustc:: ty:: steal:: Steal ;
15
- use rustc:: ty:: ResolverOutputs ;
15
+ use rustc:: ty:: { AllArenas , ResolverOutputs , GlobalCtxt } ;
16
16
use rustc:: dep_graph:: DepGraph ;
17
17
use std:: cell:: { Ref , RefMut , RefCell } ;
18
18
use std:: rc:: Rc ;
@@ -70,23 +70,29 @@ impl<T> Default for Query<T> {
70
70
71
71
pub struct Queries < ' comp > {
72
72
compiler : & ' comp Compiler ,
73
+ gcx : Once < GlobalCtxt < ' comp > > ,
74
+ arenas : Once < AllArenas > ,
75
+ forest : Once < hir:: map:: Forest > ,
73
76
74
77
dep_graph_future : Query < Option < DepGraphFuture > > ,
75
78
parse : Query < ast:: Crate > ,
76
79
crate_name : Query < String > ,
77
80
register_plugins : Query < ( ast:: Crate , Lrc < LintStore > ) > ,
78
81
expansion : Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > ,
79
82
dep_graph : Query < DepGraph > ,
80
- lower_to_hir : Query < ( Steal < hir:: map:: Forest > , Steal < ResolverOutputs > ) > ,
83
+ lower_to_hir : Query < ( & ' comp hir:: map:: Forest , Steal < ResolverOutputs > ) > ,
81
84
prepare_outputs : Query < OutputFilenames > ,
82
- global_ctxt : Query < BoxedGlobalCtxt > ,
85
+ global_ctxt : Query < BoxedGlobalCtxt < ' comp > > ,
83
86
ongoing_codegen : Query < Box < dyn Any > > ,
84
87
}
85
88
86
89
impl < ' comp > Queries < ' comp > {
87
90
pub fn new ( compiler : & ' comp Compiler ) -> Queries < ' comp > {
88
91
Queries {
89
92
compiler,
93
+ gcx : Once :: new ( ) ,
94
+ arenas : Once :: new ( ) ,
95
+ forest : Once :: new ( ) ,
90
96
dep_graph_future : Default :: default ( ) ,
91
97
parse : Default :: default ( ) ,
92
98
crate_name : Default :: default ( ) ,
@@ -209,23 +215,24 @@ impl<'comp> Queries<'comp> {
209
215
}
210
216
211
217
pub fn lower_to_hir (
212
- & self ,
213
- ) -> Result < & Query < ( Steal < hir:: map:: Forest > , Steal < ResolverOutputs > ) > > {
218
+ & ' comp self ,
219
+ ) -> Result < & Query < ( & ' comp hir:: map:: Forest , Steal < ResolverOutputs > ) > > {
214
220
self . lower_to_hir . compute ( || {
215
221
let expansion_result = self . expansion ( ) ?;
216
222
let peeked = expansion_result. peek ( ) ;
217
223
let krate = & peeked. 0 ;
218
224
let resolver = peeked. 1 . steal ( ) ;
219
225
let lint_store = & peeked. 2 ;
220
- let hir = Steal :: new ( resolver. borrow_mut ( ) . access ( |resolver| {
226
+ let hir = resolver. borrow_mut ( ) . access ( |resolver| {
221
227
passes:: lower_to_hir (
222
228
self . session ( ) ,
223
229
lint_store,
224
230
resolver,
225
231
& * self . dep_graph ( ) ?. peek ( ) ,
226
232
& krate
227
233
)
228
- } ) ?) ;
234
+ } ) ?;
235
+ let hir = self . forest . init_locking ( || hir) ;
229
236
Ok ( ( hir, Steal :: new ( BoxedResolver :: to_resolver_outputs ( resolver) ) ) )
230
237
} )
231
238
}
@@ -242,25 +249,27 @@ impl<'comp> Queries<'comp> {
242
249
} )
243
250
}
244
251
245
- pub fn global_ctxt ( & self ) -> Result < & Query < BoxedGlobalCtxt > > {
252
+ pub fn global_ctxt ( & ' comp self ) -> Result < & Query < BoxedGlobalCtxt < ' comp > > > {
246
253
self . global_ctxt . compute ( || {
247
254
let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
248
255
let outputs = self . prepare_outputs ( ) ?. peek ( ) . clone ( ) ;
249
256
let lint_store = self . expansion ( ) ?. peek ( ) . 2 . clone ( ) ;
250
- let hir = self . lower_to_hir ( ) ?;
251
- let hir = hir. peek ( ) ;
252
- let ( hir_forest, resolver_outputs) = & * hir;
257
+ let hir = self . lower_to_hir ( ) ?. peek ( ) ;
258
+ let ( ref hir_forest, ref resolver_outputs) = & * hir;
253
259
Ok ( passes:: create_global_ctxt (
254
260
self . compiler ,
255
261
lint_store,
256
- hir_forest. steal ( ) ,
262
+ hir_forest,
257
263
resolver_outputs. steal ( ) ,
258
264
outputs,
259
- & crate_name) )
265
+ & crate_name,
266
+ & self . gcx ,
267
+ & self . arenas ,
268
+ ) )
260
269
} )
261
270
}
262
271
263
- pub fn ongoing_codegen ( & self ) -> Result < & Query < Box < dyn Any > > > {
272
+ pub fn ongoing_codegen ( & ' comp self ) -> Result < & Query < Box < dyn Any > > > {
264
273
self . ongoing_codegen . compute ( || {
265
274
let outputs = self . prepare_outputs ( ) ?;
266
275
self . global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
@@ -278,7 +287,7 @@ impl<'comp> Queries<'comp> {
278
287
} )
279
288
}
280
289
281
- pub fn linker ( & self ) -> Result < Linker > {
290
+ pub fn linker ( & ' comp self ) -> Result < Linker > {
282
291
let dep_graph = self . dep_graph ( ) ?;
283
292
let prepare_outputs = self . prepare_outputs ( ) ?;
284
293
let ongoing_codegen = self . ongoing_codegen ( ) ?;
@@ -317,10 +326,18 @@ impl Linker {
317
326
318
327
impl Compiler {
319
328
pub fn enter < F , T > ( & self , f : F ) -> T
320
- where F : FnOnce ( & Queries < ' _ > ) -> T
329
+ where F : for < ' tcx > FnOnce ( & ' tcx Queries < ' tcx > ) -> T
321
330
{
322
331
let queries = Queries :: new ( & self ) ;
323
- f ( & queries)
332
+ let ret = f ( & queries) ;
333
+
334
+ if self . session ( ) . opts . debugging_opts . query_stats {
335
+ if let Ok ( gcx) = queries. global_ctxt ( ) {
336
+ gcx. peek ( ) . print_stats ( ) ;
337
+ }
338
+ }
339
+
340
+ ret
324
341
}
325
342
326
343
// This method is different to all the other methods in `Compiler` because
0 commit comments