@@ -6,7 +6,7 @@ use rustc_data_structures::svh::Svh;
6
6
use rustc_data_structures:: sync:: { DynSend , DynSync , par_for_each_in, try_par_for_each_in} ;
7
7
use rustc_hir:: def:: { DefKind , Res } ;
8
8
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE , LocalDefId , LocalModDefId } ;
9
- use rustc_hir:: definitions:: { DefKey , DefPath , DefPathHash } ;
9
+ use rustc_hir:: definitions:: { DefKey , DefPath , Definitions } ;
10
10
use rustc_hir:: intravisit:: Visitor ;
11
11
use rustc_hir:: * ;
12
12
use rustc_hir_pretty as pprust_hir;
@@ -193,12 +193,6 @@ impl<'tcx> TyCtxt<'tcx> {
193
193
self . definitions_untracked ( ) . def_path ( def_id)
194
194
}
195
195
196
- #[ inline]
197
- pub fn hir_def_path_hash ( self , def_id : LocalDefId ) -> DefPathHash {
198
- // Accessing the DefPathHash is ok, it is incr. comp. stable.
199
- self . definitions_untracked ( ) . def_path_hash ( def_id)
200
- }
201
-
202
196
pub fn hir_get_if_local ( self , id : DefId ) -> Option < Node < ' tcx > > {
203
197
id. as_local ( ) . map ( |id| self . hir_node_by_def_id ( id) )
204
198
}
@@ -1130,9 +1124,32 @@ impl<'tcx> pprust_hir::PpAnn for TyCtxt<'tcx> {
1130
1124
}
1131
1125
}
1132
1126
1127
+ /// Compute the hash for the HIR of the full crate.
1128
+ /// This hash will then be part of the crate_hash which is stored in the metadata.
1129
+ fn compute_hir_hash ( tcx : TyCtxt < ' _ > , definitions : & Definitions ) -> Fingerprint {
1130
+ let mut hir_body_nodes: Vec < _ > = tcx
1131
+ . hir_crate_items ( ( ) )
1132
+ . owners ( )
1133
+ . map ( |owner_id| {
1134
+ let def_path_hash = definitions. def_path_hash ( owner_id. def_id ) ;
1135
+ let nodes = tcx. opt_hir_owner_nodes ( owner_id) . unwrap ( ) ;
1136
+ let attrs = tcx. hir_attr_map ( owner_id) ;
1137
+ let in_scope_traits_map = tcx. in_scope_traits_map ( owner_id) . unwrap ( ) ;
1138
+ ( def_path_hash, nodes, attrs, in_scope_traits_map)
1139
+ } )
1140
+ . collect ( ) ;
1141
+ hir_body_nodes. sort_unstable_by_key ( |bn| bn. 0 ) ;
1142
+
1143
+ tcx. with_stable_hashing_context ( |mut hcx| {
1144
+ let mut stable_hasher = StableHasher :: new ( ) ;
1145
+ hir_body_nodes. hash_stable ( & mut hcx, & mut stable_hasher) ;
1146
+ stable_hasher. finish ( )
1147
+ } )
1148
+ }
1149
+
1133
1150
pub ( super ) fn crate_hash ( tcx : TyCtxt < ' _ > , _: LocalCrate ) -> Svh {
1134
- let krate = tcx. hir_crate ( ( ) ) ;
1135
- let hir_body_hash = krate . opt_hir_hash . expect ( "HIR hash missing while computing crate hash" ) ;
1151
+ let definitions = tcx. untracked ( ) . definitions . freeze ( ) ;
1152
+ let hir_body_hash = compute_hir_hash ( tcx , definitions ) ;
1136
1153
1137
1154
let upstream_crates = upstream_crates ( tcx) ;
1138
1155
@@ -1175,16 +1192,14 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
1175
1192
source_file_names. hash_stable ( & mut hcx, & mut stable_hasher) ;
1176
1193
debugger_visualizers. hash_stable ( & mut hcx, & mut stable_hasher) ;
1177
1194
if tcx. sess . opts . incremental . is_some ( ) {
1178
- let definitions = tcx. untracked ( ) . definitions . freeze ( ) ;
1179
- let mut owner_spans: Vec < _ > = krate
1180
- . owners
1181
- . iter_enumerated ( )
1182
- . filter_map ( |( def_id, info) | {
1183
- let _ = info. as_owner ( ) ?;
1195
+ let mut owner_spans: Vec < _ > = tcx
1196
+ . hir_crate_items ( ( ) )
1197
+ . definitions ( )
1198
+ . map ( |def_id| {
1184
1199
let def_path_hash = definitions. def_path_hash ( def_id) ;
1185
1200
let span = tcx. source_span ( def_id) ;
1186
1201
debug_assert_eq ! ( span. parent( ) , None ) ;
1187
- Some ( ( def_path_hash, span) )
1202
+ ( def_path_hash, span)
1188
1203
} )
1189
1204
. collect ( ) ;
1190
1205
owner_spans. sort_unstable_by_key ( |bn| bn. 0 ) ;
0 commit comments