@@ -25,6 +25,7 @@ use tydecode::TyDecoder;
2525
2626use rustc:: hir:: svh:: Svh ;
2727use rustc:: hir:: map as hir_map;
28+ use rustc:: hir:: map:: DefKey ;
2829use rustc:: util:: nodemap:: FnvHashMap ;
2930use rustc:: hir;
3031use rustc:: session:: config:: PanicStrategy ;
@@ -95,6 +96,29 @@ pub fn load_xrefs(data: &[u8]) -> index::DenseIndex {
9596 index:: DenseIndex :: from_buf ( index. data , index. start , index. end )
9697}
9798
99+ // Go through each item in the metadata and create a map from that
100+ // item's def-key to the item's DefIndex.
101+ pub fn load_key_map ( data : & [ u8 ] ) -> FnvHashMap < DefKey , DefIndex > {
102+ let root_doc = rbml:: Doc :: new ( data) ;
103+ let items_doc = reader:: get_doc ( root_doc, tag_items) ;
104+ let items_data_doc = reader:: get_doc ( items_doc, tag_items_data) ;
105+ reader:: docs ( items_data_doc)
106+ . filter ( |& ( tag, _) | tag == tag_items_data_item)
107+ . map ( |( _, item_doc) | {
108+ // load def-key from item
109+ let key = item_def_key ( item_doc) ;
110+
111+ // load def-index from item; we only encode the full def-id,
112+ // so just pull out the index
113+ let def_id_doc = reader:: get_doc ( item_doc, tag_def_id) ;
114+ let def_id = untranslated_def_id ( def_id_doc) ;
115+ assert ! ( def_id. is_local( ) ) ; // local to the crate we are decoding, that is
116+
117+ ( key, def_id. index )
118+ } )
119+ . collect ( )
120+ }
121+
98122#[ derive( Clone , Copy , Debug , PartialEq ) ]
99123enum Family {
100124 ImmStatic , // c
@@ -193,10 +217,14 @@ fn item_symbol(item: rbml::Doc) -> String {
193217 reader:: get_doc ( item, tag_items_data_item_symbol) . as_str ( ) . to_string ( )
194218}
195219
196- fn translated_def_id ( cdata : Cmd , d : rbml:: Doc ) -> DefId {
220+ fn untranslated_def_id ( d : rbml:: Doc ) -> DefId {
197221 let id = reader:: doc_as_u64 ( d) ;
198222 let index = DefIndex :: new ( ( id & 0xFFFF_FFFF ) as usize ) ;
199- let def_id = DefId { krate : ( id >> 32 ) as u32 , index : index } ;
223+ DefId { krate : ( id >> 32 ) as u32 , index : index }
224+ }
225+
226+ fn translated_def_id ( cdata : Cmd , d : rbml:: Doc ) -> DefId {
227+ let def_id = untranslated_def_id ( d) ;
200228 translate_def_id ( cdata, def_id)
201229}
202230
@@ -1750,6 +1778,10 @@ pub fn closure_ty<'a, 'tcx>(cdata: Cmd, closure_id: DefIndex, tcx: TyCtxt<'a, 't
17501778pub fn def_key ( cdata : Cmd , id : DefIndex ) -> hir_map:: DefKey {
17511779 debug ! ( "def_key: id={:?}" , id) ;
17521780 let item_doc = cdata. lookup_item ( id) ;
1781+ item_def_key ( item_doc)
1782+ }
1783+
1784+ fn item_def_key ( item_doc : rbml:: Doc ) -> hir_map:: DefKey {
17531785 match reader:: maybe_get_doc ( item_doc, tag_def_key) {
17541786 Some ( def_key_doc) => {
17551787 let mut decoder = reader:: Decoder :: new ( def_key_doc) ;
0 commit comments