@@ -15,6 +15,7 @@ use hir::def_id::{CrateNum, DefIndex, DefId, LocalDefId,
1515 RESERVED_FOR_INCR_COMP_CACHE , LOCAL_CRATE } ;
1616use hir:: map:: definitions:: DefPathHash ;
1717use middle:: cstore:: CrateStore ;
18+ use mir;
1819use rustc_data_structures:: fx:: FxHashMap ;
1920use rustc_data_structures:: indexed_vec:: { IndexVec , Idx } ;
2021use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder , opaque,
@@ -36,6 +37,9 @@ use ty::context::TyCtxt;
3637const PREV_DIAGNOSTICS_TAG : u64 = 0x1234_5678_A1A1_A1A1 ;
3738const QUERY_RESULT_INDEX_TAG : u64 = 0x1234_5678_C3C3_C3C3 ;
3839
40+ const TAG_CLEAR_CROSS_CRATE_CLEAR : u8 = 0 ;
41+ const TAG_CLEAR_CROSS_CRATE_SET : u8 = 1 ;
42+
3943/// `OnDiskCache` provides an interface to incr. comp. data cached from the
4044/// previous compilation session. This data will eventually include the results
4145/// of a few selected queries (like `typeck_tables_of` and `mir_optimized`) and
@@ -518,12 +522,32 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<hir::HirId> for CacheDecoder<'a, 'tcx, 'x>
518522// NodeIds are not stable across compilation sessions, so we store them in their
519523// HirId representation. This allows use to map them to the current NodeId.
520524impl < ' a , ' tcx , ' x > SpecializedDecoder < NodeId > for CacheDecoder < ' a , ' tcx , ' x > {
525+ #[ inline]
521526 fn specialized_decode ( & mut self ) -> Result < NodeId , Self :: Error > {
522527 let hir_id = hir:: HirId :: decode ( self ) ?;
523528 Ok ( self . tcx ( ) . hir . hir_to_node_id ( hir_id) )
524529 }
525530}
526531
532+ impl < ' a , ' tcx , ' x , T : Decodable > SpecializedDecoder < mir:: ClearCrossCrate < T > >
533+ for CacheDecoder < ' a , ' tcx , ' x > {
534+ #[ inline]
535+ fn specialized_decode ( & mut self ) -> Result < mir:: ClearCrossCrate < T > , Self :: Error > {
536+ let discr = u8:: decode ( self ) ?;
537+
538+ match discr {
539+ TAG_CLEAR_CROSS_CRATE_CLEAR => Ok ( mir:: ClearCrossCrate :: Clear ) ,
540+ TAG_CLEAR_CROSS_CRATE_SET => {
541+ let val = T :: decode ( self ) ?;
542+ Ok ( mir:: ClearCrossCrate :: Set ( val) )
543+ }
544+ _ => {
545+ unreachable ! ( )
546+ }
547+ }
548+ }
549+ }
550+
527551//- ENCODING -------------------------------------------------------------------
528552
529553struct CacheEncoder < ' enc , ' a , ' tcx , E >
@@ -658,6 +682,27 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<NodeId> for CacheEncoder<'enc, 'a, 't
658682 }
659683}
660684
685+ impl < ' enc , ' a , ' tcx , E , T > SpecializedEncoder < mir:: ClearCrossCrate < T > >
686+ for CacheEncoder < ' enc , ' a , ' tcx , E >
687+ where E : ' enc + ty_codec:: TyEncoder ,
688+ T : Encodable ,
689+ {
690+ #[ inline]
691+ fn specialized_encode ( & mut self ,
692+ val : & mir:: ClearCrossCrate < T > )
693+ -> Result < ( ) , Self :: Error > {
694+ match * val {
695+ mir:: ClearCrossCrate :: Clear => {
696+ TAG_CLEAR_CROSS_CRATE_CLEAR . encode ( self )
697+ }
698+ mir:: ClearCrossCrate :: Set ( ref val) => {
699+ TAG_CLEAR_CROSS_CRATE_SET . encode ( self ) ?;
700+ val. encode ( self )
701+ }
702+ }
703+ }
704+ }
705+
661706macro_rules! encoder_methods {
662707 ( $( $name: ident( $ty: ty) ; ) * ) => {
663708 $( fn $name( & mut self , value: $ty) -> Result <( ) , Self :: Error > {
0 commit comments