Skip to content

Commit f6d9259

Browse files
committed
Auto merge of #153412 - GuillaumeGomez:rollup-CHFIva5, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - #152164 (Lint unused features) - #152801 (Refactor WriteBackendMethods a bit) - #153317 (Abort after `representability` errors) - #153361 (enable `PassMode::Indirect { on_stack: true, .. }` tail call arguments) - #153402 (miri subtree update) - #153276 (Remove `cycle_fatal` query modifier) - #153396 (use `minicore` in some `run-make` tests) - #153401 (Migrationg of `LintDiagnostic` - part 7) - #153406 (Remove a ping for myself)
2 parents b90dc1e + bed05c2 commit f6d9259

File tree

213 files changed

+1743
-1267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+1743
-1267
lines changed

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ use object::read::archive::ArchiveFile;
2626
use rustc_codegen_ssa::back::lto::SerializedModule;
2727
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, SharedEmitter};
2828
use rustc_codegen_ssa::traits::*;
29-
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file};
29+
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, ModuleKind, looks_like_rust_object_file};
3030
use rustc_data_structures::memmap::Mmap;
3131
use rustc_data_structures::profiling::SelfProfilerRef;
3232
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
3333
use rustc_log::tracing::info;
3434
use rustc_session::config::Lto;
3535
use tempfile::{TempDir, tempdir};
3636

37-
use crate::back::write::save_temp_bitcode;
37+
use crate::back::write::{codegen, save_temp_bitcode};
3838
use crate::errors::LtoBitcodeFromRlib;
3939
use crate::{GccCodegenBackend, GccContext, LtoMode, to_gcc_opt_level};
4040

@@ -112,7 +112,7 @@ pub(crate) fn run_fat(
112112
shared_emitter: &SharedEmitter,
113113
each_linked_rlib_for_lto: &[PathBuf],
114114
modules: Vec<FatLtoInput<GccCodegenBackend>>,
115-
) -> ModuleCodegen<GccContext> {
115+
) -> CompiledModule {
116116
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
117117
let dcx = dcx.handle();
118118
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx);
@@ -132,12 +132,12 @@ pub(crate) fn run_fat(
132132
fn fat_lto(
133133
cgcx: &CodegenContext,
134134
prof: &SelfProfilerRef,
135-
_dcx: DiagCtxtHandle<'_>,
135+
dcx: DiagCtxtHandle<'_>,
136136
modules: Vec<FatLtoInput<GccCodegenBackend>>,
137137
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
138138
tmp_path: TempDir,
139139
//symbols_below_threshold: &[String],
140-
) -> ModuleCodegen<GccContext> {
140+
) -> CompiledModule {
141141
let _timer = prof.generic_activity("GCC_fat_lto_build_monolithic_module");
142142
info!("going for a fat lto");
143143

@@ -260,7 +260,7 @@ fn fat_lto(
260260
// of now.
261261
module.module_llvm.temp_dir = Some(tmp_path);
262262

263-
module
263+
codegen(cgcx, prof, dcx, module, &cgcx.module_config)
264264
}
265265

266266
pub struct ModuleBuffer(PathBuf);

compiler/rustc_codegen_gcc/src/back/write.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ use std::{env, fs};
22

33
use gccjit::{Context, OutputKind};
44
use rustc_codegen_ssa::back::link::ensure_removed;
5-
use rustc_codegen_ssa::back::write::{
6-
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, SharedEmitter,
7-
};
5+
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
86
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
97
use rustc_data_structures::profiling::SelfProfilerRef;
10-
use rustc_errors::DiagCtxt;
8+
use rustc_errors::DiagCtxtHandle;
119
use rustc_fs_util::link_or_copy;
1210
use rustc_log::tracing::debug;
1311
use rustc_session::config::OutputType;
@@ -20,13 +18,10 @@ use crate::{GccContext, LtoMode};
2018
pub(crate) fn codegen(
2119
cgcx: &CodegenContext,
2220
prof: &SelfProfilerRef,
23-
shared_emitter: &SharedEmitter,
21+
dcx: DiagCtxtHandle<'_>,
2422
module: ModuleCodegen<GccContext>,
2523
config: &ModuleConfig,
2624
) -> CompiledModule {
27-
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
28-
let dcx = dcx.handle();
29-
3025
let _timer = prof.generic_activity_with_arg("GCC_module_codegen", &*module.name);
3126
{
3227
let context = &module.module_llvm.context;

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use rustc_codegen_ssa::{CompiledModule, CompiledModules, CrateInfo, ModuleCodege
9292
use rustc_data_structures::fx::FxIndexMap;
9393
use rustc_data_structures::profiling::SelfProfilerRef;
9494
use rustc_data_structures::sync::IntoDynSyncSend;
95-
use rustc_errors::DiagCtxtHandle;
95+
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
9696
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
9797
use rustc_middle::ty::TyCtxt;
9898
use rustc_middle::util::Providers;
@@ -371,16 +371,6 @@ impl ExtraBackendMethods for GccCodegenBackend {
371371
self.lto_supported.load(Ordering::SeqCst),
372372
)
373373
}
374-
375-
fn target_machine_factory(
376-
&self,
377-
_sess: &Session,
378-
_opt_level: OptLevel,
379-
_features: &[String],
380-
) -> TargetMachineFactoryFn<Self> {
381-
// TODO(antoyo): set opt level.
382-
Arc::new(|_, _| ())
383-
}
384374
}
385375

386376
#[derive(Clone, Copy, PartialEq)]
@@ -429,7 +419,17 @@ impl WriteBackendMethods for GccCodegenBackend {
429419
type ModuleBuffer = ModuleBuffer;
430420
type ThinData = ();
431421

432-
fn run_and_optimize_fat_lto(
422+
fn target_machine_factory(
423+
&self,
424+
_sess: &Session,
425+
_opt_level: OptLevel,
426+
_features: &[String],
427+
) -> TargetMachineFactoryFn<Self> {
428+
// TODO(antoyo): set opt level.
429+
Arc::new(|_, _| ())
430+
}
431+
432+
fn optimize_and_codegen_fat_lto(
433433
cgcx: &CodegenContext,
434434
prof: &SelfProfilerRef,
435435
shared_emitter: &SharedEmitter,
@@ -438,7 +438,7 @@ impl WriteBackendMethods for GccCodegenBackend {
438438
_exported_symbols_for_lto: &[String],
439439
each_linked_rlib_for_lto: &[PathBuf],
440440
modules: Vec<FatLtoInput<Self>>,
441-
) -> ModuleCodegen<Self::Module> {
441+
) -> CompiledModule {
442442
back::lto::run_fat(cgcx, prof, shared_emitter, each_linked_rlib_for_lto, modules)
443443
}
444444

@@ -455,14 +455,6 @@ impl WriteBackendMethods for GccCodegenBackend {
455455
unreachable!()
456456
}
457457

458-
fn print_pass_timings(&self) {
459-
unimplemented!();
460-
}
461-
462-
fn print_statistics(&self) {
463-
unimplemented!()
464-
}
465-
466458
fn optimize(
467459
_cgcx: &CodegenContext,
468460
_prof: &SelfProfilerRef,
@@ -473,13 +465,13 @@ impl WriteBackendMethods for GccCodegenBackend {
473465
module.module_llvm.context.set_optimization_level(to_gcc_opt_level(config.opt_level));
474466
}
475467

476-
fn optimize_thin(
468+
fn optimize_and_codegen_thin(
477469
_cgcx: &CodegenContext,
478470
_prof: &SelfProfilerRef,
479471
_shared_emitter: &SharedEmitter,
480472
_tm_factory: TargetMachineFactoryFn<Self>,
481473
_thin: ThinModule<Self>,
482-
) -> ModuleCodegen<Self::Module> {
474+
) -> CompiledModule {
483475
unreachable!()
484476
}
485477

@@ -490,7 +482,9 @@ impl WriteBackendMethods for GccCodegenBackend {
490482
module: ModuleCodegen<Self::Module>,
491483
config: &ModuleConfig,
492484
) -> CompiledModule {
493-
back::write::codegen(cgcx, prof, shared_emitter, module, config)
485+
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
486+
let dcx = dcx.handle();
487+
back::write::codegen(cgcx, prof, dcx, module, config)
494488
}
495489

496490
fn serialize_module(_module: Self::Module, _is_thin: bool) -> Self::ModuleBuffer {

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_codegen_ssa::back::write::{
1212
CodegenContext, FatLtoInput, SharedEmitter, TargetMachineFactoryFn,
1313
};
1414
use rustc_codegen_ssa::traits::*;
15-
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file};
15+
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, ModuleKind, looks_like_rust_object_file};
1616
use rustc_data_structures::fx::FxHashMap;
1717
use rustc_data_structures::memmap::Mmap;
1818
use rustc_data_structures::profiling::SelfProfilerRef;
@@ -24,7 +24,8 @@ use rustc_session::config::{self, Lto};
2424
use tracing::{debug, info};
2525

2626
use crate::back::write::{
27-
self, CodegenDiagnosticsStage, DiagnosticHandlers, bitcode_section_name, save_temp_bitcode,
27+
self, CodegenDiagnosticsStage, DiagnosticHandlers, bitcode_section_name, codegen,
28+
save_temp_bitcode,
2829
};
2930
use crate::errors::{LlvmError, LtoBitcodeFromRlib};
3031
use crate::llvm::{self, build_string};
@@ -709,13 +710,13 @@ impl ModuleBufferMethods for ModuleBuffer {
709710
}
710711
}
711712

712-
pub(crate) fn optimize_thin_module(
713+
pub(crate) fn optimize_and_codegen_thin_module(
713714
cgcx: &CodegenContext,
714715
prof: &SelfProfilerRef,
715716
shared_emitter: &SharedEmitter,
716717
tm_factory: TargetMachineFactoryFn<LlvmCodegenBackend>,
717718
thin_module: ThinModule<LlvmCodegenBackend>,
718-
) -> ModuleCodegen<ModuleLlvm> {
719+
) -> CompiledModule {
719720
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
720721
let dcx = dcx.handle();
721722

@@ -794,7 +795,7 @@ pub(crate) fn optimize_thin_module(
794795
save_temp_bitcode(cgcx, &module, "thin-lto-after-pm");
795796
}
796797
}
797-
module
798+
codegen(cgcx, prof, shared_emitter, module, &cgcx.module_config)
798799
}
799800

800801
/// Maps LLVM module identifiers to their corresponding LLVM LTO cache keys

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,13 @@ pub(crate) fn save_temp_bitcode(
335335
&module.name,
336336
cgcx.invocation_temp.as_deref(),
337337
);
338-
write_bitcode_to_file(module, &path)
338+
write_bitcode_to_file(&module.module_llvm, &path)
339339
}
340340

341-
fn write_bitcode_to_file(module: &ModuleCodegen<ModuleLlvm>, path: &Path) {
341+
fn write_bitcode_to_file(module: &ModuleLlvm, path: &Path) {
342342
unsafe {
343343
let path = path_to_c_string(&path);
344-
let llmod = module.module_llvm.llmod();
344+
let llmod = module.llmod();
345345
llvm::LLVMWriteBitcodeToFile(llmod, path.as_ptr());
346346
}
347347
}
@@ -905,13 +905,8 @@ pub(crate) fn optimize(
905905
let _handlers =
906906
DiagnosticHandlers::new(cgcx, shared_emitter, llcx, module, CodegenDiagnosticsStage::Opt);
907907

908-
if config.emit_no_opt_bc {
909-
let out = cgcx.output_filenames.temp_path_ext_for_cgu(
910-
"no-opt.bc",
911-
&module.name,
912-
cgcx.invocation_temp.as_deref(),
913-
);
914-
write_bitcode_to_file(module, &out)
908+
if module.kind == ModuleKind::Regular {
909+
save_temp_bitcode(cgcx, module, "no-opt");
915910
}
916911

917912
// FIXME(ZuseZ4): support SanitizeHWAddress and prevent illegal/unsupported opts

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,18 @@ pub(crate) use macros::TryFromU32;
7979
#[derive(Clone)]
8080
pub struct LlvmCodegenBackend(());
8181

82-
struct TimeTraceProfiler {
83-
enabled: bool,
84-
}
82+
struct TimeTraceProfiler {}
8583

8684
impl TimeTraceProfiler {
87-
fn new(enabled: bool) -> Self {
88-
if enabled {
89-
unsafe { llvm::LLVMRustTimeTraceProfilerInitialize() }
90-
}
91-
TimeTraceProfiler { enabled }
85+
fn new() -> Self {
86+
unsafe { llvm::LLVMRustTimeTraceProfilerInitialize() }
87+
TimeTraceProfiler {}
9288
}
9389
}
9490

9591
impl Drop for TimeTraceProfiler {
9692
fn drop(&mut self) {
97-
if self.enabled {
98-
unsafe { llvm::LLVMRustTimeTraceProfilerFinishThread() }
99-
}
93+
unsafe { llvm::LLVMRustTimeTraceProfilerFinishThread() }
10094
}
10195
}
10296

@@ -122,54 +116,33 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
122116
) -> (ModuleCodegen<ModuleLlvm>, u64) {
123117
base::compile_codegen_unit(tcx, cgu_name)
124118
}
125-
fn target_machine_factory(
126-
&self,
127-
sess: &Session,
128-
optlvl: OptLevel,
129-
target_features: &[String],
130-
) -> TargetMachineFactoryFn<Self> {
131-
back::write::target_machine_factory(sess, optlvl, target_features)
132-
}
133-
134-
fn spawn_named_thread<F, T>(
135-
time_trace: bool,
136-
name: String,
137-
f: F,
138-
) -> std::io::Result<std::thread::JoinHandle<T>>
139-
where
140-
F: FnOnce() -> T,
141-
F: Send + 'static,
142-
T: Send + 'static,
143-
{
144-
std::thread::Builder::new().name(name).spawn(move || {
145-
let _profiler = TimeTraceProfiler::new(time_trace);
146-
f()
147-
})
148-
}
149119
}
150120

151121
impl WriteBackendMethods for LlvmCodegenBackend {
152122
type Module = ModuleLlvm;
153123
type ModuleBuffer = back::lto::ModuleBuffer;
154124
type TargetMachine = OwnedTargetMachine;
155125
type ThinData = back::lto::ThinData;
156-
fn print_pass_timings(&self) {
157-
let timings = llvm::build_string(|s| unsafe { llvm::LLVMRustPrintPassTimings(s) }).unwrap();
158-
print!("{timings}");
126+
fn thread_profiler() -> Box<dyn Any> {
127+
Box::new(TimeTraceProfiler::new())
159128
}
160-
fn print_statistics(&self) {
161-
let stats = llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatistics(s) }).unwrap();
162-
print!("{stats}");
129+
fn target_machine_factory(
130+
&self,
131+
sess: &Session,
132+
optlvl: OptLevel,
133+
target_features: &[String],
134+
) -> TargetMachineFactoryFn<Self> {
135+
back::write::target_machine_factory(sess, optlvl, target_features)
163136
}
164-
fn run_and_optimize_fat_lto(
137+
fn optimize_and_codegen_fat_lto(
165138
cgcx: &CodegenContext,
166139
prof: &SelfProfilerRef,
167140
shared_emitter: &SharedEmitter,
168141
tm_factory: TargetMachineFactoryFn<LlvmCodegenBackend>,
169142
exported_symbols_for_lto: &[String],
170143
each_linked_rlib_for_lto: &[PathBuf],
171144
modules: Vec<FatLtoInput<Self>>,
172-
) -> ModuleCodegen<Self::Module> {
145+
) -> CompiledModule {
173146
let mut module = back::lto::run_fat(
174147
cgcx,
175148
prof,
@@ -184,7 +157,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
184157
let dcx = dcx.handle();
185158
back::lto::run_pass_manager(cgcx, prof, dcx, &mut module, false);
186159

187-
module
160+
back::write::codegen(cgcx, prof, shared_emitter, module, &cgcx.module_config)
188161
}
189162
fn run_thin_lto(
190163
cgcx: &CodegenContext,
@@ -214,14 +187,14 @@ impl WriteBackendMethods for LlvmCodegenBackend {
214187
) {
215188
back::write::optimize(cgcx, prof, shared_emitter, module, config)
216189
}
217-
fn optimize_thin(
190+
fn optimize_and_codegen_thin(
218191
cgcx: &CodegenContext,
219192
prof: &SelfProfilerRef,
220193
shared_emitter: &SharedEmitter,
221194
tm_factory: TargetMachineFactoryFn<LlvmCodegenBackend>,
222195
thin: ThinModule<Self>,
223-
) -> ModuleCodegen<Self::Module> {
224-
back::lto::optimize_thin_module(cgcx, prof, shared_emitter, tm_factory, thin)
196+
) -> CompiledModule {
197+
back::lto::optimize_and_codegen_thin_module(cgcx, prof, shared_emitter, tm_factory, thin)
225198
}
226199
fn codegen(
227200
cgcx: &CodegenContext,
@@ -389,6 +362,16 @@ impl CodegenBackend for LlvmCodegenBackend {
389362
(compiled_modules, work_products)
390363
}
391364

365+
fn print_pass_timings(&self) {
366+
let timings = llvm::build_string(|s| unsafe { llvm::LLVMRustPrintPassTimings(s) }).unwrap();
367+
print!("{timings}");
368+
}
369+
370+
fn print_statistics(&self) {
371+
let stats = llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatistics(s) }).unwrap();
372+
print!("{stats}");
373+
}
374+
392375
fn link(
393376
&self,
394377
sess: &Session,

0 commit comments

Comments
 (0)