-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Let a portion of DefPathHash uniquely identify the DefPath's crate. #81635
Merged
bors
merged 5 commits into
rust-lang:master
from
michaelwoerister:structured_def_path_hash
Mar 8, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22d489b
Let a portion of DefPathHash uniquely identify the DefPath's crate.
michaelwoerister 6a4878f
Update UI tests affected by changed DefPathHash value construction.
michaelwoerister d4d8bdf
Add documentation to Unhasher impl for Fingerprint.
michaelwoerister 97380e3
Add more explanation to local DefPathHash collision case.
michaelwoerister 9e50544
Add unit test to ensure that both parts of a DefPathHash depend on th…
michaelwoerister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::definitions::{DefKey, DefPathData, DisambiguatedDefPathData}; | ||
use rustc_data_structures::fingerprint::Fingerprint; | ||
use rustc_span::crate_disambiguator::CrateDisambiguator; | ||
use rustc_span::def_id::{DefPathHash, StableCrateId}; | ||
|
||
#[test] | ||
fn def_path_hash_depends_on_crate_id() { | ||
// This test makes sure that *both* halves of a DefPathHash depend on | ||
// the crate-id of the defining crate. This is a desirable property | ||
// because the crate-id can be more easily changed than the DefPath | ||
// of an item, so, in the case of a crate-local DefPathHash collision, | ||
// the user can simply "role the dice again" for all DefPathHashes in | ||
// the crate by changing the crate disambiguator (e.g. via bumping the | ||
// crate's version number). | ||
|
||
let d0 = CrateDisambiguator::from(Fingerprint::new(12, 34)); | ||
let d1 = CrateDisambiguator::from(Fingerprint::new(56, 78)); | ||
|
||
let h0 = mk_test_hash("foo", d0); | ||
let h1 = mk_test_hash("foo", d1); | ||
|
||
assert_ne!(h0.stable_crate_id(), h1.stable_crate_id()); | ||
assert_ne!(h0.local_hash(), h1.local_hash()); | ||
|
||
fn mk_test_hash(crate_name: &str, crate_disambiguator: CrateDisambiguator) -> DefPathHash { | ||
let stable_crate_id = StableCrateId::new(crate_name, crate_disambiguator); | ||
let parent_hash = DefPathHash::new(stable_crate_id, 0); | ||
|
||
let key = DefKey { | ||
parent: None, | ||
disambiguated_data: DisambiguatedDefPathData { | ||
data: DefPathData::CrateRoot, | ||
disambiguator: 0, | ||
}, | ||
}; | ||
|
||
key.compute_stable_hash(parent_hash) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm. The previous version of the code had an invariant where for all u64
h
,Fingerprint::from_smaller_hash(h).to_smaller_hash() == h
, and this new version does not support that invariant (if I understand correctly).But I suppose that is also ... the point? (One workaround would be to make
from_smaller_hash
setself.0
to 0. But I would expect that to have bad fallout elsewhere...)I don't know if that invariant matters, but I'd be careful about breaking it, since its the kind of thing I would expect to hold...
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.
Okay I reviewed the code, and
from_smaller_hash
is only called in one place, onlocal_id.as_u32()
. I don't think we're making use of the invariant that I wrote above.