28
28
//! at the beginning.
29
29
30
30
use syntax:: ast;
31
+ use std:: cell:: RefCell ;
31
32
use std:: hash:: { Hash , SipHasher , Hasher } ;
32
33
use rustc:: dep_graph:: DepNode ;
33
34
use rustc:: hir;
@@ -46,7 +47,42 @@ mod def_path_hash;
46
47
mod svh_visitor;
47
48
mod caching_codemap_view;
48
49
49
- pub type IncrementalHashesMap = FnvHashMap < DepNode < DefId > , u64 > ;
50
+ pub struct IncrementalHashesMap {
51
+ hashes : FnvHashMap < DepNode < DefId > , u64 > ,
52
+
53
+ // These are the metadata hashes for the current crate as they were stored
54
+ // during the last compilation session. They are only loaded if
55
+ // -Z query-dep-graph was specified and are needed for auto-tests using
56
+ // the #[rustc_metadata_dirty] and #[rustc_metadata_clean] attributes to
57
+ // check whether some metadata hash has changed in between two revisions.
58
+ pub prev_metadata_hashes : RefCell < FnvHashMap < DefId , u64 > > ,
59
+ }
60
+
61
+ impl IncrementalHashesMap {
62
+ pub fn new ( ) -> IncrementalHashesMap {
63
+ IncrementalHashesMap {
64
+ hashes : FnvHashMap ( ) ,
65
+ prev_metadata_hashes : RefCell :: new ( FnvHashMap ( ) ) ,
66
+ }
67
+ }
68
+
69
+ pub fn insert ( & mut self , k : DepNode < DefId > , v : u64 ) -> Option < u64 > {
70
+ self . hashes . insert ( k, v)
71
+ }
72
+
73
+ pub fn iter < ' a > ( & ' a self ) -> :: std:: collections:: hash_map:: Iter < ' a , DepNode < DefId > , u64 > {
74
+ self . hashes . iter ( )
75
+ }
76
+ }
77
+
78
+ impl < ' a > :: std:: ops:: Index < & ' a DepNode < DefId > > for IncrementalHashesMap {
79
+ type Output = u64 ;
80
+
81
+ fn index ( & self , index : & ' a DepNode < DefId > ) -> & u64 {
82
+ & self . hashes [ index]
83
+ }
84
+ }
85
+
50
86
51
87
pub fn compute_incremental_hashes_map < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > )
52
88
-> IncrementalHashesMap {
@@ -55,7 +91,7 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
55
91
let hash_spans = tcx. sess . opts . debuginfo != NoDebugInfo ;
56
92
let mut visitor = HashItemsVisitor {
57
93
tcx : tcx,
58
- hashes : FnvHashMap ( ) ,
94
+ hashes : IncrementalHashesMap :: new ( ) ,
59
95
def_path_hashes : DefPathHashes :: new ( tcx) ,
60
96
codemap : CachingCodemapView :: new ( tcx) ,
61
97
hash_spans : hash_spans,
0 commit comments