2828//! at the beginning.
2929
3030use syntax:: ast;
31+ use std:: cell:: RefCell ;
3132use std:: hash:: { Hash , SipHasher , Hasher } ;
3233use rustc:: dep_graph:: DepNode ;
3334use rustc:: hir;
@@ -46,7 +47,42 @@ mod def_path_hash;
4647mod svh_visitor;
4748mod caching_codemap_view;
4849
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+
5086
5187pub fn compute_incremental_hashes_map < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > )
5288 -> IncrementalHashesMap {
@@ -55,7 +91,7 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
5591 let hash_spans = tcx. sess . opts . debuginfo != NoDebugInfo ;
5692 let mut visitor = HashItemsVisitor {
5793 tcx : tcx,
58- hashes : FnvHashMap ( ) ,
94+ hashes : IncrementalHashesMap :: new ( ) ,
5995 def_path_hashes : DefPathHashes :: new ( tcx) ,
6096 codemap : CachingCodemapView :: new ( tcx) ,
6197 hash_spans : hash_spans,
0 commit comments