11
11
use dep_graph:: { DepNodeIndex , SerializedDepNodeIndex } ;
12
12
use errors:: Diagnostic ;
13
13
use hir;
14
- use hir:: def_id:: { CrateNum , DefIndex , DefId , RESERVED_FOR_INCR_COMP_CACHE ,
15
- LOCAL_CRATE } ;
16
- use hir:: map:: definitions:: { Definitions , DefPathTable } ;
14
+ use hir:: def_id:: { CrateNum , DefIndex , DefId , LocalDefId ,
15
+ RESERVED_FOR_INCR_COMP_CACHE , LOCAL_CRATE } ;
16
+ use hir:: map:: definitions:: DefPathHash ;
17
17
use middle:: const_val:: ByteArray ;
18
18
use middle:: cstore:: CrateStore ;
19
19
use rustc_data_structures:: fx:: FxHashMap ;
@@ -37,7 +37,6 @@ use ty::subst::Substs;
37
37
// Some magic values used for verifying that encoding and decoding. These are
38
38
// basically random numbers.
39
39
const PREV_DIAGNOSTICS_TAG : u64 = 0x1234_5678_A1A1_A1A1 ;
40
- const DEF_PATH_TABLE_TAG : u64 = 0x1234_5678_B2B2_B2B2 ;
41
40
const QUERY_RESULT_INDEX_TAG : u64 = 0x1234_5678_C3C3_C3C3 ;
42
41
43
42
/// `OnDiskCache` provides an interface to incr. comp. data cached from the
@@ -56,10 +55,8 @@ pub struct OnDiskCache<'sess> {
56
55
// compilation session.
57
56
current_diagnostics : RefCell < FxHashMap < DepNodeIndex , Vec < Diagnostic > > > ,
58
57
59
-
60
58
prev_cnums : Vec < ( u32 , String , CrateDisambiguator ) > ,
61
59
cnum_map : RefCell < Option < IndexVec < CrateNum , Option < CrateNum > > > > ,
62
- prev_def_path_tables : Vec < DefPathTable > ,
63
60
64
61
prev_filemap_starts : BTreeMap < BytePos , StableFilemapId > ,
65
62
codemap : & ' sess CodeMap ,
@@ -92,14 +89,13 @@ impl<'sess> OnDiskCache<'sess> {
92
89
( header, decoder. position ( ) )
93
90
} ;
94
91
95
- let ( prev_diagnostics, prev_def_path_tables , query_result_index) = {
92
+ let ( prev_diagnostics, query_result_index) = {
96
93
let mut decoder = CacheDecoder {
97
94
tcx : None ,
98
95
opaque : opaque:: Decoder :: new ( & data[ ..] , post_header_pos) ,
99
96
codemap : sess. codemap ( ) ,
100
97
prev_filemap_starts : & header. prev_filemap_starts ,
101
98
cnum_map : & IndexVec :: new ( ) ,
102
- prev_def_path_tables : & Vec :: new ( ) ,
103
99
} ;
104
100
105
101
// Decode Diagnostics
@@ -111,11 +107,6 @@ impl<'sess> OnDiskCache<'sess> {
111
107
diagnostics. into_iter ( ) . collect ( )
112
108
} ;
113
109
114
- // Decode DefPathTables
115
- let prev_def_path_tables: Vec < DefPathTable > =
116
- decode_tagged ( & mut decoder, DEF_PATH_TABLE_TAG )
117
- . expect ( "Error while trying to decode cached DefPathTables." ) ;
118
-
119
110
// Decode the *position* of the query result index
120
111
let query_result_index_pos = {
121
112
let pos_pos = data. len ( ) - IntEncodedWithFixedSize :: ENCODED_SIZE ;
@@ -131,7 +122,7 @@ impl<'sess> OnDiskCache<'sess> {
131
122
decode_tagged ( decoder, QUERY_RESULT_INDEX_TAG )
132
123
} ) . expect ( "Error while trying to decode query result index." ) ;
133
124
134
- ( prev_diagnostics, prev_def_path_tables , query_result_index)
125
+ ( prev_diagnostics, query_result_index)
135
126
} ;
136
127
137
128
OnDiskCache {
@@ -140,7 +131,6 @@ impl<'sess> OnDiskCache<'sess> {
140
131
prev_filemap_starts : header. prev_filemap_starts ,
141
132
prev_cnums : header. prev_cnums ,
142
133
cnum_map : RefCell :: new ( None ) ,
143
- prev_def_path_tables,
144
134
codemap : sess. codemap ( ) ,
145
135
current_diagnostics : RefCell :: new ( FxHashMap ( ) ) ,
146
136
query_result_index : query_result_index. into_iter ( ) . collect ( ) ,
@@ -154,7 +144,6 @@ impl<'sess> OnDiskCache<'sess> {
154
144
prev_filemap_starts : BTreeMap :: new ( ) ,
155
145
prev_cnums : vec ! [ ] ,
156
146
cnum_map : RefCell :: new ( None ) ,
157
- prev_def_path_tables : Vec :: new ( ) ,
158
147
codemap,
159
148
current_diagnostics : RefCell :: new ( FxHashMap ( ) ) ,
160
149
query_result_index : FxHashMap ( ) ,
@@ -172,10 +161,10 @@ impl<'sess> OnDiskCache<'sess> {
172
161
let _in_ignore = tcx. dep_graph . in_ignore ( ) ;
173
162
174
163
let mut encoder = CacheEncoder {
164
+ tcx,
175
165
encoder,
176
166
type_shorthands : FxHashMap ( ) ,
177
167
predicate_shorthands : FxHashMap ( ) ,
178
- definitions : tcx. hir . definitions ( ) ,
179
168
} ;
180
169
181
170
@@ -212,22 +201,6 @@ impl<'sess> OnDiskCache<'sess> {
212
201
encoder. encode_tagged ( PREV_DIAGNOSTICS_TAG , & diagnostics) ?;
213
202
214
203
215
- // Encode all DefPathTables
216
- let upstream_def_path_tables = tcx. all_crate_nums ( LOCAL_CRATE )
217
- . iter ( )
218
- . map ( |& cnum| ( cnum, cstore. def_path_table ( cnum) ) )
219
- . collect :: < FxHashMap < _ , _ > > ( ) ;
220
- let def_path_tables: Vec < & DefPathTable > = sorted_cnums. into_iter ( ) . map ( |cnum| {
221
- if cnum == LOCAL_CRATE {
222
- tcx. hir . definitions ( ) . def_path_table ( )
223
- } else {
224
- & * upstream_def_path_tables[ & cnum]
225
- }
226
- } ) . collect ( ) ;
227
-
228
- encoder. encode_tagged ( DEF_PATH_TABLE_TAG , & def_path_tables) ?;
229
-
230
-
231
204
// Encode query results
232
205
let mut query_result_index = EncodedQueryResultIndex :: new ( ) ;
233
206
@@ -297,7 +270,6 @@ impl<'sess> OnDiskCache<'sess> {
297
270
codemap : self . codemap ,
298
271
prev_filemap_starts : & self . prev_filemap_starts ,
299
272
cnum_map : cnum_map. as_ref ( ) . unwrap ( ) ,
300
- prev_def_path_tables : & self . prev_def_path_tables ,
301
273
} ;
302
274
303
275
match decode_tagged ( & mut decoder, dep_node_index) {
@@ -373,7 +345,6 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
373
345
codemap : & ' x CodeMap ,
374
346
prev_filemap_starts : & ' x BTreeMap < BytePos , StableFilemapId > ,
375
347
cnum_map : & ' x IndexVec < CrateNum , Option < CrateNum > > ,
376
- prev_def_path_tables : & ' x Vec < DefPathTable > ,
377
348
}
378
349
379
350
impl < ' a , ' tcx , ' x > CacheDecoder < ' a , ' tcx , ' x > {
@@ -548,32 +519,24 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<DefIndex> for CacheDecoder<'a, 'tcx, 'x> {
548
519
// sessions, to map the old DefId to the new one.
549
520
impl < ' a , ' tcx , ' x > SpecializedDecoder < DefId > for CacheDecoder < ' a , ' tcx , ' x > {
550
521
fn specialized_decode ( & mut self ) -> Result < DefId , Self :: Error > {
551
- // Decode the unmapped CrateNum
552
- let prev_cnum = CrateNum :: default_decode ( self ) ?;
553
-
554
- // Decode the unmapped DefIndex
555
- let def_index = DefIndex :: default_decode ( self ) ?;
556
-
557
- // Unmapped CrateNum and DefIndex are valid keys for the *cached*
558
- // DefPathTables, so we use them to look up the DefPathHash.
559
- let def_path_hash = self . prev_def_path_tables [ prev_cnum. index ( ) ]
560
- . def_path_hash ( def_index) ;
522
+ // Load the DefPathHash which is was we encoded the DefId as.
523
+ let def_path_hash = DefPathHash :: decode ( self ) ?;
561
524
562
525
// Using the DefPathHash, we can lookup the new DefId
563
526
Ok ( self . tcx ( ) . def_path_hash_to_def_id . as_ref ( ) . unwrap ( ) [ & def_path_hash] )
564
527
}
565
528
}
566
529
530
+ impl < ' a , ' tcx , ' x > SpecializedDecoder < LocalDefId > for CacheDecoder < ' a , ' tcx , ' x > {
531
+ fn specialized_decode ( & mut self ) -> Result < LocalDefId , Self :: Error > {
532
+ Ok ( LocalDefId :: from_def_id ( DefId :: decode ( self ) ?) )
533
+ }
534
+ }
535
+
567
536
impl < ' a , ' tcx , ' x > SpecializedDecoder < hir:: HirId > for CacheDecoder < ' a , ' tcx , ' x > {
568
537
fn specialized_decode ( & mut self ) -> Result < hir:: HirId , Self :: Error > {
569
- // Decode the unmapped DefIndex of the HirId.
570
- let def_index = DefIndex :: default_decode ( self ) ?;
571
-
572
- // Use the unmapped DefIndex to look up the DefPathHash in the cached
573
- // DefPathTable. For HirIds we know that we always have to look in the
574
- // *local* DefPathTable.
575
- let def_path_hash = self . prev_def_path_tables [ LOCAL_CRATE . index ( ) ]
576
- . def_path_hash ( def_index) ;
538
+ // Load the DefPathHash which is was we encoded the DefIndex as.
539
+ let def_path_hash = DefPathHash :: decode ( self ) ?;
577
540
578
541
// Use the DefPathHash to map to the current DefId.
579
542
let def_id = self . tcx ( )
@@ -666,16 +629,17 @@ for CacheDecoder<'a, 'tcx, 'x> {
666
629
667
630
//- ENCODING -------------------------------------------------------------------
668
631
669
- struct CacheEncoder < ' enc , ' tcx , E >
670
- where E : ' enc + ty_codec:: TyEncoder
632
+ struct CacheEncoder < ' enc , ' a , ' tcx , E >
633
+ where E : ' enc + ty_codec:: TyEncoder ,
634
+ ' tcx : ' a ,
671
635
{
636
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
672
637
encoder : & ' enc mut E ,
673
638
type_shorthands : FxHashMap < ty:: Ty < ' tcx > , usize > ,
674
639
predicate_shorthands : FxHashMap < ty:: Predicate < ' tcx > , usize > ,
675
- definitions : & ' enc Definitions ,
676
640
}
677
641
678
- impl < ' enc , ' tcx , E > CacheEncoder < ' enc , ' tcx , E >
642
+ impl < ' enc , ' a , ' tcx , E > CacheEncoder < ' enc , ' a , ' tcx , E >
679
643
where E : ' enc + ty_codec:: TyEncoder
680
644
{
681
645
/// Encode something with additional information that allows to do some
@@ -699,15 +663,15 @@ impl<'enc, 'tcx, E> CacheEncoder<'enc, 'tcx, E>
699
663
}
700
664
}
701
665
702
- impl < ' enc , ' tcx , E > ty_codec:: TyEncoder for CacheEncoder < ' enc , ' tcx , E >
666
+ impl < ' enc , ' a , ' tcx , E > ty_codec:: TyEncoder for CacheEncoder < ' enc , ' a , ' tcx , E >
703
667
where E : ' enc + ty_codec:: TyEncoder
704
668
{
705
669
fn position ( & self ) -> usize {
706
670
self . encoder . position ( )
707
671
}
708
672
}
709
673
710
- impl < ' enc , ' tcx , E > SpecializedEncoder < ty:: Ty < ' tcx > > for CacheEncoder < ' enc , ' tcx , E >
674
+ impl < ' enc , ' a , ' tcx , E > SpecializedEncoder < ty:: Ty < ' tcx > > for CacheEncoder < ' enc , ' a , ' tcx , E >
711
675
where E : ' enc + ty_codec:: TyEncoder
712
676
{
713
677
fn specialized_encode ( & mut self , ty : & ty:: Ty < ' tcx > ) -> Result < ( ) , Self :: Error > {
@@ -716,8 +680,8 @@ impl<'enc, 'tcx, E> SpecializedEncoder<ty::Ty<'tcx>> for CacheEncoder<'enc, 'tcx
716
680
}
717
681
}
718
682
719
- impl < ' enc , ' tcx , E > SpecializedEncoder < ty:: GenericPredicates < ' tcx > >
720
- for CacheEncoder < ' enc , ' tcx , E >
683
+ impl < ' enc , ' a , ' tcx , E > SpecializedEncoder < ty:: GenericPredicates < ' tcx > >
684
+ for CacheEncoder < ' enc , ' a , ' tcx , E >
721
685
where E : ' enc + ty_codec:: TyEncoder
722
686
{
723
687
fn specialized_encode ( & mut self ,
@@ -728,7 +692,7 @@ impl<'enc, 'tcx, E> SpecializedEncoder<ty::GenericPredicates<'tcx>>
728
692
}
729
693
}
730
694
731
- impl < ' enc , ' tcx , E > SpecializedEncoder < hir:: HirId > for CacheEncoder < ' enc , ' tcx , E >
695
+ impl < ' enc , ' a , ' tcx , E > SpecializedEncoder < hir:: HirId > for CacheEncoder < ' enc , ' a , ' tcx , E >
732
696
where E : ' enc + ty_codec:: TyEncoder
733
697
{
734
698
fn specialized_encode ( & mut self , id : & hir:: HirId ) -> Result < ( ) , Self :: Error > {
@@ -737,18 +701,46 @@ impl<'enc, 'tcx, E> SpecializedEncoder<hir::HirId> for CacheEncoder<'enc, 'tcx,
737
701
local_id,
738
702
} = * id;
739
703
740
- owner. encode ( self ) ?;
704
+ let def_path_hash = self . tcx . hir . definitions ( ) . def_path_hash ( owner) ;
705
+
706
+ def_path_hash. encode ( self ) ?;
741
707
local_id. encode ( self )
742
708
}
743
709
}
744
710
711
+
712
+ impl < ' enc , ' a , ' tcx , E > SpecializedEncoder < DefId > for CacheEncoder < ' enc , ' a , ' tcx , E >
713
+ where E : ' enc + ty_codec:: TyEncoder
714
+ {
715
+ fn specialized_encode ( & mut self , id : & DefId ) -> Result < ( ) , Self :: Error > {
716
+ let def_path_hash = self . tcx . def_path_hash ( * id) ;
717
+ def_path_hash. encode ( self )
718
+ }
719
+ }
720
+
721
+ impl < ' enc , ' a , ' tcx , E > SpecializedEncoder < LocalDefId > for CacheEncoder < ' enc , ' a , ' tcx , E >
722
+ where E : ' enc + ty_codec:: TyEncoder
723
+ {
724
+ fn specialized_encode ( & mut self , id : & LocalDefId ) -> Result < ( ) , Self :: Error > {
725
+ id. to_def_id ( ) . encode ( self )
726
+ }
727
+ }
728
+
729
+ impl < ' enc , ' a , ' tcx , E > SpecializedEncoder < DefIndex > for CacheEncoder < ' enc , ' a , ' tcx , E >
730
+ where E : ' enc + ty_codec:: TyEncoder
731
+ {
732
+ fn specialized_encode ( & mut self , _: & DefIndex ) -> Result < ( ) , Self :: Error > {
733
+ bug ! ( "Encoding DefIndex without context." )
734
+ }
735
+ }
736
+
745
737
// NodeIds are not stable across compilation sessions, so we store them in their
746
738
// HirId representation. This allows use to map them to the current NodeId.
747
- impl < ' enc , ' tcx , E > SpecializedEncoder < NodeId > for CacheEncoder < ' enc , ' tcx , E >
739
+ impl < ' enc , ' a , ' tcx , E > SpecializedEncoder < NodeId > for CacheEncoder < ' enc , ' a , ' tcx , E >
748
740
where E : ' enc + ty_codec:: TyEncoder
749
741
{
750
742
fn specialized_encode ( & mut self , node_id : & NodeId ) -> Result < ( ) , Self :: Error > {
751
- let hir_id = self . definitions . node_to_hir_id ( * node_id) ;
743
+ let hir_id = self . tcx . hir . node_to_hir_id ( * node_id) ;
752
744
hir_id. encode ( self )
753
745
}
754
746
}
@@ -761,7 +753,7 @@ macro_rules! encoder_methods {
761
753
}
762
754
}
763
755
764
- impl < ' enc , ' tcx , E > Encoder for CacheEncoder < ' enc , ' tcx , E >
756
+ impl < ' enc , ' a , ' tcx , E > Encoder for CacheEncoder < ' enc , ' a , ' tcx , E >
765
757
where E : ' enc + ty_codec:: TyEncoder
766
758
{
767
759
type Error = E :: Error ;
@@ -803,8 +795,8 @@ impl IntEncodedWithFixedSize {
803
795
impl UseSpecializedEncodable for IntEncodedWithFixedSize { }
804
796
impl UseSpecializedDecodable for IntEncodedWithFixedSize { }
805
797
806
- impl < ' enc , ' tcx , E > SpecializedEncoder < IntEncodedWithFixedSize >
807
- for CacheEncoder < ' enc , ' tcx , E >
798
+ impl < ' enc , ' a , ' tcx , E > SpecializedEncoder < IntEncodedWithFixedSize >
799
+ for CacheEncoder < ' enc , ' a , ' tcx , E >
808
800
where E : ' enc + ty_codec:: TyEncoder
809
801
{
810
802
fn specialized_encode ( & mut self , x : & IntEncodedWithFixedSize ) -> Result < ( ) , Self :: Error > {
@@ -836,12 +828,12 @@ for CacheDecoder<'a, 'tcx, 'x> {
836
828
}
837
829
}
838
830
839
- fn encode_query_results < ' x , ' a , ' tcx , Q , E > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
840
- encoder : & mut CacheEncoder < ' x , ' tcx , E > ,
841
- query_result_index : & mut EncodedQueryResultIndex )
842
- -> Result < ( ) , E :: Error >
831
+ fn encode_query_results < ' enc , ' a , ' tcx , Q , E > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
832
+ encoder : & mut CacheEncoder < ' enc , ' a , ' tcx , E > ,
833
+ query_result_index : & mut EncodedQueryResultIndex )
834
+ -> Result < ( ) , E :: Error >
843
835
where Q : super :: plumbing:: GetCacheInternal < ' tcx > ,
844
- E : ' x + TyEncoder ,
836
+ E : ' enc + TyEncoder ,
845
837
Q :: Value : Encodable ,
846
838
{
847
839
for ( key, entry) in Q :: get_cache_internal ( tcx) . map . iter ( ) {
0 commit comments