1
1
use crate :: hir:: { ModuleItems , Owner } ;
2
2
use crate :: ty:: TyCtxt ;
3
3
use rustc_ast as ast;
4
- use rustc_data_structures:: fingerprint:: Fingerprint ;
5
- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
6
4
use rustc_data_structures:: svh:: Svh ;
7
5
use rustc_data_structures:: sync:: { par_for_each_in, Send , Sync } ;
8
6
use rustc_hir:: def:: { DefKind , Res } ;
@@ -13,12 +11,12 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
13
11
use rustc_hir:: * ;
14
12
use rustc_index:: vec:: Idx ;
15
13
use rustc_middle:: hir:: nested_filter;
16
- use rustc_span:: def_id:: StableCrateId ;
17
14
use rustc_span:: source_map:: Spanned ;
18
15
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
19
16
use rustc_span:: Span ;
20
17
use rustc_target:: spec:: abi:: Abi ;
21
18
use std:: collections:: VecDeque ;
19
+ use std:: time:: SystemTime ;
22
20
23
21
fn fn_decl < ' hir > ( node : Node < ' hir > ) -> Option < & ' hir FnDecl < ' hir > > {
24
22
match node {
@@ -1088,69 +1086,12 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
1088
1086
}
1089
1087
}
1090
1088
1091
- pub ( super ) fn crate_hash ( tcx : TyCtxt < ' _ > , crate_num : CrateNum ) -> Svh {
1089
+ pub ( super ) fn crate_hash ( _ : TyCtxt < ' _ > , crate_num : CrateNum ) -> Svh {
1092
1090
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) ;
1137
1091
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 ) )
1154
1095
}
1155
1096
1156
1097
fn hir_id_to_string ( map : Map < ' _ > , id : HirId ) -> String {
0 commit comments