-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Use 128 bit instead of Symbol for crate disambiguator #45476
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
let crate_name = format!("{}-{}", | ||
crate_name, | ||
base_n::encode(hasher.finish(), INT_ENCODE_BASE)); | ||
base_n::encode(crate_disambiguator, INT_ENCODE_BASE)); |
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.
This truncates the hash to 64 bits, should I implement a 128 but encoding in base_n
?
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.
This is pre-existing?
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.
Now sure what you mean exactly, but to_smaller_hash()
already exists and truncates to 64 bits.
I meant to ask if base_n::encode
should be extended to work with Fingerprint
/u128
, in addition to u64
. To be honest, I saw that it accepts u64
, so thought that truncating 128->64 might be acceptable in this case
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.
The code you wrote should have roughly the same effect as before since DefaultHasher
also produces 64 bits. We don't want these hashes to be too long because they end up in directory names and long paths/names sometimes cause trouble for various reasons (file system support, operating system API restrictions, etc).
Maybe you could add a comment here, similar to the one that is replaced:
// The full crate disambiguator is really long. 64 bits of it should be
// sufficient.
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.
Thanks for the PR, @Xanewok! It already looks pretty good.
Browsing through the code though, I think it is a good idea to introduce a new type for the disambiguator, as in:
#[derive(Copy, Clone, Hash, Debug, ...)]
pub struct CrateDisambiguator {
fingerprint: Fingerprint
}
impl CrateDisambiguator {
pub fn to_fingerprint(self) -> Fingerprint {
self.fingerprint
}
}
You could put that into librustc/session/config.rs
for example. It seems slightly cleaner to me if the disambiguator as its own type.
Regarding the mir-opt
tests, yes, just update the hash values.
src/librustc/hir/map/collector.rs
Outdated
@@ -118,7 +119,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { | |||
} | |||
|
|||
pub(super) fn finalize_and_compute_crate_hash(self, | |||
crate_disambiguator: &str) | |||
crate_disambiguator: &Fingerprint) |
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.
Usually we pass around Fingerprint
by value. It implements Copy
so that should be easy.
let crate_name = format!("{}-{}", | ||
crate_name, | ||
base_n::encode(hasher.finish(), INT_ENCODE_BASE)); | ||
base_n::encode(crate_disambiguator, INT_ENCODE_BASE)); |
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.
The code you wrote should have roughly the same effect as before since DefaultHasher
also produces 64 bits. We don't want these hashes to be too long because they end up in directory names and long paths/names sometimes cause trouble for various reasons (file system support, operating system API restrictions, etc).
Maybe you could add a comment here, similar to the one that is replaced:
// The full crate disambiguator is really long. 64 bits of it should be
// sufficient.
Yes, you can do that. It would be a bit more consistent this way. |
@michaelwoerister created a |
📌 Commit 7fa64bc has been approved by |
…erister Use 128 bit instead of Symbol for crate disambiguator As discussed on gitter, this changes `crate_disambiguator` from Strings to what they are represented as, a 128 bit number. There's also one bit I think also needs to change, but wasn't 100% sure how: [create_root_def](https://github.com/rust-lang/rust/blob/f338dba29705e144bad8b2a675284538dd514896/src/librustc/hir/map/definitions.rs#L468-L482). Should I change `DefKey::root_parent_stable_hash` to accept `Fingerprint` as crate_disambiguator to quickly combine the hash of `crate_name` with the new 128 bit hash instead of a string for a disambiguator? r? @michaelwoerister EDIT: Are those 3 tests `mir-opt` failing, because the hash is different, because we calculate it a little bit differently (storing directly instead of hashing the hex-string representation)? Should it be updated like in #45319?
☀️ Test successful - status-appveyor, status-travis |
🎉 |
As discussed on gitter, this changes
crate_disambiguator
from Strings to what they are represented as, a 128 bit number.There's also one bit I think also needs to change, but wasn't 100% sure how: create_root_def. Should I change
DefKey::root_parent_stable_hash
to acceptFingerprint
as crate_disambiguator to quickly combine the hash ofcrate_name
with the new 128 bit hash instead of a string for a disambiguator?r? @michaelwoerister
EDIT: Are those 3 tests
mir-opt
failing, because the hash is different, because we calculate it a little bit differently (storing directly instead of hashing the hex-string representation)? Should it be updated like in #45319?