@@ -25,6 +25,7 @@ use rustc_span::hygiene::{
2525use rustc_span:: source_map:: { SourceMap , StableSourceFileId } ;
2626use rustc_span:: CachingSourceMapView ;
2727use rustc_span:: { BytePos , ExpnData , ExpnHash , Pos , SourceFile , Span } ;
28+ use std:: io;
2829use std:: mem;
2930
3031const TAG_FILE_FOOTER : u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE ;
@@ -807,21 +808,10 @@ impl_ref_decoder! {<'tcx>
807808
808809//- ENCODING -------------------------------------------------------------------
809810
810- pub trait OpaqueEncoder : Encoder {
811- fn position ( & self ) -> usize ;
812- }
813-
814- impl OpaqueEncoder for FileEncoder {
815- #[ inline]
816- fn position ( & self ) -> usize {
817- FileEncoder :: position ( self )
818- }
819- }
820-
821811/// An encoder that can write to the incremental compilation cache.
822- pub struct CacheEncoder < ' a , ' tcx , E : OpaqueEncoder > {
812+ pub struct CacheEncoder < ' a , ' tcx > {
823813 tcx : TyCtxt < ' tcx > ,
824- encoder : E ,
814+ encoder : FileEncoder ,
825815 type_shorthands : FxHashMap < Ty < ' tcx > , usize > ,
826816 predicate_shorthands : FxHashMap < ty:: PredicateKind < ' tcx > , usize > ,
827817 interpret_allocs : FxIndexSet < interpret:: AllocId > ,
@@ -830,10 +820,7 @@ pub struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
830820 hygiene_context : & ' a HygieneEncodeContext ,
831821}
832822
833- impl < ' a , ' tcx , E > CacheEncoder < ' a , ' tcx , E >
834- where
835- E : OpaqueEncoder ,
836- {
823+ impl < ' a , ' tcx > CacheEncoder < ' a , ' tcx > {
837824 fn source_file_index ( & mut self , source_file : Lrc < SourceFile > ) -> SourceFileIndex {
838825 self . file_to_file_index [ & ( & * source_file as * const SourceFile ) ]
839826 }
@@ -852,32 +839,27 @@ where
852839 let end_pos = self . position ( ) ;
853840 ( ( end_pos - start_pos) as u64 ) . encode ( self ) ;
854841 }
842+
843+ fn finish ( self ) -> Result < usize , io:: Error > {
844+ self . encoder . finish ( )
845+ }
855846}
856847
857- impl < ' a , ' tcx , E > Encodable < CacheEncoder < ' a , ' tcx , E > > for SyntaxContext
858- where
859- E : OpaqueEncoder ,
860- {
861- fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx , E > ) {
848+ impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for SyntaxContext {
849+ fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx > ) {
862850 rustc_span:: hygiene:: raw_encode_syntax_context ( * self , s. hygiene_context , s) ;
863851 }
864852}
865853
866- impl < ' a , ' tcx , E > Encodable < CacheEncoder < ' a , ' tcx , E > > for ExpnId
867- where
868- E : OpaqueEncoder ,
869- {
870- fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx , E > ) {
854+ impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for ExpnId {
855+ fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx > ) {
871856 s. hygiene_context . schedule_expn_data_for_encoding ( * self ) ;
872857 self . expn_hash ( ) . encode ( s) ;
873858 }
874859}
875860
876- impl < ' a , ' tcx , E > Encodable < CacheEncoder < ' a , ' tcx , E > > for Span
877- where
878- E : OpaqueEncoder ,
879- {
880- fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx , E > ) {
861+ impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for Span {
862+ fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx > ) {
881863 let span_data = self . data_untracked ( ) ;
882864 span_data. ctxt . encode ( s) ;
883865 span_data. parent . encode ( s) ;
@@ -920,10 +902,7 @@ where
920902 }
921903}
922904
923- impl < ' a , ' tcx , E > TyEncoder for CacheEncoder < ' a , ' tcx , E >
924- where
925- E : OpaqueEncoder ,
926- {
905+ impl < ' a , ' tcx > TyEncoder for CacheEncoder < ' a , ' tcx > {
927906 type I = TyCtxt < ' tcx > ;
928907 const CLEAR_CROSS_CRATE : bool = false ;
929908
@@ -943,29 +922,20 @@ where
943922 }
944923}
945924
946- impl < ' a , ' tcx , E > Encodable < CacheEncoder < ' a , ' tcx , E > > for CrateNum
947- where
948- E : OpaqueEncoder ,
949- {
950- fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx , E > ) {
925+ impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for CrateNum {
926+ fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx > ) {
951927 s. tcx . stable_crate_id ( * self ) . encode ( s) ;
952928 }
953929}
954930
955- impl < ' a , ' tcx , E > Encodable < CacheEncoder < ' a , ' tcx , E > > for DefId
956- where
957- E : OpaqueEncoder ,
958- {
959- fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx , E > ) {
931+ impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for DefId {
932+ fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx > ) {
960933 s. tcx . def_path_hash ( * self ) . encode ( s) ;
961934 }
962935}
963936
964- impl < ' a , ' tcx , E > Encodable < CacheEncoder < ' a , ' tcx , E > > for DefIndex
965- where
966- E : OpaqueEncoder ,
967- {
968- fn encode ( & self , _: & mut CacheEncoder < ' a , ' tcx , E > ) {
937+ impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for DefIndex {
938+ fn encode ( & self , _: & mut CacheEncoder < ' a , ' tcx > ) {
969939 bug ! ( "encoding `DefIndex` without context" ) ;
970940 }
971941}
@@ -979,13 +949,7 @@ macro_rules! encoder_methods {
979949 }
980950}
981951
982- impl < ' a , ' tcx , E > Encoder for CacheEncoder < ' a , ' tcx , E >
983- where
984- E : OpaqueEncoder ,
985- {
986- type Ok = E :: Ok ;
987- type Err = E :: Err ;
988-
952+ impl < ' a , ' tcx > Encoder for CacheEncoder < ' a , ' tcx > {
989953 encoder_methods ! {
990954 emit_usize( usize ) ;
991955 emit_u128( u128 ) ;
@@ -1008,30 +972,26 @@ where
1008972 emit_str( & str ) ;
1009973 emit_raw_bytes( & [ u8 ] ) ;
1010974 }
1011-
1012- fn finish ( self ) -> Result < E :: Ok , E :: Err > {
1013- self . encoder . finish ( )
1014- }
1015975}
1016976
1017977// This ensures that the `Encodable<opaque::FileEncoder>::encode` specialization for byte slices
1018978// is used when a `CacheEncoder` having an `opaque::FileEncoder` is passed to `Encodable::encode`.
1019979// Unfortunately, we have to manually opt into specializations this way, given how `CacheEncoder`
1020980// and the encoding traits currently work.
1021- impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx , FileEncoder > > for [ u8 ] {
1022- fn encode ( & self , e : & mut CacheEncoder < ' a , ' tcx , FileEncoder > ) {
981+ impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for [ u8 ] {
982+ fn encode ( & self , e : & mut CacheEncoder < ' a , ' tcx > ) {
1023983 self . encode ( & mut e. encoder ) ;
1024984 }
1025985}
1026986
1027987pub fn encode_query_results < ' a , ' tcx , CTX , Q > (
1028988 tcx : CTX ,
1029- encoder : & mut CacheEncoder < ' a , ' tcx , FileEncoder > ,
989+ encoder : & mut CacheEncoder < ' a , ' tcx > ,
1030990 query_result_index : & mut EncodedDepNodeIndex ,
1031991) where
1032992 CTX : QueryContext + ' tcx ,
1033993 Q : super :: QueryDescription < CTX > ,
1034- Q :: Value : Encodable < CacheEncoder < ' a , ' tcx , FileEncoder > > ,
994+ Q :: Value : Encodable < CacheEncoder < ' a , ' tcx > > ,
1035995{
1036996 let _timer = tcx
1037997 . dep_context ( )
0 commit comments