8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- //! Debugging code to test the state of the dependency graph just
12
- //! after it is loaded from disk and just after it has been saved.
11
+ //! Debugging code to test fingerprints computed for query results.
13
12
//! For each node marked with `#[rustc_clean]` or `#[rustc_dirty]`,
14
- //! we will check that a suitable node for that item either appears
15
- //! or does not appear in the dep-graph, as appropriate:
13
+ //! we will compare the fingerprint from the current and from the previous
14
+ //! compilation session as appropriate:
16
15
//!
17
16
//! - `#[rustc_dirty(label="TypeckTables", cfg="rev2")]` if we are
18
- //! in `#[cfg(rev2)]`, then there MUST NOT be a node
19
- //! `DepNode::TypeckTables(X)` where `X` is the def-id of the
20
- //! current node.
17
+ //! in `#[cfg(rev2)]`, then the fingerprints associated with
18
+ //! `DepNode::TypeckTables(X)` must be DIFFERENT ( `X` is the def-id of the
19
+ //! current node) .
21
20
//! - `#[rustc_clean(label="TypeckTables", cfg="rev2")]` same as above,
22
- //! except that the node MUST exist .
21
+ //! except that the fingerprints must be the SAME .
23
22
//!
24
23
//! Errors are reported if we are in the suitable configuration but
25
24
//! the required condition is not met.
40
39
//! previous revision to compare things to.
41
40
//!
42
41
43
- use super :: data:: DepNodeIndex ;
44
- use super :: load:: DirtyNodes ;
45
- use rustc:: dep_graph:: { DepGraphQuery , DepNode , DepKind } ;
42
+ use rustc:: dep_graph:: DepNode ;
46
43
use rustc:: hir;
47
44
use rustc:: hir:: def_id:: DefId ;
48
45
use rustc:: hir:: itemlikevisit:: ItemLikeVisitor ;
@@ -51,41 +48,22 @@ use rustc::ich::{Fingerprint, ATTR_DIRTY, ATTR_CLEAN, ATTR_DIRTY_METADATA,
51
48
ATTR_CLEAN_METADATA } ;
52
49
use syntax:: ast:: { self , Attribute , NestedMetaItem } ;
53
50
use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
54
- use rustc_data_structures:: indexed_vec:: IndexVec ;
55
51
use syntax_pos:: Span ;
56
52
use rustc:: ty:: TyCtxt ;
57
53
58
54
const LABEL : & ' static str = "label" ;
59
55
const CFG : & ' static str = "cfg" ;
60
56
61
- pub fn check_dirty_clean_annotations < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
62
- nodes : & IndexVec < DepNodeIndex , DepNode > ,
63
- dirty_inputs : & DirtyNodes ) {
57
+ pub fn check_dirty_clean_annotations < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) {
64
58
// can't add `#[rustc_dirty]` etc without opting in to this feature
65
59
if !tcx. sess . features . borrow ( ) . rustc_attrs {
66
60
return ;
67
61
}
68
62
69
63
let _ignore = tcx. dep_graph . in_ignore ( ) ;
70
- let dirty_inputs: FxHashSet < DepNode > =
71
- dirty_inputs. keys ( )
72
- . filter_map ( |dep_node_index| {
73
- let dep_node = nodes[ * dep_node_index] ;
74
- if dep_node. extract_def_id ( tcx) . is_some ( ) {
75
- Some ( dep_node)
76
- } else {
77
- None
78
- }
79
- } )
80
- . collect ( ) ;
81
-
82
- let query = tcx. dep_graph . query ( ) ;
83
- debug ! ( "query-nodes: {:?}" , query. nodes( ) ) ;
84
64
let krate = tcx. hir . krate ( ) ;
85
65
let mut dirty_clean_visitor = DirtyCleanVisitor {
86
66
tcx,
87
- query : & query,
88
- dirty_inputs,
89
67
checked_attrs : FxHashSet ( ) ,
90
68
} ;
91
69
krate. visit_all_item_likes ( & mut dirty_clean_visitor) ;
@@ -105,8 +83,6 @@ pub fn check_dirty_clean_annotations<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
105
83
106
84
pub struct DirtyCleanVisitor < ' a , ' tcx : ' a > {
107
85
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
108
- query : & ' a DepGraphQuery ,
109
- dirty_inputs : FxHashSet < DepNode > ,
110
86
checked_attrs : FxHashSet < ast:: AttrId > ,
111
87
}
112
88
@@ -143,59 +119,28 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
143
119
fn assert_dirty ( & self , item_span : Span , dep_node : DepNode ) {
144
120
debug ! ( "assert_dirty({:?})" , dep_node) ;
145
121
146
- match dep_node. kind {
147
- DepKind :: Krate |
148
- DepKind :: Hir |
149
- DepKind :: HirBody => {
150
- // HIR nodes are inputs, so if we are asserting that the HIR node is
151
- // dirty, we check the dirty input set.
152
- if !self . dirty_inputs . contains ( & dep_node) {
153
- let dep_node_str = self . dep_node_str ( & dep_node) ;
154
- self . tcx . sess . span_err (
155
- item_span,
156
- & format ! ( "`{}` not found in dirty set, but should be dirty" ,
157
- dep_node_str) ) ;
158
- }
159
- }
160
- _ => {
161
- // Other kinds of nodes would be targets, so check if
162
- // the dep-graph contains the node.
163
- if self . query . contains_node ( & dep_node) {
164
- let dep_node_str = self . dep_node_str ( & dep_node) ;
165
- self . tcx . sess . span_err (
166
- item_span,
167
- & format ! ( "`{}` found in dep graph, but should be dirty" , dep_node_str) ) ;
168
- }
169
- }
122
+ let current_fingerprint = self . tcx . dep_graph . fingerprint_of ( & dep_node) ;
123
+ let prev_fingerprint = self . tcx . dep_graph . prev_fingerprint_of ( & dep_node) ;
124
+
125
+ if current_fingerprint == prev_fingerprint {
126
+ let dep_node_str = self . dep_node_str ( & dep_node) ;
127
+ self . tcx . sess . span_err (
128
+ item_span,
129
+ & format ! ( "`{}` should be dirty but is not" , dep_node_str) ) ;
170
130
}
171
131
}
172
132
173
133
fn assert_clean ( & self , item_span : Span , dep_node : DepNode ) {
174
134
debug ! ( "assert_clean({:?})" , dep_node) ;
175
135
176
- match dep_node. kind {
177
- DepKind :: Krate |
178
- DepKind :: Hir |
179
- DepKind :: HirBody => {
180
- // For HIR nodes, check the inputs.
181
- if self . dirty_inputs . contains ( & dep_node) {
182
- let dep_node_str = self . dep_node_str ( & dep_node) ;
183
- self . tcx . sess . span_err (
184
- item_span,
185
- & format ! ( "`{}` found in dirty-node set, but should be clean" ,
186
- dep_node_str) ) ;
187
- }
188
- }
189
- _ => {
190
- // Otherwise, check if the dep-node exists.
191
- if !self . query . contains_node ( & dep_node) {
192
- let dep_node_str = self . dep_node_str ( & dep_node) ;
193
- self . tcx . sess . span_err (
194
- item_span,
195
- & format ! ( "`{}` not found in dep graph, but should be clean" ,
196
- dep_node_str) ) ;
197
- }
198
- }
136
+ let current_fingerprint = self . tcx . dep_graph . fingerprint_of ( & dep_node) ;
137
+ let prev_fingerprint = self . tcx . dep_graph . prev_fingerprint_of ( & dep_node) ;
138
+
139
+ if current_fingerprint != prev_fingerprint {
140
+ let dep_node_str = self . dep_node_str ( & dep_node) ;
141
+ self . tcx . sess . span_err (
142
+ item_span,
143
+ & format ! ( "`{}` should be clean but is not" , dep_node_str) ) ;
199
144
}
200
145
}
201
146
0 commit comments