@@ -2,21 +2,19 @@ use crate::arena::Arena;
22use crate :: hir:: map:: { Entry , HirOwnerData , Map } ;
33use crate :: hir:: { Owner , OwnerNodes , ParentedNode } ;
44use crate :: ich:: StableHashingContext ;
5- use crate :: middle:: cstore:: CrateStore ;
65use rustc_data_structures:: fingerprint:: Fingerprint ;
76use rustc_data_structures:: fx:: FxHashMap ;
87use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
9- use rustc_data_structures:: svh:: Svh ;
108use rustc_hir as hir;
9+ use rustc_hir:: def_id:: LocalDefId ;
1110use rustc_hir:: def_id:: CRATE_DEF_INDEX ;
12- use rustc_hir:: def_id:: { LocalDefId , LOCAL_CRATE } ;
13- use rustc_hir:: definitions:: { self , DefPathHash } ;
11+ use rustc_hir:: definitions;
1412use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
1513use rustc_hir:: * ;
1614use rustc_index:: vec:: { Idx , IndexVec } ;
17- use rustc_session:: { CrateDisambiguator , Session } ;
15+ use rustc_session:: Session ;
1816use rustc_span:: source_map:: SourceMap ;
19- use rustc_span:: { Span , Symbol , DUMMY_SP } ;
17+ use rustc_span:: { Span , DUMMY_SP } ;
2018
2119use std:: iter:: repeat;
2220
@@ -40,10 +38,6 @@ pub(super) struct NodeCollector<'a, 'hir> {
4038 definitions : & ' a definitions:: Definitions ,
4139
4240 hcx : StableHashingContext < ' a > ,
43-
44- // We are collecting HIR hashes here so we can compute the
45- // crate hash from them later on.
46- hir_body_nodes : Vec < ( DefPathHash , Fingerprint ) > ,
4741}
4842
4943fn insert_vec_map < K : Idx , V : Clone > ( map : & mut IndexVec < K , Option < V > > , k : K , v : V ) {
@@ -58,34 +52,13 @@ fn insert_vec_map<K: Idx, V: Clone>(map: &mut IndexVec<K, Option<V>>, k: K, v: V
5852
5953fn hash_body (
6054 hcx : & mut StableHashingContext < ' _ > ,
61- def_path_hash : DefPathHash ,
6255 item_like : impl for < ' a > HashStable < StableHashingContext < ' a > > ,
63- hir_body_nodes : & mut Vec < ( DefPathHash , Fingerprint ) > ,
6456) -> Fingerprint {
65- let hash = {
66- let mut stable_hasher = StableHasher :: new ( ) ;
67- hcx. while_hashing_hir_bodies ( true , |hcx| {
68- item_like. hash_stable ( hcx, & mut stable_hasher) ;
69- } ) ;
70- stable_hasher. finish ( )
71- } ;
72- hir_body_nodes. push ( ( def_path_hash, hash) ) ;
73- hash
74- }
75-
76- fn upstream_crates ( cstore : & dyn CrateStore ) -> Vec < ( Symbol , Fingerprint , Svh ) > {
77- let mut upstream_crates: Vec < _ > = cstore
78- . crates_untracked ( )
79- . iter ( )
80- . map ( |& cnum| {
81- let name = cstore. crate_name_untracked ( cnum) ;
82- let disambiguator = cstore. crate_disambiguator_untracked ( cnum) . to_fingerprint ( ) ;
83- let hash = cstore. crate_hash_untracked ( cnum) ;
84- ( name, disambiguator, hash)
85- } )
86- . collect ( ) ;
87- upstream_crates. sort_unstable_by_key ( |& ( name, dis, _) | ( name. as_str ( ) , dis) ) ;
88- upstream_crates
57+ let mut stable_hasher = StableHasher :: new ( ) ;
58+ hcx. while_hashing_hir_bodies ( true , |hcx| {
59+ item_like. hash_stable ( hcx, & mut stable_hasher) ;
60+ } ) ;
61+ stable_hasher. finish ( )
8962}
9063
9164impl < ' a , ' hir > NodeCollector < ' a , ' hir > {
@@ -96,11 +69,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
9669 definitions : & ' a definitions:: Definitions ,
9770 mut hcx : StableHashingContext < ' a > ,
9871 ) -> NodeCollector < ' a , ' hir > {
99- let root_mod_def_path_hash =
100- definitions. def_path_hash ( LocalDefId { local_def_index : CRATE_DEF_INDEX } ) ;
101-
102- let mut hir_body_nodes = Vec :: new ( ) ;
103-
10472 let hash = {
10573 let Crate {
10674 ref item,
@@ -120,7 +88,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
12088 attrs : _,
12189 } = * krate;
12290
123- hash_body ( & mut hcx, root_mod_def_path_hash , item, & mut hir_body_nodes )
91+ hash_body ( & mut hcx, item)
12492 } ;
12593
12694 let mut collector = NodeCollector {
@@ -131,7 +99,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
13199 current_dep_node_owner : LocalDefId { local_def_index : CRATE_DEF_INDEX } ,
132100 definitions,
133101 hcx,
134- hir_body_nodes,
135102 map : ( 0 ..definitions. def_index_count ( ) )
136103 . map ( |_| HirOwnerData { signature : None , with_bodies : None } )
137104 . collect ( ) ,
@@ -147,53 +114,13 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
147114
148115 pub ( super ) fn finalize_and_compute_crate_hash (
149116 mut self ,
150- crate_disambiguator : CrateDisambiguator ,
151- cstore : & dyn CrateStore ,
152- commandline_args_hash : u64 ,
153- ) -> ( IndexVec < LocalDefId , HirOwnerData < ' hir > > , Svh ) {
117+ ) -> IndexVec < LocalDefId , HirOwnerData < ' hir > > {
154118 // Insert bodies into the map
155119 for ( id, body) in self . krate . bodies . iter ( ) {
156120 let bodies = & mut self . map [ id. hir_id . owner ] . with_bodies . as_mut ( ) . unwrap ( ) . bodies ;
157121 assert ! ( bodies. insert( id. hir_id. local_id, body) . is_none( ) ) ;
158122 }
159-
160- self . hir_body_nodes . sort_unstable_by_key ( |bn| bn. 0 ) ;
161-
162- let node_hashes = self . hir_body_nodes . iter ( ) . fold (
163- Fingerprint :: ZERO ,
164- |combined_fingerprint, & ( def_path_hash, fingerprint) | {
165- combined_fingerprint. combine ( def_path_hash. 0 . combine ( fingerprint) )
166- } ,
167- ) ;
168-
169- let upstream_crates = upstream_crates ( cstore) ;
170-
171- // We hash the final, remapped names of all local source files so we
172- // don't have to include the path prefix remapping commandline args.
173- // If we included the full mapping in the SVH, we could only have
174- // reproducible builds by compiling from the same directory. So we just
175- // hash the result of the mapping instead of the mapping itself.
176- let mut source_file_names: Vec < _ > = self
177- . source_map
178- . files ( )
179- . iter ( )
180- . filter ( |source_file| source_file. cnum == LOCAL_CRATE )
181- . map ( |source_file| source_file. name_hash )
182- . collect ( ) ;
183-
184- source_file_names. sort_unstable ( ) ;
185-
186- let crate_hash_input = (
187- ( ( node_hashes, upstream_crates) , source_file_names) ,
188- ( commandline_args_hash, crate_disambiguator. to_fingerprint ( ) ) ,
189- ) ;
190-
191- let mut stable_hasher = StableHasher :: new ( ) ;
192- crate_hash_input. hash_stable ( & mut self . hcx , & mut stable_hasher) ;
193- let crate_hash: Fingerprint = stable_hasher. finish ( ) ;
194-
195- let svh = Svh :: new ( crate_hash. to_smaller_hash ( ) ) ;
196- ( self . map , svh)
123+ self . map
197124 }
198125
199126 fn insert_entry ( & mut self , id : HirId , entry : Entry < ' hir > , hash : Fingerprint ) {
@@ -294,10 +221,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
294221 f : F ,
295222 ) {
296223 let prev_owner = self . current_dep_node_owner ;
297-
298- let def_path_hash = self . definitions . def_path_hash ( dep_node_owner) ;
299-
300- let hash = hash_body ( & mut self . hcx , def_path_hash, item_like, & mut self . hir_body_nodes ) ;
224+ let hash = hash_body ( & mut self . hcx , item_like) ;
301225
302226 self . current_dep_node_owner = dep_node_owner;
303227 f ( self , hash) ;
0 commit comments