@@ -32,7 +32,6 @@ use syntax_pos::{BytePos, Span, NO_EXPANSION, DUMMY_SP};
3232use ty;
3333use ty:: codec:: { self as ty_codec, TyDecoder , TyEncoder } ;
3434use ty:: context:: TyCtxt ;
35- use ty:: maps:: config:: QueryDescription ;
3635use ty:: subst:: Substs ;
3736
3837// Some magic values used for verifying that encoding and decoding. These are
@@ -162,11 +161,11 @@ impl<'sess> OnDiskCache<'sess> {
162161 }
163162 }
164163
165- pub fn serialize < ' a , ' gcx , ' lcx , E > ( & self ,
166- tcx : TyCtxt < ' a , ' gcx , ' lcx > ,
167- cstore : & CrateStore ,
168- encoder : & mut E )
169- -> Result < ( ) , E :: Error >
164+ pub fn serialize < ' a , ' tcx , E > ( & self ,
165+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
166+ cstore : & CrateStore ,
167+ encoder : & mut E )
168+ -> Result < ( ) , E :: Error >
170169 where E : ty_codec:: TyEncoder
171170 {
172171 // Serializing the DepGraph should not modify it:
@@ -232,19 +231,13 @@ impl<'sess> OnDiskCache<'sess> {
232231 // Encode query results
233232 let mut query_result_index = EncodedQueryResultIndex :: new ( ) ;
234233
235- // Encode TypeckTables
236- for ( def_id , entry ) in tcx . maps . typeck_tables_of . borrow ( ) . map . iter ( ) {
237- if ty :: maps :: queries :: typeck_tables_of :: cache_on_disk ( * def_id ) {
238- let dep_node = SerializedDepNodeIndex :: new ( entry . index . index ( ) ) ;
234+ {
235+ use ty :: maps :: queries :: * ;
236+ let enc = & mut encoder ;
237+ let qri = & mut query_result_index ;
239238
240- // Record position of the cache entry
241- query_result_index. push ( ( dep_node, encoder. position ( ) ) ) ;
242-
243- // Encode the type check tables with the SerializedDepNodeIndex
244- // as tag.
245- let typeck_tables: & ty:: TypeckTables < ' gcx > = & entry. value ;
246- encoder. encode_tagged ( dep_node, typeck_tables) ?;
247- }
239+ // Encode TypeckTables
240+ encode_query_results :: < typeck_tables_of , _ > ( tcx, enc, qri) ?;
248241 }
249242
250243 // Encode query result index
@@ -842,3 +835,27 @@ for CacheDecoder<'a, 'tcx, 'x> {
842835 Ok ( IntEncodedWithFixedSize ( value) )
843836 }
844837}
838+
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 >
843+ where Q : super :: plumbing:: GetCacheInternal < ' tcx > ,
844+ E : ' x + TyEncoder ,
845+ Q :: Value : Encodable ,
846+ {
847+ for ( key, entry) in Q :: get_cache_internal ( tcx) . map . iter ( ) {
848+ if Q :: cache_on_disk ( key. clone ( ) ) {
849+ let dep_node = SerializedDepNodeIndex :: new ( entry. index . index ( ) ) ;
850+
851+ // Record position of the cache entry
852+ query_result_index. push ( ( dep_node, encoder. position ( ) ) ) ;
853+
854+ // Encode the type check tables with the SerializedDepNodeIndex
855+ // as tag.
856+ encoder. encode_tagged ( dep_node, & entry. value ) ?;
857+ }
858+ }
859+
860+ Ok ( ( ) )
861+ }
0 commit comments