-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Include source file hash in crate_hash. #94301
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
---|---|---|
|
@@ -13,7 +13,6 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor; | |
use rustc_hir::*; | ||
use rustc_index::vec::Idx; | ||
use rustc_middle::hir::nested_filter; | ||
use rustc_span::def_id::StableCrateId; | ||
use rustc_span::hygiene::MacroKind; | ||
use rustc_span::source_map::Spanned; | ||
use rustc_span::symbol::{kw, sym, Ident, Symbol}; | ||
|
@@ -1094,29 +1093,37 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { | |
let krate = tcx.hir_crate(()); | ||
let hir_body_hash = krate.hir_hash; | ||
|
||
let upstream_crates = upstream_crates(tcx); | ||
|
||
// We hash the final, remapped names of all local source files so we | ||
// don't have to include the path prefix remapping commandline args. | ||
// If we included the full mapping in the SVH, we could only have | ||
// reproducible builds by compiling from the same directory. So we just | ||
// hash the result of the mapping instead of the mapping itself. | ||
let mut source_file_names: Vec<_> = tcx | ||
let mut source_file_hashes: Vec<_> = tcx | ||
.sess | ||
.source_map() | ||
.files() | ||
.iter() | ||
.filter(|source_file| source_file.cnum == LOCAL_CRATE) | ||
.map(|source_file| source_file.name_hash) | ||
.map(|source_file| (source_file.name_hash, source_file.src_hash)) | ||
.collect(); | ||
source_file_hashes.sort_unstable_by_key(|&(name_hash, _)| name_hash); | ||
|
||
source_file_names.sort_unstable(); | ||
let mut upstream_crates: Vec<_> = tcx | ||
.crates(()) | ||
.iter() | ||
.map(|&cnum| { | ||
let stable_crate_id = tcx.resolutions(()).cstore.stable_crate_id(cnum); | ||
let hash = tcx.crate_hash(cnum); | ||
(stable_crate_id, hash) | ||
}) | ||
.collect(); | ||
upstream_crates.sort_unstable_by_key(|&(stable_crate_id, _)| stable_crate_id); | ||
|
||
let mut hcx = tcx.create_stable_hashing_context(); | ||
let mut stable_hasher = StableHasher::new(); | ||
hir_body_hash.hash_stable(&mut hcx, &mut stable_hasher); | ||
upstream_crates.hash_stable(&mut hcx, &mut stable_hasher); | ||
source_file_names.hash_stable(&mut hcx, &mut stable_hasher); | ||
source_file_hashes.hash_stable(&mut hcx, &mut stable_hasher); | ||
if tcx.sess.opts.debugging_opts.incremental_relative_spans { | ||
let definitions = &tcx.untracked_resolutions.definitions; | ||
let mut owner_spans: Vec<_> = krate | ||
|
@@ -1140,20 +1147,6 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { | |
Svh::new(crate_hash.to_smaller_hash()) | ||
} | ||
|
||
fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> { | ||
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. Is there any particular reason for inlining this method? I don't have a strong preference about where this code should be, but it's currently adding unrelated changes to the diff. |
||
let mut upstream_crates: Vec<_> = tcx | ||
.crates(()) | ||
.iter() | ||
.map(|&cnum| { | ||
let stable_crate_id = tcx.resolutions(()).cstore.stable_crate_id(cnum); | ||
let hash = tcx.crate_hash(cnum); | ||
(stable_crate_id, hash) | ||
}) | ||
.collect(); | ||
upstream_crates.sort_unstable_by_key(|&(stable_crate_id, _)| stable_crate_id); | ||
upstream_crates | ||
} | ||
|
||
fn hir_id_to_string(map: Map<'_>, id: HirId) -> String { | ||
let id_str = format!(" (hir_id={})", id); | ||
|
||
|
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.
Uh oh!
There was an error while loading. Please reload this page.