@@ -836,6 +836,76 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
836
836
}
837
837
}
838
838
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
+
839
909
impl EncodeContext < ' a , ' tcx > {
840
910
fn encode_def_ids ( & mut self ) {
841
911
if self . is_proc_macro {
@@ -864,6 +934,22 @@ impl EncodeContext<'a, 'tcx> {
864
934
self . encode_const_stability ( def_id) ;
865
935
self . encode_deprecation ( def_id) ;
866
936
}
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
+ }
867
953
}
868
954
let inherent_impls = tcx. crate_inherent_impls ( LOCAL_CRATE ) ;
869
955
for ( def_id, implementations) in inherent_impls. inherent_impls . iter ( ) {
@@ -878,11 +964,6 @@ impl EncodeContext<'a, 'tcx> {
878
964
}
879
965
}
880
966
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
-
886
967
fn encode_item_type ( & mut self , def_id : DefId ) {
887
968
debug ! ( "EncodeContext::encode_item_type({:?})" , def_id) ;
888
969
record ! ( self . tables. ty[ def_id] <- self . tcx. type_of( def_id) ) ;
@@ -913,12 +994,7 @@ impl EncodeContext<'a, 'tcx> {
913
994
if let Some ( ctor_def_id) = variant. ctor_def_id {
914
995
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( ctor_def_id) ) ;
915
996
}
916
- // FIXME(eddyb) is this ever used?
917
- self . encode_variances_of ( def_id) ;
918
997
}
919
- self . encode_generics ( def_id) ;
920
- self . encode_explicit_predicates ( def_id) ;
921
- self . encode_inferred_outlives ( def_id) ;
922
998
}
923
999
924
1000
fn encode_enum_variant_ctor ( & mut self , def : & ty:: AdtDef , index : VariantIdx ) {
@@ -939,11 +1015,7 @@ impl EncodeContext<'a, 'tcx> {
939
1015
self . encode_item_type ( def_id) ;
940
1016
if variant. ctor_kind == CtorKind :: Fn {
941
1017
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
942
- self . encode_variances_of ( def_id) ;
943
1018
}
944
- self . encode_generics ( def_id) ;
945
- self . encode_explicit_predicates ( def_id) ;
946
- self . encode_inferred_outlives ( def_id) ;
947
1019
}
948
1020
949
1021
fn encode_info_for_mod ( & mut self , local_def_id : LocalDefId , md : & hir:: Mod < ' _ > ) {
@@ -1002,9 +1074,6 @@ impl EncodeContext<'a, 'tcx> {
1002
1074
record ! ( self . tables. kind[ def_id] <- EntryKind :: Field ) ;
1003
1075
self . encode_ident_span ( def_id, field. ident ) ;
1004
1076
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) ;
1008
1077
}
1009
1078
1010
1079
fn encode_struct_ctor ( & mut self , adt_def : & ty:: AdtDef , def_id : DefId ) {
@@ -1023,37 +1092,9 @@ impl EncodeContext<'a, 'tcx> {
1023
1092
self . encode_item_type ( def_id) ;
1024
1093
if variant. ctor_kind == CtorKind :: Fn {
1025
1094
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) ;
1049
1095
}
1050
1096
}
1051
1097
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
-
1057
1098
fn encode_explicit_item_bounds ( & mut self , def_id : DefId ) {
1058
1099
debug ! ( "EncodeContext::encode_explicit_item_bounds({:?})" , def_id) ;
1059
1100
let bounds = self . tcx . explicit_item_bounds ( def_id) ;
@@ -1128,11 +1169,7 @@ impl EncodeContext<'a, 'tcx> {
1128
1169
}
1129
1170
if trait_item. kind == ty:: AssocKind :: Fn {
1130
1171
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1131
- self . encode_variances_of ( def_id) ;
1132
1172
}
1133
- self . encode_generics ( def_id) ;
1134
- self . encode_explicit_predicates ( def_id) ;
1135
- self . encode_inferred_outlives ( def_id) ;
1136
1173
}
1137
1174
1138
1175
fn encode_info_for_impl_item ( & mut self , def_id : DefId ) {
@@ -1189,11 +1226,7 @@ impl EncodeContext<'a, 'tcx> {
1189
1226
self . encode_item_type ( def_id) ;
1190
1227
if impl_item. kind == ty:: AssocKind :: Fn {
1191
1228
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1192
- self . encode_variances_of ( def_id) ;
1193
1229
}
1194
- self . encode_generics ( def_id) ;
1195
- self . encode_explicit_predicates ( def_id) ;
1196
- self . encode_inferred_outlives ( def_id) ;
1197
1230
}
1198
1231
1199
1232
fn encode_fn_param_names_for_body ( & mut self , body_id : hir:: BodyId ) -> Lazy < [ Ident ] > {
@@ -1458,37 +1491,6 @@ impl EncodeContext<'a, 'tcx> {
1458
1491
record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
1459
1492
}
1460
1493
}
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
- }
1492
1494
}
1493
1495
1494
1496
/// Serialize the text of exported macros
@@ -1529,7 +1531,6 @@ impl EncodeContext<'a, 'tcx> {
1529
1531
if let ty:: Closure ( def_id, substs) = * ty. kind ( ) {
1530
1532
record ! ( self . tables. fn_sig[ def_id] <- substs. as_closure( ) . sig( ) ) ;
1531
1533
}
1532
- self . encode_generics ( def_id. to_def_id ( ) ) ;
1533
1534
}
1534
1535
1535
1536
fn encode_info_for_anon_const ( & mut self , def_id : LocalDefId ) {
@@ -1541,9 +1542,6 @@ impl EncodeContext<'a, 'tcx> {
1541
1542
1542
1543
record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: AnonConst ( qualifs, const_data) ) ;
1543
1544
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 ( ) ) ;
1547
1545
}
1548
1546
1549
1547
fn encode_native_libraries ( & mut self ) -> Lazy < [ NativeLib ] > {
@@ -1822,11 +1820,7 @@ impl EncodeContext<'a, 'tcx> {
1822
1820
self . encode_item_type ( def_id) ;
1823
1821
if let hir:: ForeignItemKind :: Fn ( ..) = nitem. kind {
1824
1822
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1825
- self . encode_variances_of ( def_id) ;
1826
1823
}
1827
- self . encode_generics ( def_id) ;
1828
- self . encode_explicit_predicates ( def_id) ;
1829
- self . encode_inferred_outlives ( def_id) ;
1830
1824
}
1831
1825
}
1832
1826
0 commit comments