Skip to content

Commit c0dc0c6

Browse files
committed
Store individual output file name with every PrintRequest
1 parent 11dcd1d commit c0dc0c6

File tree

6 files changed

+61
-56
lines changed

6 files changed

+61
-56
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_metadata::EncodedMetadata;
4040
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4141
use rustc_middle::query::Providers;
4242
use rustc_middle::ty::TyCtxt;
43-
use rustc_session::config::{OptLevel, OutputFilenames, PrintRequest};
43+
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4444
use rustc_session::Session;
4545
use rustc_span::symbol::Symbol;
4646

@@ -262,9 +262,9 @@ impl CodegenBackend for LlvmCodegenBackend {
262262
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true)
263263
}
264264

265-
fn print(&self, req: PrintRequest, sess: &Session) {
266-
match req {
267-
PrintRequest::RelocationModels => {
265+
fn print(&self, req: &PrintRequest, sess: &Session) {
266+
match req.kind {
267+
PrintKind::RelocationModels => {
268268
println!("Available relocation models:");
269269
for name in &[
270270
"static",
@@ -280,21 +280,21 @@ impl CodegenBackend for LlvmCodegenBackend {
280280
}
281281
println!();
282282
}
283-
PrintRequest::CodeModels => {
283+
PrintKind::CodeModels => {
284284
println!("Available code models:");
285285
for name in &["tiny", "small", "kernel", "medium", "large"] {
286286
println!(" {}", name);
287287
}
288288
println!();
289289
}
290-
PrintRequest::TlsModels => {
290+
PrintKind::TlsModels => {
291291
println!("Available TLS models:");
292292
for name in &["global-dynamic", "local-dynamic", "initial-exec", "local-exec"] {
293293
println!(" {}", name);
294294
}
295295
println!();
296296
}
297-
PrintRequest::StackProtectorStrategies => {
297+
PrintKind::StackProtectorStrategies => {
298298
println!(
299299
r#"Available stack protector strategies:
300300
all
@@ -319,7 +319,7 @@ impl CodegenBackend for LlvmCodegenBackend {
319319
"#
320320
);
321321
}
322-
req => llvm_util::print(req, sess),
322+
_other => llvm_util::print(req, sess),
323323
}
324324
}
325325

compiler/rustc_codegen_llvm/src/llvm_util.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1212
use rustc_data_structures::small_c_str::SmallCStr;
1313
use rustc_fs_util::path_to_c_string;
1414
use rustc_middle::bug;
15-
use rustc_session::config::PrintRequest;
15+
use rustc_session::config::{PrintKind, PrintRequest};
1616
use rustc_session::Session;
1717
use rustc_span::symbol::Symbol;
1818
use rustc_target::spec::{MergeFunctions, PanicStrategy};
@@ -400,19 +400,19 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
400400
println!("and may be renamed or removed in a future version of LLVM or rustc.\n");
401401
}
402402

403-
pub(crate) fn print(req: PrintRequest, sess: &Session) {
403+
pub(crate) fn print(req: &PrintRequest, sess: &Session) {
404404
require_inited();
405405
let tm = create_informational_target_machine(sess);
406-
match req {
407-
PrintRequest::TargetCPUs => {
406+
match req.kind {
407+
PrintKind::TargetCPUs => {
408408
// SAFETY generate a C compatible string from a byte slice to pass
409409
// the target CPU name into LLVM, the lifetime of the reference is
410410
// at least as long as the C function
411411
let cpu_cstring = CString::new(handle_native(sess.target.cpu.as_ref()))
412412
.unwrap_or_else(|e| bug!("failed to convert to cstring: {}", e));
413413
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, cpu_cstring.as_ptr()) };
414414
}
415-
PrintRequest::TargetFeatures => print_target_features(sess, tm),
415+
PrintKind::TargetFeatures => print_target_features(sess, tm),
416416
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
417417
}
418418
}

compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
1313
use rustc_middle::middle::dependency_format::Linkage;
1414
use rustc_middle::middle::exported_symbols::SymbolExportKind;
1515
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, Strip};
16-
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SplitDwarfKind};
16+
use rustc_session::config::{OutputFilenames, OutputType, PrintKind, SplitDwarfKind};
1717
use rustc_session::cstore::DllImport;
1818
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
1919
use rustc_session::search_paths::PathKind;
@@ -596,7 +596,7 @@ fn link_staticlib<'a>(
596596

597597
all_native_libs.extend_from_slice(&codegen_results.crate_info.used_libraries);
598598

599-
if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
599+
if sess.opts.prints.iter().any(|print| print.kind == PrintKind::NativeStaticLibs) {
600600
print_native_static_libs(sess, &all_native_libs, &all_rust_dylibs);
601601
}
602602

@@ -744,7 +744,7 @@ fn link_natively<'a>(
744744
cmd.env_remove(k.as_ref());
745745
}
746746

747-
if sess.opts.prints.contains(&PrintRequest::LinkArgs) {
747+
if sess.opts.prints.iter().any(|print| print.kind == PrintKind::LinkArgs) {
748748
println!("{:?}", &cmd);
749749
}
750750

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub trait CodegenBackend {
6161
fn locale_resource(&self) -> &'static str;
6262

6363
fn init(&self, _sess: &Session) {}
64-
fn print(&self, _req: PrintRequest, _sess: &Session) {}
64+
fn print(&self, _req: &PrintRequest, _sess: &Session) {}
6565
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<Symbol> {
6666
vec![]
6767
}

compiler/rustc_driver_impl/src/lib.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ use rustc_interface::{interface, Queries};
3535
use rustc_lint::LintStore;
3636
use rustc_metadata::locator;
3737
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
38-
use rustc_session::config::{
39-
ErrorOutputType, Input, OutFileName, OutputType, PrintRequest, TrimmedDefPaths,
40-
};
38+
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
4139
use rustc_session::cstore::MetadataLoader;
4240
use rustc_session::getopts::{self, Matches};
4341
use rustc_session::lint::{Lint, LintId};
@@ -714,10 +712,10 @@ fn print_crate_info(
714712
sess: &Session,
715713
parse_attrs: bool,
716714
) -> Compilation {
717-
use rustc_session::config::PrintRequest::*;
715+
use rustc_session::config::PrintKind::*;
718716
// NativeStaticLibs and LinkArgs are special - printed during linking
719717
// (empty iterator returns true)
720-
if sess.opts.prints.iter().all(|&p| p == NativeStaticLibs || p == LinkArgs) {
718+
if sess.opts.prints.iter().all(|p| p.kind == NativeStaticLibs || p.kind == LinkArgs) {
721719
return Compilation::Continue;
722720
}
723721

@@ -734,7 +732,7 @@ fn print_crate_info(
734732
None
735733
};
736734
for req in &sess.opts.prints {
737-
match *req {
735+
match req.kind {
738736
TargetList => {
739737
let mut targets = rustc_target::spec::TARGETS.to_vec();
740738
targets.sort_unstable();
@@ -761,7 +759,7 @@ fn print_crate_info(
761759
};
762760
let t_outputs = rustc_interface::util::build_output_filenames(attrs, sess);
763761
let id = rustc_session::output::find_crate_name(sess, attrs);
764-
if *req == PrintRequest::CrateName {
762+
if req.kind == CrateName {
765763
safe_println!("{id}");
766764
continue;
767765
}
@@ -817,7 +815,7 @@ fn print_crate_info(
817815
| TargetCPUs
818816
| StackProtectorStrategies
819817
| TargetFeatures => {
820-
codegen_backend.print(*req, sess);
818+
codegen_backend.print(req, sess);
821819
}
822820
// Any output here interferes with Cargo's parsing of other printed output
823821
NativeStaticLibs => {}

compiler/rustc_session/src/config.rs

+38-31
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,14 @@ impl ExternEntry {
710710
}
711711
}
712712

713+
#[derive(Clone, PartialEq, Debug)]
714+
pub struct PrintRequest {
715+
pub kind: PrintKind,
716+
pub out: OutFileName,
717+
}
718+
713719
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
714-
pub enum PrintRequest {
720+
pub enum PrintKind {
715721
FileNames,
716722
Sysroot,
717723
TargetLibdir,
@@ -2091,68 +2097,69 @@ fn collect_print_requests(
20912097
) -> Vec<PrintRequest> {
20922098
let mut prints = Vec::<PrintRequest>::new();
20932099
if cg.target_cpu.as_ref().is_some_and(|s| s == "help") {
2094-
prints.push(PrintRequest::TargetCPUs);
2100+
prints.push(PrintRequest { kind: PrintKind::TargetCPUs, out: OutFileName::Stdout });
20952101
cg.target_cpu = None;
20962102
};
20972103
if cg.target_feature == "help" {
2098-
prints.push(PrintRequest::TargetFeatures);
2104+
prints.push(PrintRequest { kind: PrintKind::TargetFeatures, out: OutFileName::Stdout });
20992105
cg.target_feature = String::new();
21002106
}
21012107

2102-
const PRINT_REQUESTS: &[(&str, PrintRequest)] = &[
2103-
("crate-name", PrintRequest::CrateName),
2104-
("file-names", PrintRequest::FileNames),
2105-
("sysroot", PrintRequest::Sysroot),
2106-
("target-libdir", PrintRequest::TargetLibdir),
2107-
("cfg", PrintRequest::Cfg),
2108-
("calling-conventions", PrintRequest::CallingConventions),
2109-
("target-list", PrintRequest::TargetList),
2110-
("target-cpus", PrintRequest::TargetCPUs),
2111-
("target-features", PrintRequest::TargetFeatures),
2112-
("relocation-models", PrintRequest::RelocationModels),
2113-
("code-models", PrintRequest::CodeModels),
2114-
("tls-models", PrintRequest::TlsModels),
2115-
("native-static-libs", PrintRequest::NativeStaticLibs),
2116-
("stack-protector-strategies", PrintRequest::StackProtectorStrategies),
2117-
("target-spec-json", PrintRequest::TargetSpec),
2118-
("all-target-specs-json", PrintRequest::AllTargetSpecs),
2119-
("link-args", PrintRequest::LinkArgs),
2120-
("split-debuginfo", PrintRequest::SplitDebuginfo),
2121-
("deployment-target", PrintRequest::DeploymentTarget),
2108+
const PRINT_KINDS: &[(&str, PrintKind)] = &[
2109+
("crate-name", PrintKind::CrateName),
2110+
("file-names", PrintKind::FileNames),
2111+
("sysroot", PrintKind::Sysroot),
2112+
("target-libdir", PrintKind::TargetLibdir),
2113+
("cfg", PrintKind::Cfg),
2114+
("calling-conventions", PrintKind::CallingConventions),
2115+
("target-list", PrintKind::TargetList),
2116+
("target-cpus", PrintKind::TargetCPUs),
2117+
("target-features", PrintKind::TargetFeatures),
2118+
("relocation-models", PrintKind::RelocationModels),
2119+
("code-models", PrintKind::CodeModels),
2120+
("tls-models", PrintKind::TlsModels),
2121+
("native-static-libs", PrintKind::NativeStaticLibs),
2122+
("stack-protector-strategies", PrintKind::StackProtectorStrategies),
2123+
("target-spec-json", PrintKind::TargetSpec),
2124+
("all-target-specs-json", PrintKind::AllTargetSpecs),
2125+
("link-args", PrintKind::LinkArgs),
2126+
("split-debuginfo", PrintKind::SplitDebuginfo),
2127+
("deployment-target", PrintKind::DeploymentTarget),
21222128
];
21232129

21242130
prints.extend(matches.opt_strs("print").into_iter().map(|req| {
2125-
match PRINT_REQUESTS.iter().find(|&&(name, _)| name == req) {
2126-
Some((_, PrintRequest::TargetSpec)) => {
2131+
let kind = match PRINT_KINDS.iter().find(|&&(name, _)| name == req) {
2132+
Some((_, PrintKind::TargetSpec)) => {
21272133
if unstable_opts.unstable_options {
2128-
PrintRequest::TargetSpec
2134+
PrintKind::TargetSpec
21292135
} else {
21302136
handler.early_error(
21312137
"the `-Z unstable-options` flag must also be passed to \
21322138
enable the target-spec-json print option",
21332139
);
21342140
}
21352141
}
2136-
Some((_, PrintRequest::AllTargetSpecs)) => {
2142+
Some((_, PrintKind::AllTargetSpecs)) => {
21372143
if unstable_opts.unstable_options {
2138-
PrintRequest::AllTargetSpecs
2144+
PrintKind::AllTargetSpecs
21392145
} else {
21402146
handler.early_error(
21412147
"the `-Z unstable-options` flag must also be passed to \
21422148
enable the all-target-specs-json print option",
21432149
);
21442150
}
21452151
}
2146-
Some(&(_, print_request)) => print_request,
2152+
Some(&(_, print_kind)) => print_kind,
21472153
None => {
21482154
let prints =
2149-
PRINT_REQUESTS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
2155+
PRINT_KINDS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
21502156
let prints = prints.join(", ");
21512157
handler.early_error(format!(
21522158
"unknown print request `{req}`. Valid print requests are: {prints}"
21532159
));
21542160
}
2155-
}
2161+
};
2162+
PrintRequest { kind, out: OutFileName::Stdout }
21562163
}));
21572164

21582165
prints

0 commit comments

Comments
 (0)