@@ -25,7 +25,7 @@ use middle::cstore::{LOCAL_CRATE, InlinedItemRef, LinkMeta, tls};
25
25
use rustc:: hir:: def;
26
26
use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , DefId } ;
27
27
use middle:: dependency_format:: Linkage ;
28
- use rustc:: dep_graph:: { DepGraph , DepNode , DepTask } ;
28
+ use rustc:: dep_graph:: DepNode ;
29
29
use rustc:: traits:: specialization_graph;
30
30
use rustc:: ty:: { self , Ty , TyCtxt } ;
31
31
use rustc:: ty:: util:: IntTypeExt ;
@@ -54,6 +54,8 @@ use rustc::hir::intravisit::Visitor;
54
54
use rustc:: hir:: intravisit;
55
55
use rustc:: hir:: map:: DefKey ;
56
56
57
+ use super :: index_builder:: { CrateIndex , XRef } ;
58
+
57
59
pub struct EncodeContext < ' a , ' tcx : ' a > {
58
60
pub diag : & ' a Handler ,
59
61
pub tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -71,35 +73,6 @@ impl<'a, 'tcx> EncodeContext<'a,'tcx> {
71
73
}
72
74
}
73
75
74
- /// "interned" entries referenced by id
75
- #[ derive( PartialEq , Eq , Hash ) ]
76
- pub enum XRef < ' tcx > { Predicate ( ty:: Predicate < ' tcx > ) }
77
-
78
- struct CrateIndex < ' a , ' tcx > {
79
- dep_graph : & ' a DepGraph ,
80
- items : IndexData ,
81
- xrefs : FnvHashMap < XRef < ' tcx > , u32 > , // sequentially-assigned
82
- }
83
-
84
- impl < ' a , ' tcx > CrateIndex < ' a , ' tcx > {
85
- /// Records that `id` is being emitted at the current offset.
86
- /// This data is later used to construct the item index in the
87
- /// metadata so we can quickly find the data for a given item.
88
- ///
89
- /// Returns a dep-graph task that you should keep live as long as
90
- /// the data for this item is being emitted.
91
- fn record ( & mut self , id : DefId , rbml_w : & mut Encoder ) -> DepTask < ' a > {
92
- let position = rbml_w. mark_stable_position ( ) ;
93
- self . items . record ( id, position) ;
94
- self . dep_graph . in_task ( DepNode :: MetaData ( id) )
95
- }
96
-
97
- fn add_xref ( & mut self , xref : XRef < ' tcx > ) -> u32 {
98
- let old_len = self . xrefs . len ( ) as u32 ;
99
- * self . xrefs . entry ( xref) . or_insert ( old_len)
100
- }
101
- }
102
-
103
76
fn encode_name ( rbml_w : & mut Encoder , name : Name ) {
104
77
rbml_w. wr_tagged_str ( tag_paths_data_name, & name. as_str ( ) ) ;
105
78
}
@@ -1380,11 +1353,7 @@ fn encode_info_for_items<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
1380
1353
-> CrateIndex < ' a , ' tcx > {
1381
1354
let krate = ecx. tcx . map . krate ( ) ;
1382
1355
1383
- let mut index = CrateIndex {
1384
- dep_graph : & ecx. tcx . dep_graph ,
1385
- items : IndexData :: new ( ecx. tcx . map . num_local_def_ids ( ) ) ,
1386
- xrefs : FnvHashMap ( )
1387
- } ;
1356
+ let mut index = CrateIndex :: new ( ecx) ;
1388
1357
rbml_w. start_tag ( tag_items_data) ;
1389
1358
1390
1359
{
@@ -1929,12 +1898,14 @@ fn encode_metadata_inner(rbml_w: &mut Encoder,
1929
1898
stats. item_bytes = rbml_w. writer . seek ( SeekFrom :: Current ( 0 ) ) . unwrap ( ) - i;
1930
1899
rbml_w. end_tag ( ) ;
1931
1900
1901
+ let ( items, xrefs) = index. into_fields ( ) ;
1902
+
1932
1903
i = rbml_w. writer . seek ( SeekFrom :: Current ( 0 ) ) . unwrap ( ) ;
1933
- encode_item_index ( rbml_w, index . items ) ;
1904
+ encode_item_index ( rbml_w, items) ;
1934
1905
stats. index_bytes = rbml_w. writer . seek ( SeekFrom :: Current ( 0 ) ) . unwrap ( ) - i;
1935
1906
1936
1907
i = rbml_w. writer . seek ( SeekFrom :: Current ( 0 ) ) . unwrap ( ) ;
1937
- encode_xrefs ( & ecx, rbml_w, index . xrefs ) ;
1908
+ encode_xrefs ( & ecx, rbml_w, xrefs) ;
1938
1909
stats. xref_bytes = rbml_w. writer . seek ( SeekFrom :: Current ( 0 ) ) . unwrap ( ) - i;
1939
1910
1940
1911
encode_struct_field_attrs ( & ecx, rbml_w, krate) ;
0 commit comments