@@ -169,8 +169,11 @@ fn produce_final_output_artifacts(
169
169
if codegen_results. modules . len ( ) == 1 {
170
170
// 1) Only one codegen unit. In this case it's no difficulty
171
171
// to copy `foo.0.x` to `foo.x`.
172
- let module_name = Some ( & codegen_results. modules [ 0 ] . name [ ..] ) ;
173
- let path = crate_output. temp_path ( output_type, module_name) ;
172
+ let path = crate_output. temp_path_for_cgu (
173
+ output_type,
174
+ & codegen_results. modules [ 0 ] . name ,
175
+ sess. invocation_temp . as_deref ( ) ,
176
+ ) ;
174
177
let output = crate_output. path ( output_type) ;
175
178
if !output_type. is_text_output ( ) && output. is_tty ( ) {
176
179
sess. dcx ( )
@@ -183,22 +186,16 @@ fn produce_final_output_artifacts(
183
186
ensure_removed ( sess. dcx ( ) , & path) ;
184
187
}
185
188
} else {
186
- let extension = crate_output
187
- . temp_path ( output_type, None )
188
- . extension ( )
189
- . unwrap ( )
190
- . to_str ( )
191
- . unwrap ( )
192
- . to_owned ( ) ;
193
-
194
189
if crate_output. outputs . contains_explicit_name ( & output_type) {
195
190
// 2) Multiple codegen units, with `--emit foo=some_name`. We have
196
191
// no good solution for this case, so warn the user.
197
- sess. dcx ( ) . emit_warn ( ssa_errors:: IgnoringEmitPath { extension } ) ;
192
+ sess. dcx ( )
193
+ . emit_warn ( ssa_errors:: IgnoringEmitPath { extension : output_type. extension ( ) } ) ;
198
194
} else if crate_output. single_output_file . is_some ( ) {
199
195
// 3) Multiple codegen units, with `-o some_name`. We have
200
196
// no good solution for this case, so warn the user.
201
- sess. dcx ( ) . emit_warn ( ssa_errors:: IgnoringOutput { extension } ) ;
197
+ sess. dcx ( )
198
+ . emit_warn ( ssa_errors:: IgnoringOutput { extension : output_type. extension ( ) } ) ;
202
199
} else {
203
200
// 4) Multiple codegen units, but no explicit name. We
204
201
// just leave the `foo.0.x` files in place.
@@ -351,6 +348,7 @@ fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {
351
348
352
349
fn emit_cgu (
353
350
output_filenames : & OutputFilenames ,
351
+ invocation_temp : Option < & str > ,
354
352
prof : & SelfProfilerRef ,
355
353
name : String ,
356
354
module : UnwindModule < ObjectModule > ,
@@ -366,6 +364,7 @@ fn emit_cgu(
366
364
367
365
let module_regular = emit_module (
368
366
output_filenames,
367
+ invocation_temp,
369
368
prof,
370
369
product. object ,
371
370
ModuleKind :: Regular ,
@@ -391,6 +390,7 @@ fn emit_cgu(
391
390
392
391
fn emit_module (
393
392
output_filenames : & OutputFilenames ,
393
+ invocation_temp : Option < & str > ,
394
394
prof : & SelfProfilerRef ,
395
395
mut object : cranelift_object:: object:: write:: Object < ' _ > ,
396
396
kind : ModuleKind ,
@@ -409,7 +409,7 @@ fn emit_module(
409
409
object. set_section_data ( comment_section, producer, 1 ) ;
410
410
}
411
411
412
- let tmp_file = output_filenames. temp_path ( OutputType :: Object , Some ( & name) ) ;
412
+ let tmp_file = output_filenames. temp_path_for_cgu ( OutputType :: Object , & name, invocation_temp ) ;
413
413
let file = match File :: create ( & tmp_file) {
414
414
Ok ( file) => file,
415
415
Err ( err) => return Err ( format ! ( "error creating object file: {}" , err) ) ,
@@ -449,8 +449,11 @@ fn reuse_workproduct_for_cgu(
449
449
cgu : & CodegenUnit < ' _ > ,
450
450
) -> Result < ModuleCodegenResult , String > {
451
451
let work_product = cgu. previous_work_product ( tcx) ;
452
- let obj_out_regular =
453
- tcx. output_filenames ( ( ) ) . temp_path ( OutputType :: Object , Some ( cgu. name ( ) . as_str ( ) ) ) ;
452
+ let obj_out_regular = tcx. output_filenames ( ( ) ) . temp_path_for_cgu (
453
+ OutputType :: Object ,
454
+ cgu. name ( ) . as_str ( ) ,
455
+ tcx. sess . invocation_temp . as_deref ( ) ,
456
+ ) ;
454
457
let source_file_regular = rustc_incremental:: in_incr_comp_dir_sess (
455
458
& tcx. sess ,
456
459
& work_product. saved_files . get ( "o" ) . expect ( "no saved object file in work product" ) ,
@@ -595,13 +598,19 @@ fn module_codegen(
595
598
596
599
let global_asm_object_file =
597
600
profiler. generic_activity_with_arg ( "compile assembly" , & * cgu_name) . run ( || {
598
- crate :: global_asm:: compile_global_asm ( & global_asm_config, & cgu_name, & cx. global_asm )
601
+ crate :: global_asm:: compile_global_asm (
602
+ & global_asm_config,
603
+ & cgu_name,
604
+ & cx. global_asm ,
605
+ cx. invocation_temp . as_deref ( ) ,
606
+ )
599
607
} ) ?;
600
608
601
609
let codegen_result =
602
610
profiler. generic_activity_with_arg ( "write object file" , & * cgu_name) . run ( || {
603
611
emit_cgu (
604
612
& global_asm_config. output_filenames ,
613
+ cx. invocation_temp . as_deref ( ) ,
605
614
& profiler,
606
615
cgu_name,
607
616
module,
@@ -626,8 +635,11 @@ fn emit_metadata_module(tcx: TyCtxt<'_>, metadata: &EncodedMetadata) -> Compiled
626
635
. as_str ( )
627
636
. to_string ( ) ;
628
637
629
- let tmp_file =
630
- tcx. output_filenames ( ( ) ) . temp_path ( OutputType :: Metadata , Some ( & metadata_cgu_name) ) ;
638
+ let tmp_file = tcx. output_filenames ( ( ) ) . temp_path_for_cgu (
639
+ OutputType :: Metadata ,
640
+ & metadata_cgu_name,
641
+ tcx. sess . invocation_temp . as_deref ( ) ,
642
+ ) ;
631
643
632
644
let symbol_name = rustc_middle:: middle:: exported_symbols:: metadata_symbol_name ( tcx) ;
633
645
let obj = create_compressed_metadata_file ( tcx. sess , metadata, & symbol_name) ;
@@ -657,6 +669,7 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option<CompiledModule> {
657
669
658
670
match emit_module (
659
671
tcx. output_filenames ( ( ) ) ,
672
+ tcx. sess . invocation_temp . as_deref ( ) ,
660
673
& tcx. sess . prof ,
661
674
product. object ,
662
675
ModuleKind :: Allocator ,
@@ -728,26 +741,27 @@ pub(crate) fn run_aot(
728
741
729
742
let concurrency_limiter = IntoDynSyncSend ( ConcurrencyLimiter :: new ( todo_cgus. len ( ) ) ) ;
730
743
731
- let modules = tcx . sess . time ( "codegen mono items" , || {
732
- let mut modules : Vec < _ > = par_map ( todo_cgus , |( _ , cgu ) | {
733
- let dep_node = cgu . codegen_dep_node ( tcx ) ;
734
- tcx . dep_graph
735
- . with_task (
744
+ let modules: Vec < _ > =
745
+ tcx . sess . time ( "codegen mono items" , || {
746
+ let modules : Vec < _ > = par_map ( todo_cgus , | ( _ , cgu ) | {
747
+ let dep_node = cgu . codegen_dep_node ( tcx ) ;
748
+ let ( module , _ ) = tcx . dep_graph . with_task (
736
749
dep_node,
737
750
tcx,
738
751
( global_asm_config. clone ( ) , cgu. name ( ) , concurrency_limiter. acquire ( tcx. dcx ( ) ) ) ,
739
752
module_codegen,
740
753
Some ( rustc_middle:: dep_graph:: hash_result) ,
741
- )
742
- . 0
743
- } ) ;
744
- modules. extend (
745
- done_cgus
754
+ ) ;
755
+ IntoDynSyncSend ( module)
756
+ } ) ;
757
+ modules
746
758
. into_iter ( )
747
- . map ( |( _, cgu) | OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) ) ) ,
748
- ) ;
749
- modules
750
- } ) ;
759
+ . map ( |module| module. 0 )
760
+ . chain ( done_cgus. into_iter ( ) . map ( |( _, cgu) | {
761
+ OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) )
762
+ } ) )
763
+ . collect ( )
764
+ } ) ;
751
765
752
766
let allocator_module = emit_allocator_module ( tcx) ;
753
767
0 commit comments