Skip to content

Commit a26d99f

Browse files
committed
In --emit KIND=PATH options, only hash KIND
The PATH has no material effect on the emitted artifact, and setting the patch via `-o` or `--out-dir` does not affect the hash. Closes rust-lang#86044
1 parent cef3ab7 commit a26d99f

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

compiler/rustc_interface/src/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ fn test_output_types_tracking_hash_different_paths() {
152152
v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
153153
v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
154154

155-
assert_different_hash(&v1, &v2);
156-
assert_different_hash(&v1, &v3);
157-
assert_different_hash(&v2, &v3);
155+
assert_same_hash(&v1, &v2);
156+
assert_same_hash(&v1, &v3);
157+
assert_same_hash(&v2, &v3);
158158
}
159159

160160
#[test]

compiler/rustc_session/src/config.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use std::collections::btree_map::{
3131
};
3232
use std::collections::{BTreeMap, BTreeSet};
3333
use std::fmt;
34+
use std::hash::{Hash, Hasher};
3435
use std::iter::{self, FromIterator};
3536
use std::path::{Path, PathBuf};
3637
use std::str::{self, FromStr};
@@ -325,10 +326,19 @@ impl Default for TrimmedDefPaths {
325326

326327
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
327328
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
328-
/// dependency tracking for command-line arguments.
329-
#[derive(Clone, Hash, Debug)]
329+
/// dependency tracking for command-line arguments. Also only hash keys, since tracking
330+
/// should only depend on the output types, not the paths they're written to.
331+
#[derive(Clone, Debug)]
330332
pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
331333

334+
impl Hash for OutputTypes {
335+
fn hash<H: Hasher>(&self, hasher: &mut H) {
336+
for k in self.keys() {
337+
k.hash(hasher);
338+
}
339+
}
340+
}
341+
332342
impl_stable_hash_via_hash!(OutputTypes);
333343

334344
impl OutputTypes {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
OUT=$(TMPDIR)/emit
4+
5+
# --emit KIND=PATH should not affect crate hash vs --emit KIND
6+
all: $(OUT)/a/libfoo.rlib $(OUT)/b/libfoo.rlib $(TMPDIR)/libfoo.rlib
7+
$(RUSTC) -Zls $(TMPDIR)/libfoo.rlib > $(TMPDIR)/base.txt
8+
$(RUSTC) -Zls $(OUT)/a/libfoo.rlib > $(TMPDIR)/a.txt
9+
$(RUSTC) -Zls $(OUT)/b/libfoo.rlib > $(TMPDIR)/b.txt
10+
11+
diff $(TMPDIR)/base.txt $(TMPDIR)/a.txt
12+
diff $(TMPDIR)/base.txt $(TMPDIR)/b.txt
13+
14+
# Default output name
15+
$(TMPDIR)/libfoo.rlib: foo.rs
16+
$(RUSTC) --emit link foo.rs
17+
18+
# Output named with -o
19+
$(OUT)/a/libfoo.rlib: foo.rs
20+
mkdir -p $(OUT)/a
21+
$(RUSTC) --emit link -o $@ foo.rs
22+
23+
# Output named with KIND=PATH
24+
$(OUT)/b/libfoo.rlib: foo.rs
25+
mkdir -p $(OUT)/b
26+
$(RUSTC) --emit link=$@ foo.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#![crate_type = "rlib"]

0 commit comments

Comments
 (0)