Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upUse 128 bit instead of Symbol for crate disambiguator #45476
Conversation
rust-highfive
assigned
michaelwoerister
Oct 23, 2017
This comment has been minimized.
This comment has been minimized.
|
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. |
Xanewok
reviewed
Oct 23, 2017
| let crate_name = format!("{}-{}", | ||
| crate_name, | ||
| base_n::encode(hasher.finish(), INT_ENCODE_BASE)); | ||
| base_n::encode(crate_disambiguator, INT_ENCODE_BASE)); |
This comment has been minimized.
This comment has been minimized.
Xanewok
Oct 23, 2017
Author
Member
This truncates the hash to 64 bits, should I implement a 128 but encoding in base_n?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Xanewok
Oct 23, 2017
Author
Member
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
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Oct 24, 2017
Contributor
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.
kennytm
added
the
S-waiting-on-author
label
Oct 24, 2017
michaelwoerister
reviewed
Oct 24, 2017
|
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 Regarding the |
| @@ -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) | |||
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Oct 24, 2017
Contributor
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)); |
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Oct 24, 2017
Contributor
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.
This comment has been minimized.
This comment has been minimized.
Yes, you can do that. It would be a bit more consistent this way. |
This comment has been minimized.
This comment has been minimized.
|
@michaelwoerister created a |
kennytm
added
S-waiting-on-review
and removed
S-waiting-on-author
labels
Oct 24, 2017
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
michaelwoerister
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Oct 25, 2017
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Oct 25, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 7fa64bc
into
rust-lang:master
Oct 25, 2017
bors
referenced this pull request
Oct 25, 2017
Merged
Avoid unnecessary copies of arguments that are simple bindings #45380
This comment has been minimized.
This comment has been minimized.
|
|
Xanewok commentedOct 23, 2017
•
edited
As discussed on gitter, this changes
crate_disambiguatorfrom 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_hashto acceptFingerprintas crate_disambiguator to quickly combine the hash ofcrate_namewith the new 128 bit hash instead of a string for a disambiguator?r? @michaelwoerister
EDIT: Are those 3 tests
mir-optfailing, 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?