Skip to content

Commit e275af4

Browse files
committed
Merge LocalToolchain and Compiler and rename it to just Toolchain
There was no need for two structs, the `is_nightly` attribute is unused and it was basically the same as `LocalToolchain`.
1 parent 8af0277 commit e275af4

File tree

7 files changed

+77
-85
lines changed

7 files changed

+77
-85
lines changed

collector/src/bin/collector.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use collector::compile::execute::profiler::{ProfileProcessor, Profiler};
3030
use collector::runtime::{
3131
bench_runtime, runtime_benchmark_dir, BenchmarkFilter, CargoIsolationMode,
3232
};
33-
use collector::toolchain::{get_local_toolchain, Compiler, Sysroot};
33+
use collector::toolchain::{get_local_toolchain, Sysroot, Toolchain};
3434

3535
fn n_normal_benchmarks_remaining(n: usize) -> String {
3636
let suffix = if n == 1 { "" } else { "s" };
@@ -66,7 +66,7 @@ fn bench(
6666
mut conn: Box<dyn Connection>,
6767
profiles: &[Profile],
6868
scenarios: &[Scenario],
69-
compiler: Compiler<'_>,
69+
toolchain: &Toolchain,
7070
benchmarks: &[Benchmark],
7171
iterations: Option<usize>,
7272
is_self_profile: bool,
@@ -75,7 +75,7 @@ fn bench(
7575
let mut errors = BenchmarkErrors::new();
7676
eprintln!(
7777
"Benchmarking {} for triple {}",
78-
collector.artifact_id, compiler.triple
78+
collector.artifact_id, toolchain.triple
7979
);
8080

8181
if is_self_profile {
@@ -145,7 +145,7 @@ fn bench(
145145
n_normal_benchmarks_remaining(benchmarks.len() - nth_benchmark)
146146
)
147147
},
148-
&|processor| benchmark.measure(processor, profiles, scenarios, compiler, iterations),
148+
&|processor| benchmark.measure(processor, profiles, scenarios, toolchain, iterations),
149149
)
150150
}
151151

@@ -155,7 +155,7 @@ fn bench(
155155
&BenchmarkName("rustc".to_string()),
156156
Category::Primary,
157157
&|| eprintln!("Special benchmark commencing (due to `--bench-rustc`)"),
158-
&|processor| processor.measure_rustc(compiler).context("measure rustc"),
158+
&|processor| processor.measure_rustc(toolchain).context("measure rustc"),
159159
);
160160
}
161161

@@ -332,16 +332,15 @@ fn cg_annotate(cgout: &Path, path: &Path) -> anyhow::Result<()> {
332332

333333
#[allow(clippy::too_many_arguments)]
334334
fn profile(
335-
compiler: Compiler,
336-
id: &str,
335+
toolchain: &Toolchain,
337336
profiler: Profiler,
338337
out_dir: &Path,
339338
benchmarks: &[Benchmark],
340339
profiles: &[Profile],
341340
scenarios: &[Scenario],
342341
errors: &mut BenchmarkErrors,
343342
) {
344-
eprintln!("Profiling {} with {:?}", id, profiler);
343+
eprintln!("Profiling {} with {:?}", toolchain.id, profiler);
345344
if let Profiler::SelfProfile = profiler {
346345
check_measureme_installed().unwrap();
347346
}
@@ -352,8 +351,8 @@ fn profile(
352351
.map(|(i, benchmark)| {
353352
let benchmark_id = format!("{} ({}/{})", benchmark.name, i + 1, benchmarks.len());
354353
eprintln!("Executing benchmark {benchmark_id}");
355-
let mut processor = ProfileProcessor::new(profiler, out_dir, id);
356-
let result = benchmark.measure(&mut processor, profiles, scenarios, compiler, Some(1));
354+
let mut processor = ProfileProcessor::new(profiler, out_dir, &toolchain.id);
355+
let result = benchmark.measure(&mut processor, profiles, scenarios, toolchain, Some(1));
357356
eprintln!("Finished benchmark {benchmark_id}");
358357

359358
if let Err(ref s) = result {
@@ -717,6 +716,7 @@ fn main_result() -> anyhow::Result<i32> {
717716
local.cargo.as_deref(),
718717
local.id.as_deref(),
719718
"",
719+
target_triple,
720720
)?;
721721
let pool = Pool::open(&db.db);
722722

@@ -769,6 +769,7 @@ fn main_result() -> anyhow::Result<i32> {
769769
local.cargo.as_deref(),
770770
local.id.as_deref(),
771771
"",
772+
target_triple,
772773
)?;
773774

774775
let mut benchmarks = get_compile_benchmarks(
@@ -792,7 +793,7 @@ fn main_result() -> anyhow::Result<i32> {
792793
conn,
793794
profiles,
794795
scenarios,
795-
Compiler::from_toolchain(&toolchain, &target_triple),
796+
&toolchain,
796797
&benchmarks,
797798
Some(iterations),
798799
self_profile.self_profile,
@@ -842,7 +843,8 @@ fn main_result() -> anyhow::Result<i32> {
842843
exclude,
843844
runs,
844845
} => {
845-
let sysroot = Sysroot::install(commit.sha.to_string(), &target_triple)
846+
let sha = commit.sha.to_string();
847+
let sysroot = Sysroot::install(sha.clone(), &target_triple)
846848
.with_context(|| format!("failed to install sysroot for {:?}", commit))?;
847849

848850
let mut benchmarks = get_compile_benchmarks(
@@ -865,7 +867,7 @@ fn main_result() -> anyhow::Result<i32> {
865867
conn,
866868
&Profile::all(),
867869
&Scenario::all(),
868-
Compiler::from_sysroot(&sysroot),
870+
&Toolchain::from_sysroot(&sysroot, sha),
869871
&benchmarks,
870872
runs.map(|v| v as usize),
871873
self_profile.self_profile,
@@ -937,19 +939,19 @@ fn main_result() -> anyhow::Result<i32> {
937939
local.cargo.as_deref(),
938940
local.id.as_deref(),
939941
suffix,
942+
target_triple.clone(),
940943
)?;
941-
let compiler = Compiler::from_toolchain(&toolchain, &target_triple);
944+
let id = toolchain.id.clone();
942945
profile(
943-
compiler,
944-
&toolchain.id,
946+
&toolchain,
945947
profiler,
946948
&out_dir,
947949
&benchmarks,
948950
profiles,
949951
scenarios,
950952
&mut errors,
951953
);
952-
Ok(toolchain.id)
954+
Ok(id)
953955
};
954956

955957
if let Some(rustc2) = rustc2 {
@@ -1096,7 +1098,7 @@ fn bench_published_artifact(
10961098
let mut benchmarks = get_compile_benchmarks(benchmark_dir, None, None, None)?;
10971099
benchmarks.retain(|b| b.category().is_stable());
10981100

1099-
let artifact_id = ArtifactId::Tag(toolchain);
1101+
let artifact_id = ArtifactId::Tag(toolchain.clone());
11001102
let (conn, collector) = rt.block_on(init_compile_collector(
11011103
&pool,
11021104
&benchmarks,
@@ -1108,12 +1110,12 @@ fn bench_published_artifact(
11081110
conn,
11091111
&profiles,
11101112
&scenarios,
1111-
Compiler {
1112-
rustc: Path::new(rustc.trim()),
1113-
rustdoc: Some(Path::new(rustdoc.trim())),
1114-
cargo: Path::new(cargo.trim()),
1115-
is_nightly: false,
1116-
triple: target_triple,
1113+
&Toolchain {
1114+
rustc: PathBuf::from(rustc.trim()),
1115+
rustdoc: Some(PathBuf::from(rustdoc.trim())),
1116+
cargo: PathBuf::from(cargo.trim()),
1117+
id: toolchain,
1118+
triple: target_triple.to_string(),
11171119
},
11181120
&benchmarks,
11191121
Some(3),

collector/src/compile/benchmark/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::compile::benchmark::patch::Patch;
33
use crate::compile::benchmark::profile::Profile;
44
use crate::compile::benchmark::scenario::Scenario;
55
use crate::compile::execute::{CargoProcess, Processor};
6-
use crate::toolchain::Compiler;
6+
use crate::toolchain::Toolchain;
77
use anyhow::{bail, Context};
88
use log::debug;
99
use std::collections::{HashMap, HashSet};
@@ -143,7 +143,7 @@ impl Benchmark {
143143

144144
fn mk_cargo_process<'a>(
145145
&'a self,
146-
compiler: Compiler<'a>,
146+
toolchain: &'a Toolchain,
147147
cwd: &'a Path,
148148
profile: Profile,
149149
) -> CargoProcess<'a> {
@@ -163,7 +163,7 @@ impl Benchmark {
163163
}
164164

165165
CargoProcess {
166-
compiler,
166+
toolchain,
167167
processor_name: self.name.clone(),
168168
cwd,
169169
profile,
@@ -194,7 +194,7 @@ impl Benchmark {
194194
processor: &mut dyn Processor,
195195
profiles: &[Profile],
196196
scenarios: &[Scenario],
197-
compiler: Compiler<'_>,
197+
toolchain: &Toolchain,
198198
iterations: Option<usize>,
199199
) -> anyhow::Result<()> {
200200
if self.config.disabled {
@@ -261,7 +261,7 @@ impl Benchmark {
261261
for (profile, prep_dir) in &profile_dirs {
262262
let server = server.clone();
263263
let thread = s.spawn::<_, anyhow::Result<()>>(move || {
264-
self.mk_cargo_process(compiler, prep_dir.path(), *profile)
264+
self.mk_cargo_process(toolchain, prep_dir.path(), *profile)
265265
.jobserver(server)
266266
.run_rustc(false)?;
267267
Ok(())
@@ -308,7 +308,7 @@ impl Benchmark {
308308

309309
// A full non-incremental build.
310310
if scenarios.contains(&Scenario::Full) {
311-
self.mk_cargo_process(compiler, cwd, profile)
311+
self.mk_cargo_process(toolchain, cwd, profile)
312312
.processor(processor, Scenario::Full, "Full", None)
313313
.run_rustc(true)?;
314314
}
@@ -318,15 +318,15 @@ impl Benchmark {
318318
// An incremental from scratch (slowest incremental case).
319319
// This is required for any subsequent incremental builds.
320320
if scenarios.iter().any(|s| s.is_incr()) {
321-
self.mk_cargo_process(compiler, cwd, profile)
321+
self.mk_cargo_process(toolchain, cwd, profile)
322322
.incremental(true)
323323
.processor(processor, Scenario::IncrFull, "IncrFull", None)
324324
.run_rustc(true)?;
325325
}
326326

327327
// An incremental build with no changes (fastest incremental case).
328328
if scenarios.contains(&Scenario::IncrUnchanged) {
329-
self.mk_cargo_process(compiler, cwd, profile)
329+
self.mk_cargo_process(toolchain, cwd, profile)
330330
.incremental(true)
331331
.processor(processor, Scenario::IncrUnchanged, "IncrUnchanged", None)
332332
.run_rustc(true)?;
@@ -340,7 +340,7 @@ impl Benchmark {
340340
// An incremental build with some changes (realistic
341341
// incremental case).
342342
let scenario_str = format!("IncrPatched{}", i);
343-
self.mk_cargo_process(compiler, cwd, profile)
343+
self.mk_cargo_process(toolchain, cwd, profile)
344344
.incremental(true)
345345
.processor(
346346
processor,

collector/src/compile/execute/bencher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::compile::execute::{
66
rustc, DeserializeStatError, PerfTool, ProcessOutputData, Processor, Retry, SelfProfile,
77
SelfProfileFiles, Stats, Upload,
88
};
9-
use crate::toolchain::Compiler;
9+
use crate::toolchain::Toolchain;
1010
use crate::utils::git::get_rustc_perf_commit;
1111
use futures::stream::FuturesUnordered;
1212
use futures::StreamExt;
@@ -160,11 +160,11 @@ impl<'a> BenchProcessor<'a> {
160160
.block_on(async move { while let Some(()) = buf.next().await {} });
161161
}
162162

163-
pub fn measure_rustc(&mut self, compiler: Compiler<'_>) -> anyhow::Result<()> {
163+
pub fn measure_rustc(&mut self, toolchain: &Toolchain) -> anyhow::Result<()> {
164164
rustc::measure(
165165
self.rt,
166166
self.conn,
167-
compiler,
167+
toolchain,
168168
self.artifact,
169169
self.artifact_row_id,
170170
)

collector/src/compile/execute/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::compile::benchmark::patch::Patch;
44
use crate::compile::benchmark::profile::Profile;
55
use crate::compile::benchmark::scenario::Scenario;
66
use crate::compile::benchmark::BenchmarkName;
7-
use crate::toolchain::Compiler;
7+
use crate::toolchain::Toolchain;
88
use crate::{command_output, utils};
99
use anyhow::Context;
1010
use bencher::Bencher;
@@ -113,7 +113,7 @@ impl PerfTool {
113113
}
114114

115115
pub struct CargoProcess<'a> {
116-
pub compiler: Compiler<'a>,
116+
pub toolchain: &'a Toolchain,
117117
pub cwd: &'a Path,
118118
pub profile: Profile,
119119
pub incremental: bool,
@@ -144,12 +144,12 @@ impl<'a> CargoProcess<'a> {
144144
}
145145

146146
fn base_command(&self, cwd: &Path, subcommand: &str) -> Command {
147-
let mut cmd = Command::new(Path::new(self.compiler.cargo));
147+
let mut cmd = Command::new(Path::new(&self.toolchain.cargo));
148148
cmd
149149
// Not all cargo invocations (e.g. `cargo clean`) need all of these
150150
// env vars set, but it doesn't hurt to have them.
151151
.env("RUSTC", &*FAKE_RUSTC)
152-
.env("RUSTC_REAL", self.compiler.rustc)
152+
.env("RUSTC_REAL", &self.toolchain.rustc)
153153
// We separately pass -Cincremental to the leaf crate --
154154
// CARGO_INCREMENTAL is cached separately for both the leaf crate
155155
// and any in-tree dependencies, and we don't want that; it wastes
@@ -164,7 +164,7 @@ impl<'a> CargoProcess<'a> {
164164
.arg("--manifest-path")
165165
.arg(&self.manifest_path);
166166

167-
if let Some(r) = &self.compiler.rustdoc {
167+
if let Some(r) = &self.toolchain.rustdoc {
168168
cmd.env("RUSTDOC", &*FAKE_RUSTDOC).env("RUSTDOC_REAL", r);
169169
}
170170
cmd

collector/src/compile/execute/rustc.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! no real reason for us to compile the standard library twice, and it avoids
88
//! having to think about how to deduplicate results.
99
10-
use crate::toolchain::Compiler;
10+
use crate::toolchain::Toolchain;
1111
use crate::utils::git::get_rustc_perf_commit;
1212
use anyhow::Context;
1313
use database::ArtifactId;
@@ -20,23 +20,23 @@ use tokio::runtime::Runtime;
2020
pub fn measure(
2121
rt: &mut Runtime,
2222
conn: &mut dyn database::Connection,
23-
compiler: Compiler<'_>,
23+
toolchain: &Toolchain,
2424
artifact: &database::ArtifactId,
2525
aid: database::ArtifactIdNumber,
2626
) -> anyhow::Result<()> {
2727
eprintln!("Running rustc");
2828

2929
checkout(artifact).context("checking out rust-lang/rust")?;
3030

31-
record(rt, conn, compiler, artifact, aid)?;
31+
record(rt, conn, toolchain, artifact, aid)?;
3232

3333
Ok(())
3434
}
3535

3636
fn record(
3737
rt: &mut Runtime,
3838
conn: &mut dyn database::Connection,
39-
compiler: Compiler<'_>,
39+
toolchain: &Toolchain,
4040
artifact: &database::ArtifactId,
4141
aid: database::ArtifactIdNumber,
4242
) -> anyhow::Result<()> {
@@ -95,9 +95,12 @@ fn record(
9595
.arg("rust.deny-warnings=false")
9696
.arg("--set")
9797
.arg(&format!("build.rustc={}", fake_rustc.to_str().unwrap()))
98-
.env("RUSTC_PERF_REAL_RUSTC", compiler.rustc)
98+
.env("RUSTC_PERF_REAL_RUSTC", &toolchain.rustc)
9999
.arg("--set")
100-
.arg(&format!("build.cargo={}", compiler.cargo.to_str().unwrap()))
100+
.arg(&format!(
101+
"build.cargo={}",
102+
toolchain.cargo.to_str().unwrap()
103+
))
101104
.status()
102105
.context("configuring")?;
103106
assert!(status.success(), "configure successful");
@@ -111,7 +114,7 @@ fn record(
111114
.context("x.py script canonicalize")?,
112115
)
113116
.current_dir(checkout)
114-
.env("RUSTC_PERF_REAL_RUSTC", compiler.rustc)
117+
.env("RUSTC_PERF_REAL_RUSTC", &toolchain.rustc)
115118
.arg("build")
116119
.arg("--stage")
117120
.arg("0")

0 commit comments

Comments
 (0)