1
1
use rustc_data_structures:: fingerprint:: Fingerprint ;
2
2
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
3
3
use rustc_data_structures:: svh:: Svh ;
4
- use rustc_hir:: def_id:: { CrateNum , LocalDefId , StableCrateId , LOCAL_CRATE } ;
4
+ use rustc_hir:: def_id:: { CrateNum , LocalDefId , StableCrateId , CRATE_DEF_ID , LOCAL_CRATE } ;
5
5
use rustc_hir:: intravisit:: { self , Visitor } ;
6
- use rustc_hir:: { ForeignItem , ImplItem , Item , ItemKind , Mod , TraitItem } ;
6
+ use rustc_hir:: { Crate , ForeignItem , ImplItem , Item , ItemKind , Mod , TraitItem } ;
7
7
use rustc_hir:: { ForeignItemId , HirId , ImplItemId , ItemId , ModuleItems , TraitItemId } ;
8
8
use rustc_middle:: hir:: nested_filter;
9
9
use rustc_middle:: ty:: query:: Providers ;
10
10
use rustc_middle:: ty:: TyCtxt ;
11
- use rustc_span:: Span ;
11
+ use rustc_span:: { Span , DUMMY_SP } ;
12
12
13
13
pub fn provide ( providers : & mut Providers ) {
14
- * providers = Providers { crate_hash, hir_module_items, hir_crate_items, ..* providers } ;
14
+ * providers =
15
+ Providers { hir_crate, crate_hash, hir_module_items, hir_crate_items, ..* providers } ;
16
+ }
17
+
18
+ fn hir_crate < ' tcx > ( tcx : TyCtxt < ' tcx > , ( ) : ( ) ) -> Crate < ' tcx > {
19
+ let mut collector = CrateCollector { tcx, owners : vec ! [ CRATE_DEF_ID ] } ;
20
+ tcx. hir ( ) . walk_toplevel_module ( & mut collector) ;
21
+ let owners = tcx. arena . alloc_from_iter ( collector. owners ) ;
22
+
23
+ // Discard hygiene data, which isn't required after lowering to HIR.
24
+ if !tcx. sess . opts . debugging_opts . keep_hygiene_data {
25
+ rustc_span:: hygiene:: clear_syntax_context_map ( ) ;
26
+ }
27
+
28
+ return Crate { owners } ;
29
+
30
+ struct CrateCollector < ' tcx > {
31
+ tcx : TyCtxt < ' tcx > ,
32
+ owners : Vec < LocalDefId > ,
33
+ }
34
+
35
+ impl < ' hir > Visitor < ' hir > for CrateCollector < ' hir > {
36
+ type NestedFilter = nested_filter:: All ;
37
+
38
+ fn nested_visit_map ( & mut self ) -> Self :: Map {
39
+ self . tcx . hir ( )
40
+ }
41
+
42
+ fn visit_item ( & mut self , item : & ' hir Item < ' hir > ) {
43
+ self . owners . push ( item. def_id ) ;
44
+ intravisit:: walk_item ( self , item)
45
+ }
46
+
47
+ fn visit_trait_item ( & mut self , item : & ' hir TraitItem < ' hir > ) {
48
+ self . owners . push ( item. def_id ) ;
49
+ intravisit:: walk_trait_item ( self , item)
50
+ }
51
+
52
+ fn visit_impl_item ( & mut self , item : & ' hir ImplItem < ' hir > ) {
53
+ self . owners . push ( item. def_id ) ;
54
+ intravisit:: walk_impl_item ( self , item)
55
+ }
56
+
57
+ fn visit_foreign_item ( & mut self , item : & ' hir ForeignItem < ' hir > ) {
58
+ self . owners . push ( item. def_id ) ;
59
+ intravisit:: walk_foreign_item ( self , item)
60
+ }
61
+ }
15
62
}
16
63
17
64
fn crate_hash ( tcx : TyCtxt < ' _ > , crate_num : CrateNum ) -> Svh {
18
65
debug_assert_eq ! ( crate_num, LOCAL_CRATE ) ;
19
66
let krate = tcx. hir_crate ( ( ) ) ;
20
- let hir_body_hash = krate. hir_hash ;
67
+ let definitions = tcx. definitions_untracked ( ) ;
68
+
69
+ let mut hir_body_nodes: Vec < _ > = krate
70
+ . owners
71
+ . iter ( )
72
+ . map ( |& def_id| {
73
+ let def_path_hash = tcx. hir ( ) . def_path_hash ( def_id) ;
74
+ let info = tcx. lower_to_hir ( def_id) . unwrap ( ) ;
75
+ let span = if tcx. sess . opts . debugging_opts . incremental_relative_spans {
76
+ definitions. def_span ( def_id)
77
+ } else {
78
+ DUMMY_SP
79
+ } ;
80
+ debug_assert_eq ! ( span. parent( ) , None ) ;
81
+ ( def_path_hash, info, span)
82
+ } )
83
+ . collect ( ) ;
84
+ hir_body_nodes. sort_unstable_by_key ( |bn| bn. 0 ) ;
21
85
22
86
let upstream_crates = upstream_crates ( tcx) ;
23
87
@@ -39,25 +103,9 @@ fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
39
103
40
104
let crate_hash: Fingerprint = tcx. with_stable_hashing_context ( |mut hcx| {
41
105
let mut stable_hasher = StableHasher :: new ( ) ;
42
- hir_body_hash . hash_stable ( & mut hcx, & mut stable_hasher) ;
106
+ hir_body_nodes . hash_stable ( & mut hcx, & mut stable_hasher) ;
43
107
upstream_crates. hash_stable ( & mut hcx, & mut stable_hasher) ;
44
108
source_file_names. hash_stable ( & mut hcx, & mut stable_hasher) ;
45
- if tcx. sess . opts . debugging_opts . incremental_relative_spans {
46
- let definitions = tcx. definitions_untracked ( ) ;
47
- let mut owner_spans: Vec < _ > = krate
48
- . owners
49
- . iter_enumerated ( )
50
- . filter_map ( |( def_id, info) | {
51
- let _ = info. as_owner ( ) ?;
52
- let def_path_hash = definitions. def_path_hash ( def_id) ;
53
- let span = definitions. def_span ( def_id) ;
54
- debug_assert_eq ! ( span. parent( ) , None ) ;
55
- Some ( ( def_path_hash, span) )
56
- } )
57
- . collect ( ) ;
58
- owner_spans. sort_unstable_by_key ( |bn| bn. 0 ) ;
59
- owner_spans. hash_stable ( & mut hcx, & mut stable_hasher) ;
60
- }
61
109
tcx. sess . opts . dep_tracking_hash ( true ) . hash_stable ( & mut hcx, & mut stable_hasher) ;
62
110
tcx. sess . local_stable_crate_id ( ) . hash_stable ( & mut hcx, & mut stable_hasher) ;
63
111
// Hash visibility information since it does not appear in HIR.
0 commit comments