@@ -71,11 +71,14 @@ struct PerDefTables<'tcx> {
71
71
deprecation : PerDefTable < Lazy < attr:: Deprecation > > ,
72
72
73
73
ty : PerDefTable < Lazy < Ty < ' tcx > > > ,
74
+ fn_sig : PerDefTable < Lazy < ty:: PolyFnSig < ' tcx > > > ,
75
+ impl_trait_ref : PerDefTable < Lazy < ty:: TraitRef < ' tcx > > > ,
74
76
inherent_impls : PerDefTable < Lazy < [ DefIndex ] > > ,
75
77
variances : PerDefTable < Lazy < [ ty:: Variance ] > > ,
76
78
generics : PerDefTable < Lazy < ty:: Generics > > ,
77
79
predicates : PerDefTable < Lazy < ty:: GenericPredicates < ' tcx > > > ,
78
80
predicates_defined_on : PerDefTable < Lazy < ty:: GenericPredicates < ' tcx > > > ,
81
+ super_predicates : PerDefTable < Lazy < ty:: GenericPredicates < ' tcx > > > ,
79
82
80
83
mir : PerDefTable < Lazy < mir:: Body < ' tcx > > > ,
81
84
promoted_mir : PerDefTable < Lazy < IndexVec < mir:: Promoted , mir:: Body < ' tcx > > > > ,
@@ -508,11 +511,14 @@ impl<'tcx> EncodeContext<'tcx> {
508
511
deprecation : self . per_def . deprecation . encode ( & mut self . opaque ) ,
509
512
510
513
ty : self . per_def . ty . encode ( & mut self . opaque ) ,
514
+ fn_sig : self . per_def . fn_sig . encode ( & mut self . opaque ) ,
515
+ impl_trait_ref : self . per_def . impl_trait_ref . encode ( & mut self . opaque ) ,
511
516
inherent_impls : self . per_def . inherent_impls . encode ( & mut self . opaque ) ,
512
517
variances : self . per_def . variances . encode ( & mut self . opaque ) ,
513
518
generics : self . per_def . generics . encode ( & mut self . opaque ) ,
514
519
predicates : self . per_def . predicates . encode ( & mut self . opaque ) ,
515
520
predicates_defined_on : self . per_def . predicates_defined_on . encode ( & mut self . opaque ) ,
521
+ super_predicates : self . per_def . super_predicates . encode ( & mut self . opaque ) ,
516
522
517
523
mir : self . per_def . mir . encode ( & mut self . opaque ) ,
518
524
promoted_mir : self . per_def . promoted_mir . encode ( & mut self . opaque ) ,
@@ -635,13 +641,7 @@ impl EncodeContext<'tcx> {
635
641
let data = VariantData {
636
642
ctor_kind : variant. ctor_kind ,
637
643
discr : variant. discr ,
638
- // FIXME(eddyb) deduplicate these with `encode_enum_variant_ctor`.
639
644
ctor : variant. ctor_def_id . map ( |did| did. index ) ,
640
- ctor_sig : if variant. ctor_kind == CtorKind :: Fn {
641
- variant. ctor_def_id . map ( |ctor_def_id| self . lazy ( & tcx. fn_sig ( ctor_def_id) ) )
642
- } else {
643
- None
644
- } ,
645
645
} ;
646
646
647
647
let enum_id = tcx. hir ( ) . as_local_hir_id ( enum_did) . unwrap ( ) ;
@@ -660,6 +660,11 @@ impl EncodeContext<'tcx> {
660
660
self . encode_deprecation ( def_id) ;
661
661
self . encode_item_type ( def_id) ;
662
662
if variant. ctor_kind == CtorKind :: Fn {
663
+ // FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
664
+ if let Some ( ctor_def_id) = variant. ctor_def_id {
665
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( ctor_def_id) ) ;
666
+ }
667
+ // FIXME(eddyb) is this ever used?
663
668
self . encode_variances_of ( def_id) ;
664
669
}
665
670
self . encode_generics ( def_id) ;
@@ -679,15 +684,11 @@ impl EncodeContext<'tcx> {
679
684
let def_id = variant. ctor_def_id . unwrap ( ) ;
680
685
debug ! ( "EncodeContext::encode_enum_variant_ctor({:?})" , def_id) ;
681
686
687
+ // FIXME(eddyb) encode only the `CtorKind` for constructors.
682
688
let data = VariantData {
683
689
ctor_kind : variant. ctor_kind ,
684
690
discr : variant. discr ,
685
691
ctor : Some ( def_id. index ) ,
686
- ctor_sig : if variant. ctor_kind == CtorKind :: Fn {
687
- Some ( self . lazy ( tcx. fn_sig ( def_id) ) )
688
- } else {
689
- None
690
- }
691
692
} ;
692
693
693
694
// Variant constructors have the same visibility as the parent enums, unless marked as
@@ -706,6 +707,7 @@ impl EncodeContext<'tcx> {
706
707
self . encode_deprecation ( def_id) ;
707
708
self . encode_item_type ( def_id) ;
708
709
if variant. ctor_kind == CtorKind :: Fn {
710
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
709
711
self . encode_variances_of ( def_id) ;
710
712
}
711
713
self . encode_generics ( def_id) ;
@@ -780,11 +782,6 @@ impl EncodeContext<'tcx> {
780
782
ctor_kind : variant. ctor_kind ,
781
783
discr : variant. discr ,
782
784
ctor : Some ( def_id. index ) ,
783
- ctor_sig : if variant. ctor_kind == CtorKind :: Fn {
784
- Some ( self . lazy ( tcx. fn_sig ( def_id) ) )
785
- } else {
786
- None
787
- }
788
785
} ;
789
786
790
787
let struct_id = tcx. hir ( ) . as_local_hir_id ( adt_def_id) . unwrap ( ) ;
@@ -811,6 +808,7 @@ impl EncodeContext<'tcx> {
811
808
self . encode_deprecation ( def_id) ;
812
809
self . encode_item_type ( def_id) ;
813
810
if variant. ctor_kind == CtorKind :: Fn {
811
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
814
812
self . encode_variances_of ( def_id) ;
815
813
}
816
814
self . encode_generics ( def_id) ;
@@ -835,6 +833,11 @@ impl EncodeContext<'tcx> {
835
833
self . tcx. predicates_defined_on( def_id) )
836
834
}
837
835
836
+ fn encode_super_predicates ( & mut self , def_id : DefId ) {
837
+ debug ! ( "EncodeContext::encode_super_predicates({:?})" , def_id) ;
838
+ record ! ( self . per_def. super_predicates[ def_id] <- self . tcx. super_predicates_of( def_id) ) ;
839
+ }
840
+
838
841
fn encode_info_for_trait_item ( & mut self , def_id : DefId ) {
839
842
debug ! ( "EncodeContext::encode_info_for_trait_item({:?})" , def_id) ;
840
843
let tcx = self . tcx ;
@@ -874,7 +877,6 @@ impl EncodeContext<'tcx> {
874
877
asyncness: m_sig. header. asyncness,
875
878
constness: hir:: Constness :: NotConst ,
876
879
param_names,
877
- sig: self . lazy( tcx. fn_sig( def_id) ) ,
878
880
}
879
881
} else {
880
882
bug!( )
@@ -906,6 +908,7 @@ impl EncodeContext<'tcx> {
906
908
ty:: AssocKind :: OpaqueTy => unreachable ! ( ) ,
907
909
}
908
910
if trait_item. kind == ty:: AssocKind :: Method {
911
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
909
912
self . encode_variances_of ( def_id) ;
910
913
}
911
914
self . encode_generics ( def_id) ;
@@ -952,7 +955,6 @@ impl EncodeContext<'tcx> {
952
955
asyncness: sig. header. asyncness,
953
956
constness: sig. header. constness,
954
957
param_names: self . encode_fn_param_names_for_body( body) ,
955
- sig: self . lazy( tcx. fn_sig( def_id) ) ,
956
958
}
957
959
} else {
958
960
bug!( )
@@ -973,6 +975,7 @@ impl EncodeContext<'tcx> {
973
975
self . encode_deprecation ( def_id) ;
974
976
self . encode_item_type ( def_id) ;
975
977
if impl_item. kind == ty:: AssocKind :: Method {
978
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
976
979
self . encode_variances_of ( def_id) ;
977
980
}
978
981
self . encode_generics ( def_id) ;
@@ -1081,7 +1084,6 @@ impl EncodeContext<'tcx> {
1081
1084
asyncness: header. asyncness,
1082
1085
constness: header. constness,
1083
1086
param_names: self . encode_fn_param_names_for_body( body) ,
1084
- sig: self . lazy( tcx. fn_sig( def_id) ) ,
1085
1087
} ;
1086
1088
1087
1089
EntryKind :: Fn ( self . lazy( data) )
@@ -1109,7 +1111,6 @@ impl EncodeContext<'tcx> {
1109
1111
ctor_kind: variant. ctor_kind,
1110
1112
discr: variant. discr,
1111
1113
ctor,
1112
- ctor_sig: None ,
1113
1114
} ) , adt_def. repr)
1114
1115
}
1115
1116
hir:: ItemKind :: Union ( ..) => {
@@ -1120,7 +1121,6 @@ impl EncodeContext<'tcx> {
1120
1121
ctor_kind: variant. ctor_kind,
1121
1122
discr: variant. discr,
1122
1123
ctor: None ,
1123
- ctor_sig: None ,
1124
1124
} ) , adt_def. repr)
1125
1125
}
1126
1126
hir:: ItemKind :: Impl ( _, _, defaultness, ..) => {
@@ -1154,7 +1154,6 @@ impl EncodeContext<'tcx> {
1154
1154
defaultness,
1155
1155
parent_impl: parent,
1156
1156
coerce_unsized_info,
1157
- trait_ref: trait_ref. map( |trait_ref| self . lazy( trait_ref) ) ,
1158
1157
} ;
1159
1158
1160
1159
EntryKind :: Impl ( self . lazy( data) )
@@ -1166,18 +1165,11 @@ impl EncodeContext<'tcx> {
1166
1165
paren_sugar: trait_def. paren_sugar,
1167
1166
has_auto_impl: self . tcx. trait_is_auto( def_id) ,
1168
1167
is_marker: trait_def. is_marker,
1169
- super_predicates: self . lazy( tcx. super_predicates_of( def_id) ) ,
1170
1168
} ;
1171
1169
1172
1170
EntryKind :: Trait ( self . lazy( data) )
1173
1171
}
1174
- hir:: ItemKind :: TraitAlias ( ..) => {
1175
- let data = TraitAliasData {
1176
- super_predicates: self . lazy( tcx. super_predicates_of( def_id) ) ,
1177
- } ;
1178
-
1179
- EntryKind :: TraitAlias ( self . lazy( data) )
1180
- }
1172
+ hir:: ItemKind :: TraitAlias ( ..) => EntryKind :: TraitAlias ,
1181
1173
hir:: ItemKind :: ExternCrate ( _) |
1182
1174
hir:: ItemKind :: Use ( ..) => bug!( "cannot encode info for item {:?}" , item) ,
1183
1175
} ) ;
@@ -1232,6 +1224,14 @@ impl EncodeContext<'tcx> {
1232
1224
hir:: ItemKind :: Impl ( ..) => self . encode_item_type ( def_id) ,
1233
1225
_ => { }
1234
1226
}
1227
+ if let hir:: ItemKind :: Fn ( ..) = item. kind {
1228
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1229
+ }
1230
+ if let hir:: ItemKind :: Impl ( ..) = item. kind {
1231
+ if let Some ( trait_ref) = self . tcx . impl_trait_ref ( def_id) {
1232
+ record ! ( self . per_def. impl_trait_ref[ def_id] <- trait_ref) ;
1233
+ }
1234
+ }
1235
1235
self . encode_inherent_implementations ( def_id) ;
1236
1236
match item. kind {
1237
1237
hir:: ItemKind :: Enum ( ..) |
@@ -1269,6 +1269,13 @@ impl EncodeContext<'tcx> {
1269
1269
}
1270
1270
_ => { } // not *wrong* for other kinds of items, but not needed
1271
1271
}
1272
+ match item. kind {
1273
+ hir:: ItemKind :: Trait ( ..) |
1274
+ hir:: ItemKind :: TraitAlias ( ..) => {
1275
+ self . encode_super_predicates ( def_id) ;
1276
+ }
1277
+ _ => { }
1278
+ }
1272
1279
1273
1280
let mir = match item. kind {
1274
1281
hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => true ,
@@ -1321,10 +1328,12 @@ impl EncodeContext<'tcx> {
1321
1328
fn encode_info_for_closure ( & mut self , def_id : DefId ) {
1322
1329
debug ! ( "EncodeContext::encode_info_for_closure({:?})" , def_id) ;
1323
1330
1324
- let tables = self . tcx . typeck_tables_of ( def_id) ;
1331
+ // NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
1332
+ // including on the signature, which is inferred in `typeck_tables_of.
1325
1333
let hir_id = self . tcx . hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
1334
+ let ty = self . tcx . typeck_tables_of ( def_id) . node_type ( hir_id) ;
1326
1335
1327
- record ! ( self . per_def. kind[ def_id] <- match tables . node_type ( hir_id ) . kind {
1336
+ record ! ( self . per_def. kind[ def_id] <- match ty . kind {
1328
1337
ty:: Generator ( def_id, ..) => {
1329
1338
let layout = self . tcx. generator_layout( def_id) ;
1330
1339
let data = GeneratorData {
@@ -1333,18 +1342,17 @@ impl EncodeContext<'tcx> {
1333
1342
EntryKind :: Generator ( self . lazy( data) )
1334
1343
}
1335
1344
1336
- ty:: Closure ( def_id, substs) => {
1337
- let sig = substs. as_closure( ) . sig( def_id, self . tcx) ;
1338
- let data = ClosureData { sig: self . lazy( sig) } ;
1339
- EntryKind :: Closure ( self . lazy( data) )
1340
- }
1345
+ ty:: Closure ( ..) => EntryKind :: Closure ,
1341
1346
1342
1347
_ => bug!( "closure that is neither generator nor closure" ) ,
1343
1348
} ) ;
1344
1349
record ! ( self . per_def. visibility[ def_id] <- ty:: Visibility :: Public ) ;
1345
1350
record ! ( self . per_def. span[ def_id] <- self . tcx. def_span( def_id) ) ;
1346
1351
record ! ( self . per_def. attributes[ def_id] <- & self . tcx. get_attrs( def_id) [ ..] ) ;
1347
1352
self . encode_item_type ( def_id) ;
1353
+ if let ty:: Closure ( def_id, substs) = ty. kind {
1354
+ record ! ( self . per_def. fn_sig[ def_id] <- substs. as_closure( ) . sig( def_id, self . tcx) ) ;
1355
+ }
1348
1356
self . encode_generics ( def_id) ;
1349
1357
self . encode_optimized_mir ( def_id) ;
1350
1358
self . encode_promoted_mir ( def_id) ;
@@ -1553,7 +1561,6 @@ impl EncodeContext<'tcx> {
1553
1561
asyncness: hir:: IsAsync :: NotAsync ,
1554
1562
constness: hir:: Constness :: NotConst ,
1555
1563
param_names: self . encode_fn_param_names( names) ,
1556
- sig: self . lazy( tcx. fn_sig( def_id) ) ,
1557
1564
} ;
1558
1565
EntryKind :: ForeignFn ( self . lazy( data) )
1559
1566
}
@@ -1569,6 +1576,7 @@ impl EncodeContext<'tcx> {
1569
1576
self . encode_deprecation ( def_id) ;
1570
1577
self . encode_item_type ( def_id) ;
1571
1578
if let hir:: ForeignItemKind :: Fn ( ..) = nitem. kind {
1579
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1572
1580
self . encode_variances_of ( def_id) ;
1573
1581
}
1574
1582
self . encode_generics ( def_id) ;
0 commit comments