@@ -2,7 +2,7 @@ use crate::interface::{Compiler, Result};
22use crate :: passes:: { self , BoxedResolver , BoxedGlobalCtxt } ;
33
44use rustc_incremental:: DepGraphFuture ;
5- use rustc_data_structures:: sync:: Lrc ;
5+ use rustc_data_structures:: sync:: { Lrc , Once } ;
66use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
77use rustc:: session:: config:: { OutputFilenames , OutputType } ;
88use rustc:: util:: common:: { time, ErrorReported } ;
@@ -12,7 +12,7 @@ use rustc::session::Session;
1212use rustc:: lint:: LintStore ;
1313use rustc:: hir:: def_id:: LOCAL_CRATE ;
1414use rustc:: ty:: steal:: Steal ;
15- use rustc:: ty:: ResolverOutputs ;
15+ use rustc:: ty:: { AllArenas , ResolverOutputs , GlobalCtxt } ;
1616use rustc:: dep_graph:: DepGraph ;
1717use std:: cell:: { Ref , RefMut , RefCell } ;
1818use std:: rc:: Rc ;
@@ -70,23 +70,29 @@ impl<T> Default for Query<T> {
7070
7171pub struct Queries < ' comp > {
7272 compiler : & ' comp Compiler ,
73+ gcx : Once < GlobalCtxt < ' comp > > ,
74+ arenas : Once < AllArenas > ,
75+ forest : Once < hir:: map:: Forest > ,
7376
7477 dep_graph_future : Query < Option < DepGraphFuture > > ,
7578 parse : Query < ast:: Crate > ,
7679 crate_name : Query < String > ,
7780 register_plugins : Query < ( ast:: Crate , Lrc < LintStore > ) > ,
7881 expansion : Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > ,
7982 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 > ) > ,
8184 prepare_outputs : Query < OutputFilenames > ,
82- global_ctxt : Query < BoxedGlobalCtxt > ,
85+ global_ctxt : Query < BoxedGlobalCtxt < ' comp > > ,
8386 ongoing_codegen : Query < Box < dyn Any > > ,
8487}
8588
8689impl < ' comp > Queries < ' comp > {
8790 pub fn new ( compiler : & ' comp Compiler ) -> Queries < ' comp > {
8891 Queries {
8992 compiler,
93+ gcx : Once :: new ( ) ,
94+ arenas : Once :: new ( ) ,
95+ forest : Once :: new ( ) ,
9096 dep_graph_future : Default :: default ( ) ,
9197 parse : Default :: default ( ) ,
9298 crate_name : Default :: default ( ) ,
@@ -209,23 +215,24 @@ impl<'comp> Queries<'comp> {
209215 }
210216
211217 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 > ) > > {
214220 self . lower_to_hir . compute ( || {
215221 let expansion_result = self . expansion ( ) ?;
216222 let peeked = expansion_result. peek ( ) ;
217223 let krate = & peeked. 0 ;
218224 let resolver = peeked. 1 . steal ( ) ;
219225 let lint_store = & peeked. 2 ;
220- let hir = Steal :: new ( resolver. borrow_mut ( ) . access ( |resolver| {
226+ let hir = resolver. borrow_mut ( ) . access ( |resolver| {
221227 passes:: lower_to_hir (
222228 self . session ( ) ,
223229 lint_store,
224230 resolver,
225231 & * self . dep_graph ( ) ?. peek ( ) ,
226232 & krate
227233 )
228- } ) ?) ;
234+ } ) ?;
235+ let hir = self . forest . init_locking ( || hir) ;
229236 Ok ( ( hir, Steal :: new ( BoxedResolver :: to_resolver_outputs ( resolver) ) ) )
230237 } )
231238 }
@@ -242,25 +249,27 @@ impl<'comp> Queries<'comp> {
242249 } )
243250 }
244251
245- pub fn global_ctxt ( & self ) -> Result < & Query < BoxedGlobalCtxt > > {
252+ pub fn global_ctxt ( & ' comp self ) -> Result < & Query < BoxedGlobalCtxt < ' comp > > > {
246253 self . global_ctxt . compute ( || {
247254 let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
248255 let outputs = self . prepare_outputs ( ) ?. peek ( ) . clone ( ) ;
249256 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;
253259 Ok ( passes:: create_global_ctxt (
254260 self . compiler ,
255261 lint_store,
256- hir_forest. steal ( ) ,
262+ hir_forest,
257263 resolver_outputs. steal ( ) ,
258264 outputs,
259- & crate_name) )
265+ & crate_name,
266+ & self . gcx ,
267+ & self . arenas ,
268+ ) )
260269 } )
261270 }
262271
263- pub fn ongoing_codegen ( & self ) -> Result < & Query < Box < dyn Any > > > {
272+ pub fn ongoing_codegen ( & ' comp self ) -> Result < & Query < Box < dyn Any > > > {
264273 self . ongoing_codegen . compute ( || {
265274 let outputs = self . prepare_outputs ( ) ?;
266275 self . global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
@@ -278,7 +287,7 @@ impl<'comp> Queries<'comp> {
278287 } )
279288 }
280289
281- pub fn linker ( & self ) -> Result < Linker > {
290+ pub fn linker ( & ' comp self ) -> Result < Linker > {
282291 let dep_graph = self . dep_graph ( ) ?;
283292 let prepare_outputs = self . prepare_outputs ( ) ?;
284293 let ongoing_codegen = self . ongoing_codegen ( ) ?;
@@ -317,10 +326,18 @@ impl Linker {
317326
318327impl Compiler {
319328 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
321330 {
322331 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
324341 }
325342
326343 // This method is different to all the other methods in `Compiler` because
0 commit comments