9
9
// except according to those terms.
10
10
11
11
use rbml:: opaque:: Encoder ;
12
- use rustc:: dep_graph:: DepNode ;
12
+ use rustc:: dep_graph:: { DepGraphQuery , DepNode } ;
13
+ use rustc:: hir:: def_id:: DefId ;
13
14
use rustc:: middle:: cstore:: LOCAL_CRATE ;
14
15
use rustc:: session:: Session ;
15
16
use rustc:: ty:: TyCtxt ;
17
+ use rustc_data_structures:: fnv:: FnvHashMap ;
16
18
use rustc_serialize:: { Encodable as RustcEncodable } ;
17
19
use std:: hash:: { Hasher , SipHasher } ;
18
20
use std:: io:: { self , Cursor , Write } ;
@@ -99,15 +101,15 @@ pub fn encode_dep_graph<'a, 'tcx>(hcx: &mut HashContext<'a, 'tcx>,
99
101
{
100
102
let tcx = hcx. tcx ;
101
103
let query = tcx. dep_graph . query ( ) ;
104
+ let ( nodes, edges) = post_process_graph ( hcx, query) ;
102
105
103
106
let mut builder = DefIdDirectoryBuilder :: new ( tcx) ;
104
107
105
108
// Create hashes for inputs.
106
109
let hashes =
107
- query. nodes ( )
108
- . into_iter ( )
110
+ nodes. iter ( )
109
111
. filter_map ( |dep_node| {
110
- hcx. hash ( & dep_node)
112
+ hcx. hash ( dep_node)
111
113
. map ( |hash| {
112
114
let node = builder. map ( dep_node) ;
113
115
SerializedHash { node : node, hash : hash }
@@ -117,16 +119,14 @@ pub fn encode_dep_graph<'a, 'tcx>(hcx: &mut HashContext<'a, 'tcx>,
117
119
118
120
// Create the serialized dep-graph.
119
121
let graph = SerializedDepGraph {
120
- nodes : query. nodes ( ) . into_iter ( )
121
- . map ( |node| builder. map ( node) )
122
- . collect ( ) ,
123
- edges : query. edges ( ) . into_iter ( )
124
- . map ( |( source_node, target_node) | {
125
- let source = builder. map ( source_node) ;
126
- let target = builder. map ( target_node) ;
127
- ( source, target)
128
- } )
129
- . collect ( ) ,
122
+ nodes : nodes. iter ( ) . map ( |node| builder. map ( node) ) . collect ( ) ,
123
+ edges : edges. iter ( )
124
+ . map ( |& ( ref source_node, ref target_node) | {
125
+ let source = builder. map ( source_node) ;
126
+ let target = builder. map ( target_node) ;
127
+ ( source, target)
128
+ } )
129
+ . collect ( ) ,
130
130
hashes : hashes,
131
131
} ;
132
132
@@ -140,6 +140,57 @@ pub fn encode_dep_graph<'a, 'tcx>(hcx: &mut HashContext<'a, 'tcx>,
140
140
Ok ( ( ) )
141
141
}
142
142
143
+ pub fn post_process_graph < ' a , ' tcx > ( hcx : & mut HashContext < ' a , ' tcx > ,
144
+ query : DepGraphQuery < DefId > )
145
+ -> ( Vec < DepNode < DefId > > , Vec < ( DepNode < DefId > , DepNode < DefId > ) > )
146
+ {
147
+ let tcx = hcx. tcx ;
148
+ let mut cache = FnvHashMap ( ) ;
149
+
150
+ let mut uninline_def_id = |def_id : DefId | -> Option < DefId > {
151
+ if tcx. map . is_inlined_def_id ( def_id) {
152
+ Some (
153
+ cache. entry ( def_id)
154
+ . or_insert_with ( || {
155
+ let def_path = tcx. def_path ( def_id) ;
156
+ debug ! ( "post_process_graph: uninlining def-id {:?} to yield {:?}" ,
157
+ def_id, def_path) ;
158
+ let retraced_def_id = tcx. retrace_path ( & def_path) . unwrap ( ) ;
159
+ debug ! ( "post_process_graph: retraced to {:?}" , retraced_def_id) ;
160
+ retraced_def_id
161
+ } )
162
+ . clone ( ) )
163
+ } else {
164
+ None
165
+ }
166
+ } ;
167
+
168
+ let mut uninline_metadata = |node : & DepNode < DefId > | -> DepNode < DefId > {
169
+ match * node {
170
+ DepNode :: Hir ( def_id) => {
171
+ match uninline_def_id ( def_id) {
172
+ Some ( uninlined_def_id) => DepNode :: MetaData ( uninlined_def_id) ,
173
+ None => DepNode :: Hir ( def_id)
174
+ }
175
+ }
176
+ _ => node. clone ( )
177
+ }
178
+ } ;
179
+
180
+ let nodes = query. nodes ( )
181
+ . into_iter ( )
182
+ . map ( |node| uninline_metadata ( node) )
183
+ . collect ( ) ;
184
+
185
+ let edges = query. edges ( )
186
+ . into_iter ( )
187
+ . map ( |( from, to) | ( uninline_metadata ( from) , uninline_metadata ( to) ) )
188
+ . collect ( ) ;
189
+
190
+ ( nodes, edges)
191
+ }
192
+
193
+
143
194
pub fn encode_metadata_hashes < ' a , ' tcx > ( hcx : & mut HashContext < ' a , ' tcx > ,
144
195
encoder : & mut Encoder )
145
196
-> io:: Result < ( ) >
0 commit comments