Rename rustc command variable to compiler

This commit is contained in:
Zalathar
2026-01-27 16:23:50 +11:00
parent 0b42f38dc7
commit 40d4d322b8
+71 -70
View File
@@ -1611,16 +1611,16 @@ fn make_compile_args(
) -> Command {
// FIXME(Zalathar): We should have a cleaner distinction between
// `rustc` flags, `rustdoc` flags, and flags shared by both.
let mut rustc = match compiler_kind {
let mut compiler = match compiler_kind {
CompilerKind::Rustc => Command::new(&self.config.rustc_path),
CompilerKind::Rustdoc => {
Command::new(&self.config.rustdoc_path.clone().expect("no rustdoc built yet"))
}
};
rustc.arg(input_file);
compiler.arg(input_file);
// Use a single thread for efficiency and a deterministic error message order
rustc.arg("-Zthreads=1");
compiler.arg("-Zthreads=1");
// Hide libstd sources from ui tests to make sure we generate the stderr
// output that users will see.
@@ -1630,19 +1630,19 @@ fn make_compile_args(
// This also has the benefit of more effectively normalizing output between different
// compilers, so that we don't have to know the `/rustc/$sha` output to normalize after the
// fact.
rustc.arg("-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX");
rustc.arg("-Ztranslate-remapped-path-to-local-path=no");
compiler.arg("-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX");
compiler.arg("-Ztranslate-remapped-path-to-local-path=no");
// Hide Cargo dependency sources from ui tests to make sure the error message doesn't
// change depending on whether $CARGO_HOME is remapped or not. If this is not present,
// when $CARGO_HOME is remapped the source won't be shown, and when it's not remapped the
// source will be shown, causing a blessing hell.
rustc.arg("-Z").arg(format!(
compiler.arg("-Z").arg(format!(
"ignore-directory-in-diagnostics-source-blocks={}",
home::cargo_home().expect("failed to find cargo home").to_str().unwrap()
));
// Similarly, vendored sources shouldn't be shown when running from a dist tarball.
rustc.arg("-Z").arg(format!(
compiler.arg("-Z").arg(format!(
"ignore-directory-in-diagnostics-source-blocks={}",
self.config.src_root.join("vendor"),
));
@@ -1654,12 +1654,12 @@ fn make_compile_args(
&& !self.config.host_rustcflags.iter().any(|flag| flag == "--sysroot")
{
// In stage 0, make sure we use `stage0-sysroot` instead of the bootstrap sysroot.
rustc.arg("--sysroot").arg(&self.config.sysroot_base);
compiler.arg("--sysroot").arg(&self.config.sysroot_base);
}
// If the provided codegen backend is not LLVM, we need to pass it.
if let Some(ref backend) = self.config.override_codegen_backend {
rustc.arg(format!("-Zcodegen-backend={}", backend));
compiler.arg(format!("-Zcodegen-backend={}", backend));
}
// Optionally prevent default --target if specified in test compile-flags.
@@ -1669,18 +1669,18 @@ fn make_compile_args(
let target =
if self.props.force_host { &*self.config.host } else { &*self.config.target };
rustc.arg(&format!("--target={}", target));
compiler.arg(&format!("--target={}", target));
}
self.set_revision_flags(&mut rustc);
self.set_revision_flags(&mut compiler);
if compiler_kind == CompilerKind::Rustc {
if let Some(ref incremental_dir) = self.props.incremental_dir {
rustc.args(&["-C", &format!("incremental={}", incremental_dir)]);
rustc.args(&["-Z", "incremental-verify-ich"]);
compiler.args(&["-C", &format!("incremental={}", incremental_dir)]);
compiler.args(&["-Z", "incremental-verify-ich"]);
}
if self.config.mode == TestMode::CodegenUnits {
rustc.args(&["-Z", "human_readable_cgu_names"]);
compiler.args(&["-Z", "human_readable_cgu_names"]);
}
}
@@ -1698,7 +1698,7 @@ fn make_compile_args(
.iter()
.any(|arg| arg == "-O" || arg.contains("opt-level"))
{
rustc.arg("-O");
compiler.arg("-O");
}
}
TestMode::DebugInfo => { /* debuginfo tests must be unoptimized */ }
@@ -1709,7 +1709,7 @@ fn make_compile_args(
// compile flags (below) or in per-test `compile-flags`.
}
_ => {
rustc.arg("-O");
compiler.arg("-O");
}
}
}
@@ -1730,24 +1730,24 @@ fn make_compile_args(
if self.props.error_patterns.is_empty()
&& self.props.regex_error_patterns.is_empty()
{
rustc.args(&["--error-format", "json"]);
rustc.args(&["--json", "future-incompat"]);
compiler.args(&["--error-format", "json"]);
compiler.args(&["--json", "future-incompat"]);
}
rustc.arg("-Zui-testing");
rustc.arg("-Zdeduplicate-diagnostics=no");
compiler.arg("-Zui-testing");
compiler.arg("-Zdeduplicate-diagnostics=no");
}
TestMode::Ui => {
if !self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")) {
rustc.args(&["--error-format", "json"]);
rustc.args(&["--json", "future-incompat"]);
compiler.args(&["--error-format", "json"]);
compiler.args(&["--json", "future-incompat"]);
}
rustc.arg("-Ccodegen-units=1");
compiler.arg("-Ccodegen-units=1");
// Hide line numbers to reduce churn
rustc.arg("-Zui-testing");
rustc.arg("-Zdeduplicate-diagnostics=no");
rustc.arg("-Zwrite-long-types-to-disk=no");
compiler.arg("-Zui-testing");
compiler.arg("-Zdeduplicate-diagnostics=no");
compiler.arg("-Zwrite-long-types-to-disk=no");
// FIXME: use this for other modes too, for perf?
rustc.arg("-Cstrip=debuginfo");
compiler.arg("-Cstrip=debuginfo");
}
TestMode::MirOpt => {
// We check passes under test to minimize the mir-opt test dump
@@ -1759,7 +1759,7 @@ fn make_compile_args(
"-Zdump-mir=all".to_string()
};
rustc.args(&[
compiler.args(&[
"-Copt-level=1",
&zdump_arg,
"-Zvalidate-mir",
@@ -1769,45 +1769,46 @@ fn make_compile_args(
"--crate-type=rlib",
]);
if let Some(pass) = &self.props.mir_unit_test {
rustc.args(&["-Zmir-opt-level=0", &format!("-Zmir-enable-passes=+{}", pass)]);
compiler
.args(&["-Zmir-opt-level=0", &format!("-Zmir-enable-passes=+{}", pass)]);
} else {
rustc.args(&[
compiler.args(&[
"-Zmir-opt-level=4",
"-Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals",
]);
}
set_mir_dump_dir(&mut rustc);
set_mir_dump_dir(&mut compiler);
}
TestMode::CoverageMap => {
rustc.arg("-Cinstrument-coverage");
compiler.arg("-Cinstrument-coverage");
// These tests only compile to LLVM IR, so they don't need the
// profiler runtime to be present.
rustc.arg("-Zno-profiler-runtime");
compiler.arg("-Zno-profiler-runtime");
// Coverage mappings are sensitive to MIR optimizations, and
// the current snapshots assume `opt-level=2` unless overridden
// by `compile-flags`.
rustc.arg("-Copt-level=2");
compiler.arg("-Copt-level=2");
}
TestMode::CoverageRun => {
rustc.arg("-Cinstrument-coverage");
compiler.arg("-Cinstrument-coverage");
// Coverage reports are sometimes sensitive to optimizations,
// and the current snapshots assume `opt-level=2` unless
// overridden by `compile-flags`.
rustc.arg("-Copt-level=2");
compiler.arg("-Copt-level=2");
}
TestMode::Assembly | TestMode::Codegen => {
rustc.arg("-Cdebug-assertions=no");
compiler.arg("-Cdebug-assertions=no");
// For assembly and codegen tests, we want to use the same order
// of the items of a codegen unit as the source order, so that
// we can compare the output with the source code through filecheck.
rustc.arg("-Zcodegen-source-order");
compiler.arg("-Zcodegen-source-order");
}
TestMode::Crashes => {
set_mir_dump_dir(&mut rustc);
set_mir_dump_dir(&mut compiler);
}
TestMode::CodegenUnits => {
rustc.arg("-Zprint-mono-items");
compiler.arg("-Zprint-mono-items");
}
TestMode::Pretty
| TestMode::DebugInfo
@@ -1820,7 +1821,7 @@ fn make_compile_args(
}
if self.props.remap_src_base {
rustc.arg(format!(
compiler.arg(format!(
"--remap-path-prefix={}={}",
self.config.src_test_suite_root, FAKE_SRC_BASE,
));
@@ -1830,19 +1831,19 @@ fn make_compile_args(
match emit {
Emit::None => {}
Emit::Metadata => {
rustc.args(&["--emit", "metadata"]);
compiler.args(&["--emit", "metadata"]);
}
Emit::LlvmIr => {
rustc.args(&["--emit", "llvm-ir"]);
compiler.args(&["--emit", "llvm-ir"]);
}
Emit::Mir => {
rustc.args(&["--emit", "mir"]);
compiler.args(&["--emit", "mir"]);
}
Emit::Asm => {
rustc.args(&["--emit", "asm"]);
compiler.args(&["--emit", "asm"]);
}
Emit::LinkArgsAsm => {
rustc.args(&["-Clink-args=--emit=asm"]);
compiler.args(&["-Clink-args=--emit=asm"]);
}
}
}
@@ -1851,7 +1852,7 @@ fn make_compile_args(
if self.config.target == "wasm32-unknown-unknown" || self.is_vxworks_pure_static() {
// rustc.arg("-g"); // get any backtrace at all on errors
} else if !self.props.no_prefer_dynamic {
rustc.args(&["-C", "prefer-dynamic"]);
compiler.args(&["-C", "prefer-dynamic"]);
}
}
@@ -1860,37 +1861,37 @@ fn make_compile_args(
// avoid a compiler warning about `--out-dir` being ignored.
_ if self.props.compile_flags.iter().any(|flag| flag == "-o") => {}
TargetLocation::ThisFile(path) => {
rustc.arg("-o").arg(path);
compiler.arg("-o").arg(path);
}
TargetLocation::ThisDirectory(path) => match compiler_kind {
CompilerKind::Rustdoc => {
// `rustdoc` uses `-o` for the output directory.
rustc.arg("-o").arg(path);
compiler.arg("-o").arg(path);
}
CompilerKind::Rustc => {
rustc.arg("--out-dir").arg(path);
compiler.arg("--out-dir").arg(path);
}
},
}
match self.config.compare_mode {
Some(CompareMode::Polonius) => {
rustc.args(&["-Zpolonius=next"]);
compiler.args(&["-Zpolonius=next"]);
}
Some(CompareMode::NextSolver) => {
rustc.args(&["-Znext-solver"]);
compiler.args(&["-Znext-solver"]);
}
Some(CompareMode::NextSolverCoherence) => {
rustc.args(&["-Znext-solver=coherence"]);
compiler.args(&["-Znext-solver=coherence"]);
}
Some(CompareMode::SplitDwarf) if self.config.target.contains("windows") => {
rustc.args(&["-Csplit-debuginfo=unpacked", "-Zunstable-options"]);
compiler.args(&["-Csplit-debuginfo=unpacked", "-Zunstable-options"]);
}
Some(CompareMode::SplitDwarf) => {
rustc.args(&["-Csplit-debuginfo=unpacked"]);
compiler.args(&["-Csplit-debuginfo=unpacked"]);
}
Some(CompareMode::SplitDwarfSingle) => {
rustc.args(&["-Csplit-debuginfo=packed"]);
compiler.args(&["-Csplit-debuginfo=packed"]);
}
None => {}
}
@@ -1899,44 +1900,44 @@ fn make_compile_args(
// overwrite this.
// Don't allow `unused_attributes` since these are usually actual mistakes, rather than just unused code.
if let AllowUnused::Yes = allow_unused {
rustc.args(&["-A", "unused", "-W", "unused_attributes"]);
compiler.args(&["-A", "unused", "-W", "unused_attributes"]);
}
// Allow tests to use internal features.
rustc.args(&["-A", "internal_features"]);
compiler.args(&["-A", "internal_features"]);
// Allow tests to have unused parens and braces.
// Add #![deny(unused_parens, unused_braces)] to the test file if you want to
// test that these lints are working.
rustc.args(&["-A", "unused_parens"]);
rustc.args(&["-A", "unused_braces"]);
compiler.args(&["-A", "unused_parens"]);
compiler.args(&["-A", "unused_braces"]);
if self.props.force_host {
self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags);
self.maybe_add_external_args(&mut compiler, &self.config.host_rustcflags);
if compiler_kind == CompilerKind::Rustc
&& let Some(ref linker) = self.config.host_linker
{
rustc.arg(format!("-Clinker={linker}"));
compiler.arg(format!("-Clinker={linker}"));
}
} else {
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
self.maybe_add_external_args(&mut compiler, &self.config.target_rustcflags);
if compiler_kind == CompilerKind::Rustc
&& let Some(ref linker) = self.config.target_linker
{
rustc.arg(format!("-Clinker={linker}"));
compiler.arg(format!("-Clinker={linker}"));
}
}
// Use dynamic musl for tests because static doesn't allow creating dylibs
if self.config.host.contains("musl") || self.is_vxworks_pure_dynamic() {
rustc.arg("-Ctarget-feature=-crt-static");
compiler.arg("-Ctarget-feature=-crt-static");
}
if let LinkToAux::Yes = link_to_aux {
// if we pass an `-L` argument to a directory that doesn't exist,
// macOS ld emits warnings which disrupt the .stderr files
if self.has_aux_dir() {
rustc.arg("-L").arg(self.aux_output_dir_name());
compiler.arg("-L").arg(self.aux_output_dir_name());
}
}
@@ -1950,13 +1951,13 @@ fn make_compile_args(
//
// `minicore` requires `#![no_std]` and `#![no_core]`, which means no unwinding panics.
if self.props.add_minicore {
rustc.arg("-Cpanic=abort");
rustc.arg("-Cforce-unwind-tables=yes");
compiler.arg("-Cpanic=abort");
compiler.arg("-Cforce-unwind-tables=yes");
}
rustc.args(&self.props.compile_flags);
compiler.args(&self.props.compile_flags);
rustc
compiler
}
fn make_exe_name(&self) -> Utf8PathBuf {