@@ -7,7 +7,7 @@ use rustc_codegen_ssa::traits::CodegenBackend;
77use rustc_codegen_ssa:: CodegenResults ;
88use rustc_data_structures:: steal:: Steal ;
99use 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 } ;
1111use rustc_hir:: def_id:: { StableCrateId , CRATE_DEF_ID , LOCAL_CRATE } ;
1212use rustc_hir:: definitions:: Definitions ;
1313use rustc_incremental:: setup_dep_graph;
@@ -101,10 +101,11 @@ impl<'tcx> Queries<'tcx> {
101101 }
102102 }
103103
104- fn session ( & self ) -> & Lrc < Session > {
105- & self . compiler . sess
104+ fn session ( & self ) -> & Session {
105+ & self . compiler . session ( )
106106 }
107- fn codegen_backend ( & self ) -> & Lrc < dyn CodegenBackend > {
107+
108+ fn codegen_backend ( & self ) -> & dyn CodegenBackend {
108109 self . compiler . codegen_backend ( )
109110 }
110111
@@ -197,7 +198,7 @@ impl<'tcx> Queries<'tcx> {
197198 // Hook for UI tests.
198199 Self :: check_for_rustc_errors_attr ( tcx) ;
199200
200- Ok ( passes:: start_codegen ( & * * self . codegen_backend ( ) , tcx) )
201+ Ok ( passes:: start_codegen ( self . codegen_backend ( ) , tcx) )
201202 } )
202203 }
203204
@@ -236,67 +237,48 @@ impl<'tcx> Queries<'tcx> {
236237 }
237238
238239 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+ } )
258251 } )
259252 }
260253}
261254
262255pub struct Linker {
263- // compilation inputs
264- sess : Lrc < Session > ,
265- codegen_backend : Lrc < dyn CodegenBackend > ,
266-
267- // compilation outputs
268256 dep_graph : DepGraph ,
269- prepare_outputs : Arc < OutputFilenames > ,
257+ output_filenames : Arc < OutputFilenames > ,
270258 // Only present when incr. comp. is enabled.
271259 crate_hash : Option < Svh > ,
272260 ongoing_codegen : Box < dyn Any > ,
273261}
274262
275263impl 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 ) ?;
282267
283- self . sess . compile_status ( ) ?;
268+ sess. compile_status ( ) ?;
284269
285- let sess = & self . sess ;
286- let dep_graph = self . dep_graph ;
287270 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)
289272 } ) ;
290273
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 ) ) ;
293276
294277 // Now that we won't touch anything in the incremental compilation directory
295278 // 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 ) ;
297280
298- if !self
299- . sess
281+ if !sess
300282 . opts
301283 . output_types
302284 . keys ( )
@@ -306,14 +288,14 @@ impl Linker {
306288 }
307289
308290 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 ) ;
310292 CodegenResults :: serialize_rlink ( sess, & rlink_file, & codegen_results)
311293 . map_err ( |error| sess. emit_fatal ( FailedWritingFile { path : & rlink_file, error } ) ) ?;
312294 return Ok ( ( ) ) ;
313295 }
314296
315297 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 )
317299 }
318300}
319301
0 commit comments