@@ -17,7 +17,8 @@ use rustc_middle::dep_graph::DepGraph;
1717use rustc_middle:: ty:: { GlobalCtxt , TyCtxt } ;
1818use rustc_session:: config:: { self , CrateType , OutputFilenames , OutputType } ;
1919use rustc_session:: cstore:: Untracked ;
20- use rustc_session:: { output:: find_crate_name, Session } ;
20+ use rustc_session:: output:: find_crate_name;
21+ use rustc_session:: Session ;
2122use rustc_span:: symbol:: sym;
2223use std:: any:: Any ;
2324use std:: cell:: { RefCell , RefMut } ;
@@ -101,25 +102,18 @@ impl<'tcx> Queries<'tcx> {
101102 }
102103 }
103104
104- fn session ( & self ) -> & Session {
105- self . compiler . session ( )
106- }
107-
108- fn codegen_backend ( & self ) -> & dyn CodegenBackend {
109- self . compiler . codegen_backend ( )
110- }
111-
112105 pub fn parse ( & self ) -> Result < QueryResult < ' _ , ast:: Crate > > {
113- self . parse
114- . compute ( || passes:: parse ( self . session ( ) ) . map_err ( |mut parse_error| parse_error. emit ( ) ) )
106+ self . parse . compute ( || {
107+ passes:: parse ( & self . compiler . sess ) . map_err ( |mut parse_error| parse_error. emit ( ) )
108+ } )
115109 }
116110
117111 #[ deprecated = "pre_configure may be made private in the future. If you need it please open an issue with your use case." ]
118112 pub fn pre_configure ( & self ) -> Result < QueryResult < ' _ , ( ast:: Crate , ast:: AttrVec ) > > {
119113 self . pre_configure . compute ( || {
120114 let mut krate = self . parse ( ) ?. steal ( ) ;
121115
122- let sess = self . session ( ) ;
116+ let sess = & self . compiler . sess ;
123117 rustc_builtin_macros:: cmdline_attrs:: inject (
124118 & mut krate,
125119 & sess. parse_sess ,
@@ -134,7 +128,7 @@ impl<'tcx> Queries<'tcx> {
134128
135129 pub fn global_ctxt ( & ' tcx self ) -> Result < QueryResult < ' _ , & ' tcx GlobalCtxt < ' tcx > > > {
136130 self . gcx . compute ( || {
137- let sess = self . session ( ) ;
131+ let sess = & self . compiler . sess ;
138132 #[ allow( deprecated) ]
139133 let ( krate, pre_configured_attrs) = self . pre_configure ( ) ?. steal ( ) ;
140134
@@ -150,7 +144,7 @@ impl<'tcx> Queries<'tcx> {
150144 let dep_graph = setup_dep_graph ( sess, crate_name, stable_crate_id) ?;
151145
152146 let cstore = FreezeLock :: new ( Box :: new ( CStore :: new (
153- self . codegen_backend ( ) . metadata_loader ( ) ,
147+ self . compiler . codegen_backend . metadata_loader ( ) ,
154148 stable_crate_id,
155149 ) ) as _ ) ;
156150 let definitions = FreezeLock :: new ( Definitions :: new ( stable_crate_id) ) ;
@@ -186,22 +180,6 @@ impl<'tcx> Queries<'tcx> {
186180 } )
187181 }
188182
189- pub fn ongoing_codegen ( & ' tcx self ) -> Result < Box < dyn Any > > {
190- self . global_ctxt ( ) ?. enter ( |tcx| {
191- // Don't do code generation if there were any errors
192- self . session ( ) . compile_status ( ) ?;
193-
194- // If we have any delayed bugs, for example because we created TyKind::Error earlier,
195- // it's likely that codegen will only cause more ICEs, obscuring the original problem
196- self . session ( ) . diagnostic ( ) . flush_delayed ( ) ;
197-
198- // Hook for UI tests.
199- Self :: check_for_rustc_errors_attr ( tcx) ;
200-
201- Ok ( passes:: start_codegen ( self . codegen_backend ( ) , tcx) )
202- } )
203- }
204-
205183 /// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used
206184 /// to write UI tests that actually test that compilation succeeds without reporting
207185 /// an error.
@@ -236,8 +214,20 @@ impl<'tcx> Queries<'tcx> {
236214 }
237215 }
238216
239- pub fn linker ( & ' tcx self , ongoing_codegen : Box < dyn Any > ) -> Result < Linker > {
217+ pub fn codegen_and_build_linker ( & ' tcx self ) -> Result < Linker > {
240218 self . global_ctxt ( ) ?. enter ( |tcx| {
219+ // Don't do code generation if there were any errors
220+ self . compiler . sess . compile_status ( ) ?;
221+
222+ // If we have any delayed bugs, for example because we created TyKind::Error earlier,
223+ // it's likely that codegen will only cause more ICEs, obscuring the original problem
224+ self . compiler . sess . diagnostic ( ) . flush_delayed ( ) ;
225+
226+ // Hook for UI tests.
227+ Self :: check_for_rustc_errors_attr ( tcx) ;
228+
229+ let ongoing_codegen = passes:: start_codegen ( & * self . compiler . codegen_backend , tcx) ;
230+
241231 Ok ( Linker {
242232 dep_graph : tcx. dep_graph . clone ( ) ,
243233 output_filenames : tcx. output_filenames ( ( ) ) . clone ( ) ,
@@ -304,6 +294,7 @@ impl Compiler {
304294 where
305295 F : for < ' tcx > FnOnce ( & ' tcx Queries < ' tcx > ) -> T ,
306296 {
297+ // Must declare `_timer` first so that it is dropped after `queries`.
307298 let mut _timer = None ;
308299 let queries = Queries :: new ( self ) ;
309300 let ret = f ( & queries) ;
@@ -316,15 +307,16 @@ impl Compiler {
316307 // after this point, they'll show up as "<unknown>" in self-profiling data.
317308 {
318309 let _prof_timer =
319- queries. session ( ) . prof . generic_activity ( "self_profile_alloc_query_strings" ) ;
310+ queries. compiler . sess . prof . generic_activity ( "self_profile_alloc_query_strings" ) ;
320311 gcx. enter ( rustc_query_impl:: alloc_self_profile_query_strings) ;
321312 }
322313
323- self . session ( )
324- . time ( "serialize_dep_graph" , || gcx. enter ( rustc_incremental:: save_dep_graph) ) ;
314+ self . sess . time ( "serialize_dep_graph" , || gcx. enter ( rustc_incremental:: save_dep_graph) ) ;
325315 }
326316
327- _timer = Some ( self . session ( ) . timer ( "free_global_ctxt" ) ) ;
317+ // The timer's lifetime spans the dropping of `queries`, which contains
318+ // the global context.
319+ _timer = Some ( self . sess . timer ( "free_global_ctxt" ) ) ;
328320
329321 ret
330322 }
0 commit comments