@@ -25,6 +25,7 @@ use rustc_span::hygiene::{
25
25
use rustc_span:: source_map:: { SourceMap , StableSourceFileId } ;
26
26
use rustc_span:: CachingSourceMapView ;
27
27
use rustc_span:: { BytePos , ExpnData , ExpnHash , Pos , SourceFile , Span } ;
28
+ use std:: io;
28
29
use std:: mem;
29
30
30
31
const TAG_FILE_FOOTER : u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE ;
@@ -807,21 +808,10 @@ impl_ref_decoder! {<'tcx>
807
808
808
809
//- ENCODING -------------------------------------------------------------------
809
810
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
-
821
811
/// An encoder that can write to the incremental compilation cache.
822
- pub struct CacheEncoder < ' a , ' tcx , E : OpaqueEncoder > {
812
+ pub struct CacheEncoder < ' a , ' tcx > {
823
813
tcx : TyCtxt < ' tcx > ,
824
- encoder : E ,
814
+ encoder : FileEncoder ,
825
815
type_shorthands : FxHashMap < Ty < ' tcx > , usize > ,
826
816
predicate_shorthands : FxHashMap < ty:: PredicateKind < ' tcx > , usize > ,
827
817
interpret_allocs : FxIndexSet < interpret:: AllocId > ,
@@ -830,10 +820,7 @@ pub struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
830
820
hygiene_context : & ' a HygieneEncodeContext ,
831
821
}
832
822
833
- impl < ' a , ' tcx , E > CacheEncoder < ' a , ' tcx , E >
834
- where
835
- E : OpaqueEncoder ,
836
- {
823
+ impl < ' a , ' tcx > CacheEncoder < ' a , ' tcx > {
837
824
fn source_file_index ( & mut self , source_file : Lrc < SourceFile > ) -> SourceFileIndex {
838
825
self . file_to_file_index [ & ( & * source_file as * const SourceFile ) ]
839
826
}
@@ -852,32 +839,27 @@ where
852
839
let end_pos = self . position ( ) ;
853
840
( ( end_pos - start_pos) as u64 ) . encode ( self ) ;
854
841
}
842
+
843
+ fn finish ( self ) -> Result < usize , io:: Error > {
844
+ self . encoder . finish ( )
845
+ }
855
846
}
856
847
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 > ) {
862
850
rustc_span:: hygiene:: raw_encode_syntax_context ( * self , s. hygiene_context , s) ;
863
851
}
864
852
}
865
853
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 > ) {
871
856
s. hygiene_context . schedule_expn_data_for_encoding ( * self ) ;
872
857
self . expn_hash ( ) . encode ( s) ;
873
858
}
874
859
}
875
860
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 > ) {
881
863
let span_data = self . data_untracked ( ) ;
882
864
span_data. ctxt . encode ( s) ;
883
865
span_data. parent . encode ( s) ;
@@ -920,10 +902,7 @@ where
920
902
}
921
903
}
922
904
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 > {
927
906
type I = TyCtxt < ' tcx > ;
928
907
const CLEAR_CROSS_CRATE : bool = false ;
929
908
@@ -943,29 +922,20 @@ where
943
922
}
944
923
}
945
924
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 > ) {
951
927
s. tcx . stable_crate_id ( * self ) . encode ( s) ;
952
928
}
953
929
}
954
930
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 > ) {
960
933
s. tcx . def_path_hash ( * self ) . encode ( s) ;
961
934
}
962
935
}
963
936
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 > ) {
969
939
bug ! ( "encoding `DefIndex` without context" ) ;
970
940
}
971
941
}
@@ -979,13 +949,7 @@ macro_rules! encoder_methods {
979
949
}
980
950
}
981
951
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 > {
989
953
encoder_methods ! {
990
954
emit_usize( usize ) ;
991
955
emit_u128( u128 ) ;
@@ -1008,30 +972,26 @@ where
1008
972
emit_str( & str ) ;
1009
973
emit_raw_bytes( & [ u8 ] ) ;
1010
974
}
1011
-
1012
- fn finish ( self ) -> Result < E :: Ok , E :: Err > {
1013
- self . encoder . finish ( )
1014
- }
1015
975
}
1016
976
1017
977
// This ensures that the `Encodable<opaque::FileEncoder>::encode` specialization for byte slices
1018
978
// is used when a `CacheEncoder` having an `opaque::FileEncoder` is passed to `Encodable::encode`.
1019
979
// Unfortunately, we have to manually opt into specializations this way, given how `CacheEncoder`
1020
980
// 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 > ) {
1023
983
self . encode ( & mut e. encoder ) ;
1024
984
}
1025
985
}
1026
986
1027
987
pub fn encode_query_results < ' a , ' tcx , CTX , Q > (
1028
988
tcx : CTX ,
1029
- encoder : & mut CacheEncoder < ' a , ' tcx , FileEncoder > ,
989
+ encoder : & mut CacheEncoder < ' a , ' tcx > ,
1030
990
query_result_index : & mut EncodedDepNodeIndex ,
1031
991
) where
1032
992
CTX : QueryContext + ' tcx ,
1033
993
Q : super :: QueryDescription < CTX > ,
1034
- Q :: Value : Encodable < CacheEncoder < ' a , ' tcx , FileEncoder > > ,
994
+ Q :: Value : Encodable < CacheEncoder < ' a , ' tcx > > ,
1035
995
{
1036
996
let _timer = tcx
1037
997
. dep_context ( )
0 commit comments