-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include rustc version in rustc_span::StableCrateId
#89836
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,14 +126,17 @@ impl Borrow<Fingerprint> for DefPathHash { | |
} | ||
} | ||
|
||
/// A [StableCrateId] is a 64 bit hash of the crate name combined with all | ||
/// `-Cmetadata` arguments. It is to [CrateNum] what [DefPathHash] is to | ||
/// [DefId]. It is stable across compilation sessions. | ||
/// A [`StableCrateId`] is a 64-bit hash of a crate name, together with all | ||
/// `-Cmetadata` arguments, and some other data. It is to [`CrateNum`] what [`DefPathHash`] is to | ||
/// [`DefId`]. It is stable across compilation sessions. | ||
/// | ||
/// Since the ID is a hash value there is a (very small) chance that two crates | ||
/// end up with the same [StableCrateId]. The compiler will check for such | ||
/// Since the ID is a hash value, there is a small chance that two crates | ||
/// end up with the same [`StableCrateId`]. The compiler will check for such | ||
/// collisions when loading crates and abort compilation in order to avoid | ||
/// further trouble. | ||
/// | ||
/// See the discussion in [`DefId`] for more information | ||
/// on the possibility of hash collisions in rustc, | ||
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)] | ||
#[derive(HashStable_Generic, Encodable, Decodable)] | ||
pub struct StableCrateId(pub(crate) u64); | ||
|
@@ -152,7 +155,7 @@ impl StableCrateId { | |
let mut hasher = StableHasher::new(); | ||
crate_name.hash(&mut hasher); | ||
|
||
// We don't want the stable crate id to dependent on the order | ||
// We don't want the stable crate ID to depend on the order of | ||
// -C metadata arguments, so sort them: | ||
metadata.sort(); | ||
// Every distinct -C metadata value is only incorporated once: | ||
|
@@ -171,6 +174,18 @@ impl StableCrateId { | |
// linking against a library of the same name, if this is an executable. | ||
hasher.write(if is_exe { b"exe" } else { b"lib" }); | ||
|
||
// Also incorporate the rustc version. Otherwise, with -Zsymbol-mangling-version=v0 | ||
// and no -Cmetadata, symbols from the same crate compiled with different versions of | ||
// rustc are named the same. | ||
// | ||
// RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER is used to inject rustc version information | ||
// during testing. | ||
if let Some(val) = std::env::var_os("RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER") { | ||
hasher.write(val.to_string_lossy().into_owned().as_bytes()) | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me it's a visual reminder that we want to give version-related data to the hasher only once. |
||
hasher.write(option_env!("CFG_VERSION").unwrap_or("unknown version").as_bytes()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: why not skip this step entirely if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is based on @bjorn3's suggestion in the original issue. For some reason, for me it feels right to have the rustc version contribute some data to the hash in all cases, instead of an empty string sometimes. |
||
} | ||
|
||
StableCrateId(hasher.finish()) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjgillot is this fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjorn #89836 (comment)