Skip to content

Commit 89e5db8

Browse files
committed
Only inherit local hash for paths.
1 parent 8051f01 commit 89e5db8

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

compiler/rustc_hir/src/definitions.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ impl DefKey {
140140
pub(crate) fn compute_stable_hash(&self, parent: DefPathHash) -> DefPathHash {
141141
let mut hasher = StableHasher::new();
142142

143-
parent.hash(&mut hasher);
143+
// The new path is in the same crate as `parent`, and will contain the stable_crate_id.
144+
// Therefore, we only need to include information of the parent's local hash.
145+
parent.local_hash().hash(&mut hasher);
144146

145147
let DisambiguatedDefPathData { ref data, disambiguator } = self.disambiguated_data;
146148

@@ -361,8 +363,16 @@ impl Definitions {
361363
},
362364
};
363365

364-
let parent_hash = DefPathHash::new(stable_crate_id, Hash64::ZERO);
365-
let def_path_hash = key.compute_stable_hash(parent_hash);
366+
// We want *both* halves of a DefPathHash to depend on the crate-id of the defining crate.
367+
// The crate-id can be more easily changed than the DefPath of an item, so, in the case of
368+
// a crate-local DefPathHash collision, the user can simply "roll the dice again" for all
369+
// DefPathHashes in the crate by changing the crate disambiguator (e.g. via bumping the
370+
// crate's version number).
371+
//
372+
// Children paths will only hash the local portion, and still inherit the change to the
373+
// root hash.
374+
let def_path_hash =
375+
DefPathHash::new(stable_crate_id, Hash64::new(stable_crate_id.as_u64()));
366376

367377
// Create the root definition.
368378
let mut table = DefPathTable::new(stable_crate_id);

tests/mir-opt/inline/cycle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn f(g: impl Fn()) {
1313
#[inline(always)]
1414
fn g() {
1515
// CHECK-LABEL: fn g(
16-
// CHECK-NOT: (inlined f::<fn() {main}>)
16+
// CHECK-NOT: inlined
1717
f(main);
1818
}
1919

tests/ui/symbol-names/basic.legacy.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: symbol-name(_ZN5basic4main17hc88b9d80a69d119aE)
1+
error: symbol-name(_ZN5basic4main17h1dddcfd03744167fE)
22
--> $DIR/basic.rs:8:1
33
|
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

7-
error: demangling(basic::main::hc88b9d80a69d119a)
7+
error: demangling(basic::main::h1dddcfd03744167f)
88
--> $DIR/basic.rs:8:1
99
|
1010
LL | #[rustc_symbol_name]

tests/ui/symbol-names/issue-60925.legacy.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17hbddb77d6f71afb32E)
1+
error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h4b3099ec5dc5d306E)
22
--> $DIR/issue-60925.rs:21:9
33
|
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

7-
error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::hbddb77d6f71afb32)
7+
error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::h4b3099ec5dc5d306)
88
--> $DIR/issue-60925.rs:21:9
99
|
1010
LL | #[rustc_symbol_name]

tests/ui/thir-print/thir-tree-match.stdout

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ body:
9494
did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo)
9595
variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }]
9696
flags: IS_ENUM
97-
repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 3477539199540094892 }
97+
repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 13397682652773712997 }
9898
args: []
9999
variant_index: 0
100100
subpatterns: [
@@ -108,7 +108,7 @@ body:
108108
did: DefId(0:3 ~ thir_tree_match[fcf8]::Bar)
109109
variants: [VariantDef { def_id: DefId(0:4 ~ thir_tree_match[fcf8]::Bar::First), ctor: Some((Const, DefId(0:5 ~ thir_tree_match[fcf8]::Bar::First::{constructor#0}))), name: "First", discr: Relative(0), fields: [], tainted: None, flags: }, VariantDef { def_id: DefId(0:6 ~ thir_tree_match[fcf8]::Bar::Second), ctor: Some((Const, DefId(0:7 ~ thir_tree_match[fcf8]::Bar::Second::{constructor#0}))), name: "Second", discr: Relative(1), fields: [], tainted: None, flags: }, VariantDef { def_id: DefId(0:8 ~ thir_tree_match[fcf8]::Bar::Third), ctor: Some((Const, DefId(0:9 ~ thir_tree_match[fcf8]::Bar::Third::{constructor#0}))), name: "Third", discr: Relative(2), fields: [], tainted: None, flags: }]
110110
flags: IS_ENUM
111-
repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 10333377570083945360 }
111+
repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 7908585036048874241 }
112112
args: []
113113
variant_index: 0
114114
subpatterns: []
@@ -156,7 +156,7 @@ body:
156156
did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo)
157157
variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }]
158158
flags: IS_ENUM
159-
repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 3477539199540094892 }
159+
repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 13397682652773712997 }
160160
args: []
161161
variant_index: 0
162162
subpatterns: [
@@ -208,7 +208,7 @@ body:
208208
did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo)
209209
variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }]
210210
flags: IS_ENUM
211-
repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 3477539199540094892 }
211+
repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 13397682652773712997 }
212212
args: []
213213
variant_index: 1
214214
subpatterns: []

0 commit comments

Comments
 (0)