Skip to content

Commit b79460e

Browse files
Remove rustc version from stable crate IDs
Since rust-lang/rust#89836, rustc stable crate IDs include a hash of the rustc version (including the git commit it's built from), which means that hashmaps or other structures have different behavior when comparing different rustc builds. This is bad for rustc-perf, as it means that comparing two commits has a source of noise that makes it harder to know what the actual change between two artifacts is.
1 parent 9d8903f commit b79460e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

collector/src/rustc-fake.rs

+33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ use std::path::PathBuf;
77
use std::process::Command;
88
use std::time::{Duration, Instant};
99

10+
fn determinism_env(cmd: &mut Command) {
11+
// Since rust-lang/rust#89836, rustc stable crate IDs include a hash of the
12+
// rustc version (including the git commit it's built from), which means
13+
// that hashmaps or other structures have different behavior when comparing
14+
// different rustc builds. This is bad for rustc-perf, as it means that
15+
// comparing two commits has a source of noise that makes it harder to know
16+
// what the actual change between two artifacts is.
17+
cmd.env("RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER", "rustc-perf");
18+
}
19+
1020
fn main() {
1121
let mut args_os = env::args_os();
1222
let name = args_os.next().unwrap().into_string().unwrap();
@@ -30,6 +40,14 @@ fn main() {
3040

3141
args.push(OsString::from("-Adeprecated"));
3242
args.push(OsString::from("-Aunknown-lints"));
43+
44+
// This forces incremental query hash verification on. Currently, rustc
45+
// hashes 1/32 of queries loaded from disk without this flag, but that 1/32
46+
// is based on the (expected) hash of the data, which can vary from build to
47+
// build, adding a source of noise to our measurements, which we prefer to
48+
// avoid. rustc-perf can accept the higher cost of always verifying hashes,
49+
// and we currently prefer to avoid exposing a means of hard-disabling
50+
// verification.
3351
args.push(OsString::from("-Zincremental-verify-ich"));
3452

3553
if let Some(pos) = args.iter().position(|arg| arg == "--wrap-rustc-with") {
@@ -44,6 +62,7 @@ fn main() {
4462
match wrapper {
4563
"perf-stat" | "perf-stat-self-profile" => {
4664
let mut cmd = Command::new("perf");
65+
determinism_env(&mut cmd);
4766
let has_perf = cmd.output().is_ok();
4867
assert!(has_perf);
4968
cmd.arg("stat")
@@ -121,6 +140,7 @@ fn main() {
121140
assert!(status.success(), "tracelog did not complete successfully");
122141

123142
let mut tool = Command::new(tool);
143+
determinism_env(&mut tool);
124144
tool.args(&args);
125145

126146
let prof_out_dir = std::env::current_dir().unwrap().join("self-profile-output");
@@ -162,6 +182,7 @@ fn main() {
162182

163183
"self-profile" => {
164184
let mut cmd = Command::new(&tool);
185+
determinism_env(&mut cmd);
165186
cmd.arg("-Zself-profile-events=all");
166187
cmd.arg("-Zself-profile=Zsp").args(&args);
167188

@@ -172,6 +193,7 @@ fn main() {
172193
args.insert(0, "-Ztime-passes".into());
173194

174195
let mut cmd = Command::new(&tool);
196+
determinism_env(&mut cmd);
175197
cmd.args(args).stderr(std::process::Stdio::from(
176198
std::fs::File::create("Ztp").unwrap(),
177199
));
@@ -180,6 +202,7 @@ fn main() {
180202

181203
"perf-record" => {
182204
let mut cmd = Command::new("perf");
205+
determinism_env(&mut cmd);
183206
let has_perf = cmd.output().is_ok();
184207
assert!(has_perf);
185208
cmd.arg("record")
@@ -195,6 +218,7 @@ fn main() {
195218

196219
"oprofile" => {
197220
let mut cmd = Command::new("operf");
221+
determinism_env(&mut cmd);
198222
let has_oprofile = cmd.output().is_ok();
199223
assert!(has_oprofile);
200224
// Other possibly useful args: --callgraph, --separate-thread
@@ -205,6 +229,7 @@ fn main() {
205229

206230
"cachegrind" => {
207231
let mut cmd = Command::new("valgrind");
232+
determinism_env(&mut cmd);
208233
let has_valgrind = cmd.output().is_ok();
209234
assert!(has_valgrind);
210235

@@ -229,6 +254,7 @@ fn main() {
229254

230255
"callgrind" => {
231256
let mut cmd = Command::new("valgrind");
257+
determinism_env(&mut cmd);
232258
let has_valgrind = cmd.output().is_ok();
233259
assert!(has_valgrind);
234260

@@ -246,6 +272,7 @@ fn main() {
246272

247273
"dhat" => {
248274
let mut cmd = Command::new("valgrind");
275+
determinism_env(&mut cmd);
249276
let has_valgrind = cmd.output().is_ok();
250277
assert!(has_valgrind);
251278
cmd.arg("--tool=dhat")
@@ -259,6 +286,7 @@ fn main() {
259286

260287
"massif" => {
261288
let mut cmd = Command::new("valgrind");
289+
determinism_env(&mut cmd);
262290
let has_valgrind = cmd.output().is_ok();
263291
assert!(has_valgrind);
264292
cmd.arg("--tool=massif")
@@ -275,6 +303,7 @@ fn main() {
275303

276304
"eprintln" => {
277305
let mut cmd = bash_command(tool, args, "2> eprintln");
306+
determinism_env(&mut cmd);
278307

279308
assert!(cmd.status().expect("failed to spawn").success());
280309
}
@@ -288,6 +317,7 @@ fn main() {
288317
// `rustc` (which this file wraps) doesn't produce the output,
289318
// this file can't redirect that output.
290319
let mut cmd = Command::new(&tool);
320+
determinism_env(&mut cmd);
291321
cmd.args(&args);
292322

293323
assert!(cmd.status().expect("failed to spawn").success());
@@ -298,6 +328,7 @@ fn main() {
298328
// option)
299329
args.push("-Zprint-mono-items=lazy".into());
300330
let mut cmd = bash_command(tool, args, "1> mono-items");
331+
determinism_env(&mut cmd);
301332

302333
assert!(cmd.status().expect("failed to spawn").success());
303334
}
@@ -306,6 +337,7 @@ fn main() {
306337
args.push("-Zdump-dep-graph".into());
307338
args.push("-Zquery-dep-graph".into());
308339
let mut cmd = Command::new(tool);
340+
determinism_env(&mut cmd);
309341
cmd.args(&args);
310342

311343
assert!(cmd.status().expect("failed to spawn").success());
@@ -332,6 +364,7 @@ fn main() {
332364
}
333365

334366
let mut cmd = Command::new(&tool);
367+
determinism_env(&mut env);
335368
cmd.args(&args);
336369
exec(&mut cmd);
337370
}

0 commit comments

Comments
 (0)