@@ -836,6 +836,76 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
836836 }
837837}
838838
839+ fn should_encode_variances ( def_kind : DefKind ) -> bool {
840+ match def_kind {
841+ DefKind :: Struct
842+ | DefKind :: Union
843+ | DefKind :: Enum
844+ | DefKind :: Variant
845+ | DefKind :: Fn
846+ | DefKind :: Ctor ( ..)
847+ | DefKind :: AssocFn => true ,
848+ DefKind :: Mod
849+ | DefKind :: Field
850+ | DefKind :: AssocTy
851+ | DefKind :: AssocConst
852+ | DefKind :: TyParam
853+ | DefKind :: ConstParam
854+ | DefKind :: Static
855+ | DefKind :: Const
856+ | DefKind :: ForeignMod
857+ | DefKind :: TyAlias
858+ | DefKind :: OpaqueTy
859+ | DefKind :: Impl
860+ | DefKind :: Trait
861+ | DefKind :: TraitAlias
862+ | DefKind :: Macro ( ..)
863+ | DefKind :: ForeignTy
864+ | DefKind :: Use
865+ | DefKind :: LifetimeParam
866+ | DefKind :: AnonConst
867+ | DefKind :: GlobalAsm
868+ | DefKind :: Closure
869+ | DefKind :: Generator
870+ | DefKind :: ExternCrate => false ,
871+ }
872+ }
873+
874+ fn should_encode_generics ( def_kind : DefKind ) -> bool {
875+ match def_kind {
876+ DefKind :: Struct
877+ | DefKind :: Union
878+ | DefKind :: Enum
879+ | DefKind :: Variant
880+ | DefKind :: Trait
881+ | DefKind :: TyAlias
882+ | DefKind :: ForeignTy
883+ | DefKind :: TraitAlias
884+ | DefKind :: AssocTy
885+ | DefKind :: Fn
886+ | DefKind :: Const
887+ | DefKind :: Static
888+ | DefKind :: Ctor ( ..)
889+ | DefKind :: AssocFn
890+ | DefKind :: AssocConst
891+ | DefKind :: AnonConst
892+ | DefKind :: OpaqueTy
893+ | DefKind :: Impl
894+ | DefKind :: Closure
895+ | DefKind :: Generator => true ,
896+ DefKind :: Mod
897+ | DefKind :: Field
898+ | DefKind :: ForeignMod
899+ | DefKind :: TyParam
900+ | DefKind :: ConstParam
901+ | DefKind :: Macro ( ..)
902+ | DefKind :: Use
903+ | DefKind :: LifetimeParam
904+ | DefKind :: GlobalAsm
905+ | DefKind :: ExternCrate => false ,
906+ }
907+ }
908+
839909impl EncodeContext < ' a , ' tcx > {
840910 fn encode_def_ids ( & mut self ) {
841911 if self . is_proc_macro {
@@ -864,6 +934,22 @@ impl EncodeContext<'a, 'tcx> {
864934 self . encode_const_stability ( def_id) ;
865935 self . encode_deprecation ( def_id) ;
866936 }
937+ if should_encode_variances ( def_kind) {
938+ let v = self . tcx . variances_of ( def_id) ;
939+ record ! ( self . tables. variances[ def_id] <- v) ;
940+ }
941+ if should_encode_generics ( def_kind) {
942+ let g = tcx. generics_of ( def_id) ;
943+ record ! ( self . tables. generics[ def_id] <- g) ;
944+ record ! ( self . tables. explicit_predicates[ def_id] <- self . tcx. explicit_predicates_of( def_id) ) ;
945+ let inferred_outlives = self . tcx . inferred_outlives_of ( def_id) ;
946+ if !inferred_outlives. is_empty ( ) {
947+ record ! ( self . tables. inferred_outlives[ def_id] <- inferred_outlives) ;
948+ }
949+ }
950+ if let DefKind :: Trait | DefKind :: TraitAlias = def_kind {
951+ record ! ( self . tables. super_predicates[ def_id] <- self . tcx. super_predicates_of( def_id) ) ;
952+ }
867953 }
868954 let inherent_impls = tcx. crate_inherent_impls ( LOCAL_CRATE ) ;
869955 for ( def_id, implementations) in inherent_impls. inherent_impls . iter ( ) {
@@ -878,11 +964,6 @@ impl EncodeContext<'a, 'tcx> {
878964 }
879965 }
880966
881- fn encode_variances_of ( & mut self , def_id : DefId ) {
882- debug ! ( "EncodeContext::encode_variances_of({:?})" , def_id) ;
883- record ! ( self . tables. variances[ def_id] <- self . tcx. variances_of( def_id) ) ;
884- }
885-
886967 fn encode_item_type ( & mut self , def_id : DefId ) {
887968 debug ! ( "EncodeContext::encode_item_type({:?})" , def_id) ;
888969 record ! ( self . tables. ty[ def_id] <- self . tcx. type_of( def_id) ) ;
@@ -913,12 +994,7 @@ impl EncodeContext<'a, 'tcx> {
913994 if let Some ( ctor_def_id) = variant. ctor_def_id {
914995 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( ctor_def_id) ) ;
915996 }
916- // FIXME(eddyb) is this ever used?
917- self . encode_variances_of ( def_id) ;
918997 }
919- self . encode_generics ( def_id) ;
920- self . encode_explicit_predicates ( def_id) ;
921- self . encode_inferred_outlives ( def_id) ;
922998 }
923999
9241000 fn encode_enum_variant_ctor ( & mut self , def : & ty:: AdtDef , index : VariantIdx ) {
@@ -939,11 +1015,7 @@ impl EncodeContext<'a, 'tcx> {
9391015 self . encode_item_type ( def_id) ;
9401016 if variant. ctor_kind == CtorKind :: Fn {
9411017 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
942- self . encode_variances_of ( def_id) ;
9431018 }
944- self . encode_generics ( def_id) ;
945- self . encode_explicit_predicates ( def_id) ;
946- self . encode_inferred_outlives ( def_id) ;
9471019 }
9481020
9491021 fn encode_info_for_mod ( & mut self , local_def_id : LocalDefId , md : & hir:: Mod < ' _ > ) {
@@ -1002,9 +1074,6 @@ impl EncodeContext<'a, 'tcx> {
10021074 record ! ( self . tables. kind[ def_id] <- EntryKind :: Field ) ;
10031075 self . encode_ident_span ( def_id, field. ident ) ;
10041076 self . encode_item_type ( def_id) ;
1005- self . encode_generics ( def_id) ;
1006- self . encode_explicit_predicates ( def_id) ;
1007- self . encode_inferred_outlives ( def_id) ;
10081077 }
10091078
10101079 fn encode_struct_ctor ( & mut self , adt_def : & ty:: AdtDef , def_id : DefId ) {
@@ -1023,37 +1092,9 @@ impl EncodeContext<'a, 'tcx> {
10231092 self . encode_item_type ( def_id) ;
10241093 if variant. ctor_kind == CtorKind :: Fn {
10251094 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1026- self . encode_variances_of ( def_id) ;
1027- }
1028- self . encode_generics ( def_id) ;
1029- self . encode_explicit_predicates ( def_id) ;
1030- self . encode_inferred_outlives ( def_id) ;
1031- }
1032-
1033- fn encode_generics ( & mut self , def_id : DefId ) {
1034- debug ! ( "EncodeContext::encode_generics({:?})" , def_id) ;
1035- record ! ( self . tables. generics[ def_id] <- self . tcx. generics_of( def_id) ) ;
1036- }
1037-
1038- fn encode_explicit_predicates ( & mut self , def_id : DefId ) {
1039- debug ! ( "EncodeContext::encode_explicit_predicates({:?})" , def_id) ;
1040- record ! ( self . tables. explicit_predicates[ def_id] <-
1041- self . tcx. explicit_predicates_of( def_id) ) ;
1042- }
1043-
1044- fn encode_inferred_outlives ( & mut self , def_id : DefId ) {
1045- debug ! ( "EncodeContext::encode_inferred_outlives({:?})" , def_id) ;
1046- let inferred_outlives = self . tcx . inferred_outlives_of ( def_id) ;
1047- if !inferred_outlives. is_empty ( ) {
1048- record ! ( self . tables. inferred_outlives[ def_id] <- inferred_outlives) ;
10491095 }
10501096 }
10511097
1052- fn encode_super_predicates ( & mut self , def_id : DefId ) {
1053- debug ! ( "EncodeContext::encode_super_predicates({:?})" , def_id) ;
1054- record ! ( self . tables. super_predicates[ def_id] <- self . tcx. super_predicates_of( def_id) ) ;
1055- }
1056-
10571098 fn encode_explicit_item_bounds ( & mut self , def_id : DefId ) {
10581099 debug ! ( "EncodeContext::encode_explicit_item_bounds({:?})" , def_id) ;
10591100 let bounds = self . tcx . explicit_item_bounds ( def_id) ;
@@ -1128,11 +1169,7 @@ impl EncodeContext<'a, 'tcx> {
11281169 }
11291170 if trait_item. kind == ty:: AssocKind :: Fn {
11301171 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1131- self . encode_variances_of ( def_id) ;
11321172 }
1133- self . encode_generics ( def_id) ;
1134- self . encode_explicit_predicates ( def_id) ;
1135- self . encode_inferred_outlives ( def_id) ;
11361173 }
11371174
11381175 fn encode_info_for_impl_item ( & mut self , def_id : DefId ) {
@@ -1189,11 +1226,7 @@ impl EncodeContext<'a, 'tcx> {
11891226 self . encode_item_type ( def_id) ;
11901227 if impl_item. kind == ty:: AssocKind :: Fn {
11911228 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1192- self . encode_variances_of ( def_id) ;
11931229 }
1194- self . encode_generics ( def_id) ;
1195- self . encode_explicit_predicates ( def_id) ;
1196- self . encode_inferred_outlives ( def_id) ;
11971230 }
11981231
11991232 fn encode_fn_param_names_for_body ( & mut self , body_id : hir:: BodyId ) -> Lazy < [ Ident ] > {
@@ -1458,37 +1491,6 @@ impl EncodeContext<'a, 'tcx> {
14581491 record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
14591492 }
14601493 }
1461- match item. kind {
1462- hir:: ItemKind :: Enum ( ..)
1463- | hir:: ItemKind :: Struct ( ..)
1464- | hir:: ItemKind :: Union ( ..)
1465- | hir:: ItemKind :: Fn ( ..) => self . encode_variances_of ( def_id) ,
1466- _ => { }
1467- }
1468- match item. kind {
1469- hir:: ItemKind :: Static ( ..)
1470- | hir:: ItemKind :: Const ( ..)
1471- | hir:: ItemKind :: Fn ( ..)
1472- | hir:: ItemKind :: TyAlias ( ..)
1473- | hir:: ItemKind :: Enum ( ..)
1474- | hir:: ItemKind :: Struct ( ..)
1475- | hir:: ItemKind :: Union ( ..)
1476- | hir:: ItemKind :: Impl { .. }
1477- | hir:: ItemKind :: OpaqueTy ( ..)
1478- | hir:: ItemKind :: Trait ( ..)
1479- | hir:: ItemKind :: TraitAlias ( ..) => {
1480- self . encode_generics ( def_id) ;
1481- self . encode_explicit_predicates ( def_id) ;
1482- self . encode_inferred_outlives ( def_id) ;
1483- }
1484- _ => { }
1485- }
1486- match item. kind {
1487- hir:: ItemKind :: Trait ( ..) | hir:: ItemKind :: TraitAlias ( ..) => {
1488- self . encode_super_predicates ( def_id) ;
1489- }
1490- _ => { }
1491- }
14921494 }
14931495
14941496 /// Serialize the text of exported macros
@@ -1529,7 +1531,6 @@ impl EncodeContext<'a, 'tcx> {
15291531 if let ty:: Closure ( def_id, substs) = * ty. kind ( ) {
15301532 record ! ( self . tables. fn_sig[ def_id] <- substs. as_closure( ) . sig( ) ) ;
15311533 }
1532- self . encode_generics ( def_id. to_def_id ( ) ) ;
15331534 }
15341535
15351536 fn encode_info_for_anon_const ( & mut self , def_id : LocalDefId ) {
@@ -1541,9 +1542,6 @@ impl EncodeContext<'a, 'tcx> {
15411542
15421543 record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: AnonConst ( qualifs, const_data) ) ;
15431544 self . encode_item_type ( def_id. to_def_id ( ) ) ;
1544- self . encode_generics ( def_id. to_def_id ( ) ) ;
1545- self . encode_explicit_predicates ( def_id. to_def_id ( ) ) ;
1546- self . encode_inferred_outlives ( def_id. to_def_id ( ) ) ;
15471545 }
15481546
15491547 fn encode_native_libraries ( & mut self ) -> Lazy < [ NativeLib ] > {
@@ -1822,11 +1820,7 @@ impl EncodeContext<'a, 'tcx> {
18221820 self . encode_item_type ( def_id) ;
18231821 if let hir:: ForeignItemKind :: Fn ( ..) = nitem. kind {
18241822 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1825- self . encode_variances_of ( def_id) ;
18261823 }
1827- self . encode_generics ( def_id) ;
1828- self . encode_explicit_predicates ( def_id) ;
1829- self . encode_inferred_outlives ( def_id) ;
18301824 }
18311825}
18321826
0 commit comments