Skip to content

Commit 9e1aff8

Browse files
committed
Auto merge of #89836 - pierwill:fix-85142-crate-hash, r=wesleywiser
Include rustc version in `rustc_span::StableCrateId` `rustc_span::def_id::StableCrateId` is a hash of various data about a crate during compilation. This PR includes the version of `rustc` in the input when computing this hash. From a cursory reading of [RFC 2603](https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html), this appears to be acceptable within that design. In order to pass the `mir-opt` and `ui` test suites, this adds new [normalization for hashes and symbol names in `compiletest`](https://github.com/rust-lang/rust/pull/89836/files#diff-03a0567fa80ca04ed5a55f9ac5c711b4f84659be2d0ac4a984196d581c04f76b). These are enabled by default, but we might prefer it to be configurable. In the UI tests, I had to truncate a significant amount of error annotations in v0 symbols (and maybe some legacy) in order to get the normalization to work correctly. (See #90116.) Closes #85142.
2 parents 69ac533 + 535278a commit 9e1aff8

File tree

53 files changed

+333
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+333
-205
lines changed

Diff for: compiler/rustc_resolve/src/late/lifetimes.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20092009
}
20102010
};
20112011

2012-
let mut def_ids: Vec<_> = defined_by
2012+
let def_ids: Vec<_> = defined_by
20132013
.values()
20142014
.flat_map(|region| match region {
20152015
Region::EarlyBound(_, def_id, _)
@@ -2020,9 +2020,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20202020
})
20212021
.collect();
20222022

2023-
// ensure that we issue lints in a repeatable order
2024-
def_ids.sort_by_cached_key(|&def_id| self.tcx.def_path_hash(def_id));
2025-
20262023
'lifetimes: for def_id in def_ids {
20272024
debug!("check_uses_for_lifetimes_defined_by_scope: def_id = {:?}", def_id);
20282025

Diff for: compiler/rustc_span/src/def_id.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,17 @@ impl Borrow<Fingerprint> for DefPathHash {
127127
}
128128
}
129129

130-
/// A [StableCrateId] is a 64 bit hash of the crate name combined with all
131-
/// `-Cmetadata` arguments. It is to [CrateNum] what [DefPathHash] is to
132-
/// [DefId]. It is stable across compilation sessions.
130+
/// A [`StableCrateId`] is a 64-bit hash of a crate name, together with all
131+
/// `-Cmetadata` arguments, and some other data. It is to [`CrateNum`] what [`DefPathHash`] is to
132+
/// [`DefId`]. It is stable across compilation sessions.
133133
///
134-
/// Since the ID is a hash value there is a (very small) chance that two crates
135-
/// end up with the same [StableCrateId]. The compiler will check for such
134+
/// Since the ID is a hash value, there is a small chance that two crates
135+
/// end up with the same [`StableCrateId`]. The compiler will check for such
136136
/// collisions when loading crates and abort compilation in order to avoid
137137
/// further trouble.
138+
///
139+
/// See the discussion in [`DefId`] for more information
140+
/// on the possibility of hash collisions in rustc,
138141
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)]
139142
#[derive(HashStable_Generic, Encodable, Decodable)]
140143
pub struct StableCrateId(pub(crate) u64);
@@ -150,7 +153,7 @@ impl StableCrateId {
150153
let mut hasher = StableHasher::new();
151154
crate_name.hash(&mut hasher);
152155

153-
// We don't want the stable crate id to dependent on the order
156+
// We don't want the stable crate ID to depend on the order of
154157
// -C metadata arguments, so sort them:
155158
metadata.sort();
156159
// Every distinct -C metadata value is only incorporated once:
@@ -169,6 +172,18 @@ impl StableCrateId {
169172
// linking against a library of the same name, if this is an executable.
170173
hasher.write(if is_exe { b"exe" } else { b"lib" });
171174

175+
// Also incorporate the rustc version. Otherwise, with -Zsymbol-mangling-version=v0
176+
// and no -Cmetadata, symbols from the same crate compiled with different versions of
177+
// rustc are named the same.
178+
//
179+
// RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER is used to inject rustc version information
180+
// during testing.
181+
if let Some(val) = std::env::var_os("RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER") {
182+
hasher.write(val.to_string_lossy().into_owned().as_bytes())
183+
} else {
184+
hasher.write(option_env!("CFG_VERSION").unwrap_or("unknown version").as_bytes());
185+
}
186+
172187
StableCrateId(hasher.finish())
173188
}
174189
}

Diff for: src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35
3131
- _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44
3232
+ // + span: $DIR/const-promotion-extern-static.rs:9:31: 9:44
33-
+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[55e6]::BAR), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
33+
+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[HASH]::BAR), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
3434
+ _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44
3535
_1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44
3636
- StorageDead(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:9:34: 9:35

Diff for: src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
- _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
3333
- _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55
3434
+ // + span: $DIR/const-promotion-extern-static.rs:13:31: 13:55
35-
+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[55e6]::FOO), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
35+
+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[HASH]::FOO), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
3636
+ _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55
3737
_1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55
3838
- StorageDead(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:13:45: 13:46

Diff for: src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// + val: Unevaluated(main, [], Some(promoted[0]))
3232
// mir::Constant
3333
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
34-
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[8240]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
34+
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
3535
_3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3636
_2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3737
_1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35

Diff for: src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// + val: Unevaluated(main, [], Some(promoted[0]))
3232
// mir::Constant
3333
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
34-
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[8240]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
34+
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
3535
_3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3636
_2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3737
_1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35

Diff for: src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// + val: Unevaluated(FOO, [], None)
2323
// mir::Constant
2424
// + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
25-
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[2706]::main::FOO), const_param_did: None }, substs_: Some([]), promoted: None }) }
25+
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[HASH]::main::FOO), const_param_did: None }, substs_: Some([]), promoted: None }) }
2626
_2 = &raw const (*_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
2727
_1 = move _2 as usize (Misc); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:39
2828
StorageDead(_2); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:38: 7:39

Diff for: src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// + val: Unevaluated(main, [], Some(promoted[0]))
1818
// mir::Constant
1919
// + span: $DIR/ref_deref.rs:5:6: 5:10
20-
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[cb9b]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
20+
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
2121
_2 = _4; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10
2222
- _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10
2323
+ _1 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:5:5: 5:10

Diff for: src/test/mir-opt/const_prop/ref_deref.main.PromoteTemps.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
+ // + val: Unevaluated(main, [], Some(promoted[0]))
2121
+ // mir::Constant
2222
+ // + span: $DIR/ref_deref.rs:5:6: 5:10
23-
+ // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[cb9b]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
23+
+ // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
2424
+ _2 = &(*_4); // scope 0 at $DIR/ref_deref.rs:5:6: 5:10
2525
_1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10
2626
- StorageDead(_3); // scope 0 at $DIR/ref_deref.rs:5:10: 5:11

Diff for: src/test/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// + val: Unevaluated(main, [], Some(promoted[0]))
1818
// mir::Constant
1919
// + span: $DIR/ref_deref_project.rs:5:6: 5:17
20-
// + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[e8c3]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
20+
// + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
2121
_2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17
2222
_1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17
2323
StorageDead(_2); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18

Diff for: src/test/mir-opt/const_prop/ref_deref_project.main.PromoteTemps.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
+ // + val: Unevaluated(main, [], Some(promoted[0]))
2121
+ // mir::Constant
2222
+ // + span: $DIR/ref_deref_project.rs:5:6: 5:17
23-
+ // + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[e8c3]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
23+
+ // + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
2424
+ _2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17
2525
_1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17
2626
- StorageDead(_3); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18

Diff for: src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// + val: Unevaluated(main, [], Some(promoted[0]))
2626
// mir::Constant
2727
// + span: $DIR/slice_len.rs:5:6: 5:19
28-
// + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[6547]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
28+
// + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
2929
_4 = _9; // scope 0 at $DIR/slice_len.rs:5:6: 5:19
3030
_3 = _4; // scope 0 at $DIR/slice_len.rs:5:6: 5:19
3131
StorageLive(_10); // scope 0 at $DIR/slice_len.rs:5:6: 5:19

Diff for: src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// + val: Unevaluated(main, [], Some(promoted[0]))
2626
// mir::Constant
2727
// + span: $DIR/slice_len.rs:5:6: 5:19
28-
// + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[6547]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
28+
// + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
2929
_4 = _9; // scope 0 at $DIR/slice_len.rs:5:6: 5:19
3030
_3 = _4; // scope 0 at $DIR/slice_len.rs:5:6: 5:19
3131
StorageLive(_10); // scope 0 at $DIR/slice_len.rs:5:6: 5:19

Diff for: src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn bar() -> bool {
3838
// + val: Unevaluated(bar, [], Some(promoted[1]))
3939
// mir::Constant
4040
// + span: $DIR/inline-retag.rs:12:7: 12:9
41-
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[a78c]::bar), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[1]) }) }
41+
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[HASH]::bar), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[1]) }) }
4242
Retag(_10); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9
4343
_4 = &(*_10); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9
4444
Retag(_4); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9
@@ -52,7 +52,7 @@ fn bar() -> bool {
5252
// + val: Unevaluated(bar, [], Some(promoted[0]))
5353
// mir::Constant
5454
// + span: $DIR/inline-retag.rs:12:11: 12:14
55-
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[a78c]::bar), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
55+
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[HASH]::bar), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
5656
Retag(_9); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14
5757
_7 = &(*_9); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14
5858
Retag(_7); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14

Diff for: src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// + val: Unevaluated(main, [], Some(promoted[0]))
6767
// mir::Constant
6868
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
69-
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
69+
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
7070
_8 = _20; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
7171
(_6.0: &i32) = move _7; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
7272
(_6.1: &i32) = move _8; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL

Diff for: src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// + val: Unevaluated(main, [], Some(promoted[0]))
6767
// mir::Constant
6868
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
69-
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
69+
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[HASH]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) }
7070
_8 = _20; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
7171
(_6.0: &i32) = move _7; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
7272
(_6.1: &i32) = move _8; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL

0 commit comments

Comments
 (0)