@@ -7,7 +7,7 @@ use rustc_codegen_ssa::traits::CodegenBackend;
7
7
use rustc_codegen_ssa:: CodegenResults ;
8
8
use rustc_data_structures:: steal:: Steal ;
9
9
use rustc_data_structures:: svh:: Svh ;
10
- use rustc_data_structures:: sync:: { AppendOnlyIndexVec , FreezeLock , Lrc , OnceLock , WorkerLocal } ;
10
+ use rustc_data_structures:: sync:: { AppendOnlyIndexVec , FreezeLock , OnceLock , WorkerLocal } ;
11
11
use rustc_hir:: def_id:: { StableCrateId , CRATE_DEF_ID , LOCAL_CRATE } ;
12
12
use rustc_hir:: definitions:: Definitions ;
13
13
use rustc_incremental:: setup_dep_graph;
@@ -101,10 +101,11 @@ impl<'tcx> Queries<'tcx> {
101
101
}
102
102
}
103
103
104
- fn session ( & self ) -> & Lrc < Session > {
105
- & self . compiler . sess
104
+ fn session ( & self ) -> & Session {
105
+ & self . compiler . session ( )
106
106
}
107
- fn codegen_backend ( & self ) -> & Lrc < dyn CodegenBackend > {
107
+
108
+ fn codegen_backend ( & self ) -> & dyn CodegenBackend {
108
109
self . compiler . codegen_backend ( )
109
110
}
110
111
@@ -197,7 +198,7 @@ impl<'tcx> Queries<'tcx> {
197
198
// Hook for UI tests.
198
199
Self :: check_for_rustc_errors_attr ( tcx) ;
199
200
200
- Ok ( passes:: start_codegen ( & * * self . codegen_backend ( ) , tcx) )
201
+ Ok ( passes:: start_codegen ( self . codegen_backend ( ) , tcx) )
201
202
} )
202
203
}
203
204
@@ -236,67 +237,48 @@ impl<'tcx> Queries<'tcx> {
236
237
}
237
238
238
239
pub fn linker ( & ' tcx self , ongoing_codegen : Box < dyn Any > ) -> Result < Linker > {
239
- let sess = self . session ( ) . clone ( ) ;
240
- let codegen_backend = self . codegen_backend ( ) . clone ( ) ;
241
-
242
- let ( crate_hash, prepare_outputs, dep_graph) = self . global_ctxt ( ) ?. enter ( |tcx| {
243
- (
244
- if tcx. needs_crate_hash ( ) { Some ( tcx. crate_hash ( LOCAL_CRATE ) ) } else { None } ,
245
- tcx. output_filenames ( ( ) ) . clone ( ) ,
246
- tcx. dep_graph . clone ( ) ,
247
- )
248
- } ) ;
249
-
250
- Ok ( Linker {
251
- sess,
252
- codegen_backend,
253
-
254
- dep_graph,
255
- prepare_outputs,
256
- crate_hash,
257
- ongoing_codegen,
240
+ self . global_ctxt ( ) ?. enter ( |tcx| {
241
+ Ok ( Linker {
242
+ dep_graph : tcx. dep_graph . clone ( ) ,
243
+ output_filenames : tcx. output_filenames ( ( ) ) . clone ( ) ,
244
+ crate_hash : if tcx. needs_crate_hash ( ) {
245
+ Some ( tcx. crate_hash ( LOCAL_CRATE ) )
246
+ } else {
247
+ None
248
+ } ,
249
+ ongoing_codegen,
250
+ } )
258
251
} )
259
252
}
260
253
}
261
254
262
255
pub struct Linker {
263
- // compilation inputs
264
- sess : Lrc < Session > ,
265
- codegen_backend : Lrc < dyn CodegenBackend > ,
266
-
267
- // compilation outputs
268
256
dep_graph : DepGraph ,
269
- prepare_outputs : Arc < OutputFilenames > ,
257
+ output_filenames : Arc < OutputFilenames > ,
270
258
// Only present when incr. comp. is enabled.
271
259
crate_hash : Option < Svh > ,
272
260
ongoing_codegen : Box < dyn Any > ,
273
261
}
274
262
275
263
impl Linker {
276
- pub fn link ( self ) -> Result < ( ) > {
277
- let ( codegen_results, work_products) = self . codegen_backend . join_codegen (
278
- self . ongoing_codegen ,
279
- & self . sess ,
280
- & self . prepare_outputs ,
281
- ) ?;
264
+ pub fn link ( self , sess : & Session , codegen_backend : & dyn CodegenBackend ) -> Result < ( ) > {
265
+ let ( codegen_results, work_products) =
266
+ codegen_backend. join_codegen ( self . ongoing_codegen , sess, & self . output_filenames ) ?;
282
267
283
- self . sess . compile_status ( ) ?;
268
+ sess. compile_status ( ) ?;
284
269
285
- let sess = & self . sess ;
286
- let dep_graph = self . dep_graph ;
287
270
sess. time ( "serialize_work_products" , || {
288
- rustc_incremental:: save_work_product_index ( sess, & dep_graph, work_products)
271
+ rustc_incremental:: save_work_product_index ( sess, & self . dep_graph , work_products)
289
272
} ) ;
290
273
291
- let prof = self . sess . prof . clone ( ) ;
292
- prof. generic_activity ( "drop_dep_graph" ) . run ( move || drop ( dep_graph) ) ;
274
+ let prof = sess. prof . clone ( ) ;
275
+ prof. generic_activity ( "drop_dep_graph" ) . run ( move || drop ( self . dep_graph ) ) ;
293
276
294
277
// Now that we won't touch anything in the incremental compilation directory
295
278
// any more, we can finalize it (which involves renaming it)
296
- rustc_incremental:: finalize_session_directory ( & self . sess , self . crate_hash ) ;
279
+ rustc_incremental:: finalize_session_directory ( sess, self . crate_hash ) ;
297
280
298
- if !self
299
- . sess
281
+ if !sess
300
282
. opts
301
283
. output_types
302
284
. keys ( )
@@ -306,14 +288,14 @@ impl Linker {
306
288
}
307
289
308
290
if sess. opts . unstable_opts . no_link {
309
- let rlink_file = self . prepare_outputs . with_extension ( config:: RLINK_EXT ) ;
291
+ let rlink_file = self . output_filenames . with_extension ( config:: RLINK_EXT ) ;
310
292
CodegenResults :: serialize_rlink ( sess, & rlink_file, & codegen_results)
311
293
. map_err ( |error| sess. emit_fatal ( FailedWritingFile { path : & rlink_file, error } ) ) ?;
312
294
return Ok ( ( ) ) ;
313
295
}
314
296
315
297
let _timer = sess. prof . verbose_generic_activity ( "link_crate" ) ;
316
- self . codegen_backend . link ( & self . sess , codegen_results, & self . prepare_outputs )
298
+ codegen_backend. link ( sess, codegen_results, & self . output_filenames )
317
299
}
318
300
}
319
301
0 commit comments