@@ -17,7 +17,8 @@ use rustc_middle::dep_graph::DepGraph;
17
17
use rustc_middle:: ty:: { GlobalCtxt , TyCtxt } ;
18
18
use rustc_session:: config:: { self , CrateType , OutputFilenames , OutputType } ;
19
19
use 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 ;
21
22
use rustc_span:: symbol:: sym;
22
23
use std:: any:: Any ;
23
24
use std:: cell:: { RefCell , RefMut } ;
@@ -101,25 +102,18 @@ impl<'tcx> Queries<'tcx> {
101
102
}
102
103
}
103
104
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
-
112
105
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
+ } )
115
109
}
116
110
117
111
#[ deprecated = "pre_configure may be made private in the future. If you need it please open an issue with your use case." ]
118
112
pub fn pre_configure ( & self ) -> Result < QueryResult < ' _ , ( ast:: Crate , ast:: AttrVec ) > > {
119
113
self . pre_configure . compute ( || {
120
114
let mut krate = self . parse ( ) ?. steal ( ) ;
121
115
122
- let sess = self . session ( ) ;
116
+ let sess = & self . compiler . sess ;
123
117
rustc_builtin_macros:: cmdline_attrs:: inject (
124
118
& mut krate,
125
119
& sess. parse_sess ,
@@ -134,7 +128,7 @@ impl<'tcx> Queries<'tcx> {
134
128
135
129
pub fn global_ctxt ( & ' tcx self ) -> Result < QueryResult < ' _ , & ' tcx GlobalCtxt < ' tcx > > > {
136
130
self . gcx . compute ( || {
137
- let sess = self . session ( ) ;
131
+ let sess = & self . compiler . sess ;
138
132
#[ allow( deprecated) ]
139
133
let ( krate, pre_configured_attrs) = self . pre_configure ( ) ?. steal ( ) ;
140
134
@@ -150,7 +144,7 @@ impl<'tcx> Queries<'tcx> {
150
144
let dep_graph = setup_dep_graph ( sess, crate_name, stable_crate_id) ?;
151
145
152
146
let cstore = FreezeLock :: new ( Box :: new ( CStore :: new (
153
- self . codegen_backend ( ) . metadata_loader ( ) ,
147
+ self . compiler . codegen_backend . metadata_loader ( ) ,
154
148
stable_crate_id,
155
149
) ) as _ ) ;
156
150
let definitions = FreezeLock :: new ( Definitions :: new ( stable_crate_id) ) ;
@@ -186,22 +180,6 @@ impl<'tcx> Queries<'tcx> {
186
180
} )
187
181
}
188
182
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
-
205
183
/// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used
206
184
/// to write UI tests that actually test that compilation succeeds without reporting
207
185
/// an error.
@@ -236,8 +214,20 @@ impl<'tcx> Queries<'tcx> {
236
214
}
237
215
}
238
216
239
- pub fn linker ( & ' tcx self , ongoing_codegen : Box < dyn Any > ) -> Result < Linker > {
217
+ pub fn codegen_and_build_linker ( & ' tcx self ) -> Result < Linker > {
240
218
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
+
241
231
Ok ( Linker {
242
232
dep_graph : tcx. dep_graph . clone ( ) ,
243
233
output_filenames : tcx. output_filenames ( ( ) ) . clone ( ) ,
@@ -304,6 +294,7 @@ impl Compiler {
304
294
where
305
295
F : for < ' tcx > FnOnce ( & ' tcx Queries < ' tcx > ) -> T ,
306
296
{
297
+ // Must declare `_timer` first so that it is dropped after `queries`.
307
298
let mut _timer = None ;
308
299
let queries = Queries :: new ( self ) ;
309
300
let ret = f ( & queries) ;
@@ -316,15 +307,16 @@ impl Compiler {
316
307
// after this point, they'll show up as "<unknown>" in self-profiling data.
317
308
{
318
309
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" ) ;
320
311
gcx. enter ( rustc_query_impl:: alloc_self_profile_query_strings) ;
321
312
}
322
313
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) ) ;
325
315
}
326
316
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" ) ) ;
328
320
329
321
ret
330
322
}
0 commit comments