11use crate :: hir:: { ModuleItems , Owner } ;
22use crate :: ty:: TyCtxt ;
33use rustc_ast as ast;
4- use rustc_data_structures:: fingerprint:: Fingerprint ;
5- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
64use rustc_data_structures:: svh:: Svh ;
75use rustc_data_structures:: sync:: { par_for_each_in, Send , Sync } ;
86use rustc_hir:: def:: { DefKind , Res } ;
@@ -13,12 +11,12 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
1311use rustc_hir:: * ;
1412use rustc_index:: vec:: Idx ;
1513use rustc_middle:: hir:: nested_filter;
16- use rustc_span:: def_id:: StableCrateId ;
1714use rustc_span:: source_map:: Spanned ;
1815use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
1916use rustc_span:: Span ;
2017use rustc_target:: spec:: abi:: Abi ;
2118use std:: collections:: VecDeque ;
19+ use std:: time:: SystemTime ;
2220
2321fn fn_decl < ' hir > ( node : Node < ' hir > ) -> Option < & ' hir FnDecl < ' hir > > {
2422 match node {
@@ -1088,69 +1086,12 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
10881086 }
10891087}
10901088
1091- pub ( super ) fn crate_hash ( tcx : TyCtxt < ' _ > , crate_num : CrateNum ) -> Svh {
1089+ pub ( super ) fn crate_hash ( _ : TyCtxt < ' _ > , crate_num : CrateNum ) -> Svh {
10921090 debug_assert_eq ! ( crate_num, LOCAL_CRATE ) ;
1093- let krate = tcx. hir_crate ( ( ) ) ;
1094- let hir_body_hash = krate. hir_hash ;
1095-
1096- let upstream_crates = upstream_crates ( tcx) ;
1097-
1098- // We hash the final, remapped names of all local source files so we
1099- // don't have to include the path prefix remapping commandline args.
1100- // If we included the full mapping in the SVH, we could only have
1101- // reproducible builds by compiling from the same directory. So we just
1102- // hash the result of the mapping instead of the mapping itself.
1103- let mut source_file_names: Vec < _ > = tcx
1104- . sess
1105- . source_map ( )
1106- . files ( )
1107- . iter ( )
1108- . filter ( |source_file| source_file. cnum == LOCAL_CRATE )
1109- . map ( |source_file| source_file. name_hash )
1110- . collect ( ) ;
1111-
1112- source_file_names. sort_unstable ( ) ;
1113-
1114- let mut hcx = tcx. create_stable_hashing_context ( ) ;
1115- let mut stable_hasher = StableHasher :: new ( ) ;
1116- hir_body_hash. hash_stable ( & mut hcx, & mut stable_hasher) ;
1117- upstream_crates. hash_stable ( & mut hcx, & mut stable_hasher) ;
1118- source_file_names. hash_stable ( & mut hcx, & mut stable_hasher) ;
1119- if tcx. sess . opts . debugging_opts . incremental_relative_spans {
1120- let definitions = & tcx. untracked_resolutions . definitions ;
1121- let mut owner_spans: Vec < _ > = krate
1122- . owners
1123- . iter_enumerated ( )
1124- . filter_map ( |( def_id, info) | {
1125- let _ = info. as_owner ( ) ?;
1126- let def_path_hash = definitions. def_path_hash ( def_id) ;
1127- let span = definitions. def_span ( def_id) ;
1128- debug_assert_eq ! ( span. parent( ) , None ) ;
1129- Some ( ( def_path_hash, span) )
1130- } )
1131- . collect ( ) ;
1132- owner_spans. sort_unstable_by_key ( |bn| bn. 0 ) ;
1133- owner_spans. hash_stable ( & mut hcx, & mut stable_hasher) ;
1134- }
1135- tcx. sess . opts . dep_tracking_hash ( true ) . hash_stable ( & mut hcx, & mut stable_hasher) ;
1136- tcx. sess . local_stable_crate_id ( ) . hash_stable ( & mut hcx, & mut stable_hasher) ;
11371091
1138- let crate_hash: Fingerprint = stable_hasher. finish ( ) ;
1139- Svh :: new ( crate_hash. to_smaller_hash ( ) )
1140- }
1141-
1142- fn upstream_crates ( tcx : TyCtxt < ' _ > ) -> Vec < ( StableCrateId , Svh ) > {
1143- let mut upstream_crates: Vec < _ > = tcx
1144- . crates ( ( ) )
1145- . iter ( )
1146- . map ( |& cnum| {
1147- let stable_crate_id = tcx. resolutions ( ( ) ) . cstore . stable_crate_id ( cnum) ;
1148- let hash = tcx. crate_hash ( cnum) ;
1149- ( stable_crate_id, hash)
1150- } )
1151- . collect ( ) ;
1152- upstream_crates. sort_unstable_by_key ( |& ( stable_crate_id, _) | stable_crate_id) ;
1153- upstream_crates
1092+ // TEST: Turn crate hash into a time-stamp/build-id
1093+ let random = SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) . unwrap ( ) . as_nanos ( ) ;
1094+ Svh :: new ( ( random as u64 ) . wrapping_add ( ( random >> 64 ) as u64 ) )
11541095}
11551096
11561097fn hir_id_to_string ( map : Map < ' _ > , id : HirId ) -> String {
0 commit comments