@@ -71,6 +71,7 @@ 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 > > > ,
74
75
inherent_impls : PerDefTable < Lazy < [ DefIndex ] > > ,
75
76
variances : PerDefTable < Lazy < [ ty:: Variance ] > > ,
76
77
generics : PerDefTable < Lazy < ty:: Generics > > ,
@@ -509,6 +510,7 @@ impl<'tcx> EncodeContext<'tcx> {
509
510
deprecation : self . per_def . deprecation . encode ( & mut self . opaque ) ,
510
511
511
512
ty : self . per_def . ty . encode ( & mut self . opaque ) ,
513
+ fn_sig : self . per_def . fn_sig . encode ( & mut self . opaque ) ,
512
514
inherent_impls : self . per_def . inherent_impls . encode ( & mut self . opaque ) ,
513
515
variances : self . per_def . variances . encode ( & mut self . opaque ) ,
514
516
generics : self . per_def . generics . encode ( & mut self . opaque ) ,
@@ -637,13 +639,7 @@ impl EncodeContext<'tcx> {
637
639
let data = VariantData {
638
640
ctor_kind : variant. ctor_kind ,
639
641
discr : variant. discr ,
640
- // FIXME(eddyb) deduplicate these with `encode_enum_variant_ctor`.
641
642
ctor : variant. ctor_def_id . map ( |did| did. index ) ,
642
- ctor_sig : if variant. ctor_kind == CtorKind :: Fn {
643
- variant. ctor_def_id . map ( |ctor_def_id| self . lazy ( & tcx. fn_sig ( ctor_def_id) ) )
644
- } else {
645
- None
646
- } ,
647
643
} ;
648
644
649
645
let enum_id = tcx. hir ( ) . as_local_hir_id ( enum_did) . unwrap ( ) ;
@@ -662,6 +658,11 @@ impl EncodeContext<'tcx> {
662
658
self . encode_deprecation ( def_id) ;
663
659
self . encode_item_type ( def_id) ;
664
660
if variant. ctor_kind == CtorKind :: Fn {
661
+ // FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
662
+ if let Some ( ctor_def_id) = variant. ctor_def_id {
663
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( ctor_def_id) ) ;
664
+ }
665
+ // FIXME(eddyb) is this ever used?
665
666
self . encode_variances_of ( def_id) ;
666
667
}
667
668
self . encode_generics ( def_id) ;
@@ -681,15 +682,11 @@ impl EncodeContext<'tcx> {
681
682
let def_id = variant. ctor_def_id . unwrap ( ) ;
682
683
debug ! ( "EncodeContext::encode_enum_variant_ctor({:?})" , def_id) ;
683
684
685
+ // FIXME(eddyb) encode only the `CtorKind` for constructors.
684
686
let data = VariantData {
685
687
ctor_kind : variant. ctor_kind ,
686
688
discr : variant. discr ,
687
689
ctor : Some ( def_id. index ) ,
688
- ctor_sig : if variant. ctor_kind == CtorKind :: Fn {
689
- Some ( self . lazy ( tcx. fn_sig ( def_id) ) )
690
- } else {
691
- None
692
- }
693
690
} ;
694
691
695
692
// Variant constructors have the same visibility as the parent enums, unless marked as
@@ -708,6 +705,7 @@ impl EncodeContext<'tcx> {
708
705
self . encode_deprecation ( def_id) ;
709
706
self . encode_item_type ( def_id) ;
710
707
if variant. ctor_kind == CtorKind :: Fn {
708
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
711
709
self . encode_variances_of ( def_id) ;
712
710
}
713
711
self . encode_generics ( def_id) ;
@@ -782,11 +780,6 @@ impl EncodeContext<'tcx> {
782
780
ctor_kind : variant. ctor_kind ,
783
781
discr : variant. discr ,
784
782
ctor : Some ( def_id. index ) ,
785
- ctor_sig : if variant. ctor_kind == CtorKind :: Fn {
786
- Some ( self . lazy ( tcx. fn_sig ( def_id) ) )
787
- } else {
788
- None
789
- }
790
783
} ;
791
784
792
785
let struct_id = tcx. hir ( ) . as_local_hir_id ( adt_def_id) . unwrap ( ) ;
@@ -813,6 +806,7 @@ impl EncodeContext<'tcx> {
813
806
self . encode_deprecation ( def_id) ;
814
807
self . encode_item_type ( def_id) ;
815
808
if variant. ctor_kind == CtorKind :: Fn {
809
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
816
810
self . encode_variances_of ( def_id) ;
817
811
}
818
812
self . encode_generics ( def_id) ;
@@ -881,7 +875,6 @@ impl EncodeContext<'tcx> {
881
875
asyncness: m_sig. header. asyncness,
882
876
constness: hir:: Constness :: NotConst ,
883
877
param_names,
884
- sig: self . lazy( tcx. fn_sig( def_id) ) ,
885
878
}
886
879
} else {
887
880
bug!( )
@@ -913,6 +906,7 @@ impl EncodeContext<'tcx> {
913
906
ty:: AssocKind :: OpaqueTy => unreachable ! ( ) ,
914
907
}
915
908
if trait_item. kind == ty:: AssocKind :: Method {
909
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
916
910
self . encode_variances_of ( def_id) ;
917
911
}
918
912
self . encode_generics ( def_id) ;
@@ -959,7 +953,6 @@ impl EncodeContext<'tcx> {
959
953
asyncness: sig. header. asyncness,
960
954
constness: sig. header. constness,
961
955
param_names: self . encode_fn_param_names_for_body( body) ,
962
- sig: self . lazy( tcx. fn_sig( def_id) ) ,
963
956
}
964
957
} else {
965
958
bug!( )
@@ -980,6 +973,7 @@ impl EncodeContext<'tcx> {
980
973
self . encode_deprecation ( def_id) ;
981
974
self . encode_item_type ( def_id) ;
982
975
if impl_item. kind == ty:: AssocKind :: Method {
976
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
983
977
self . encode_variances_of ( def_id) ;
984
978
}
985
979
self . encode_generics ( def_id) ;
@@ -1088,7 +1082,6 @@ impl EncodeContext<'tcx> {
1088
1082
asyncness: header. asyncness,
1089
1083
constness: header. constness,
1090
1084
param_names: self . encode_fn_param_names_for_body( body) ,
1091
- sig: self . lazy( tcx. fn_sig( def_id) ) ,
1092
1085
} ;
1093
1086
1094
1087
EntryKind :: Fn ( self . lazy( data) )
@@ -1116,7 +1109,6 @@ impl EncodeContext<'tcx> {
1116
1109
ctor_kind: variant. ctor_kind,
1117
1110
discr: variant. discr,
1118
1111
ctor,
1119
- ctor_sig: None ,
1120
1112
} ) , adt_def. repr)
1121
1113
}
1122
1114
hir:: ItemKind :: Union ( ..) => {
@@ -1127,7 +1119,6 @@ impl EncodeContext<'tcx> {
1127
1119
ctor_kind: variant. ctor_kind,
1128
1120
discr: variant. discr,
1129
1121
ctor: None ,
1130
- ctor_sig: None ,
1131
1122
} ) , adt_def. repr)
1132
1123
}
1133
1124
hir:: ItemKind :: Impl ( _, _, defaultness, ..) => {
@@ -1232,6 +1223,9 @@ impl EncodeContext<'tcx> {
1232
1223
hir:: ItemKind :: Impl ( ..) => self . encode_item_type ( def_id) ,
1233
1224
_ => { }
1234
1225
}
1226
+ if let hir:: ItemKind :: Fn ( ..) = item. kind {
1227
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1228
+ }
1235
1229
self . encode_inherent_implementations ( def_id) ;
1236
1230
match item. kind {
1237
1231
hir:: ItemKind :: Enum ( ..) |
@@ -1328,10 +1322,12 @@ impl EncodeContext<'tcx> {
1328
1322
fn encode_info_for_closure ( & mut self , def_id : DefId ) {
1329
1323
debug ! ( "EncodeContext::encode_info_for_closure({:?})" , def_id) ;
1330
1324
1331
- let tables = self . tcx . typeck_tables_of ( def_id) ;
1325
+ // NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
1326
+ // including on the signature, which is inferred in `typeck_tables_of.
1332
1327
let hir_id = self . tcx . hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
1328
+ let ty = self . tcx . typeck_tables_of ( def_id) . node_type ( hir_id) ;
1333
1329
1334
- record ! ( self . per_def. kind[ def_id] <- match tables . node_type ( hir_id ) . kind {
1330
+ record ! ( self . per_def. kind[ def_id] <- match ty . kind {
1335
1331
ty:: Generator ( def_id, ..) => {
1336
1332
let layout = self . tcx. generator_layout( def_id) ;
1337
1333
let data = GeneratorData {
@@ -1340,18 +1336,17 @@ impl EncodeContext<'tcx> {
1340
1336
EntryKind :: Generator ( self . lazy( data) )
1341
1337
}
1342
1338
1343
- ty:: Closure ( def_id, substs) => {
1344
- let sig = substs. as_closure( ) . sig( def_id, self . tcx) ;
1345
- let data = ClosureData { sig: self . lazy( sig) } ;
1346
- EntryKind :: Closure ( self . lazy( data) )
1347
- }
1339
+ ty:: Closure ( ..) => EntryKind :: Closure ,
1348
1340
1349
1341
_ => bug!( "closure that is neither generator nor closure" ) ,
1350
1342
} ) ;
1351
1343
record ! ( self . per_def. visibility[ def_id] <- ty:: Visibility :: Public ) ;
1352
1344
record ! ( self . per_def. span[ def_id] <- self . tcx. def_span( def_id) ) ;
1353
1345
record ! ( self . per_def. attributes[ def_id] <- & self . tcx. get_attrs( def_id) [ ..] ) ;
1354
1346
self . encode_item_type ( def_id) ;
1347
+ if let ty:: Closure ( def_id, substs) = ty. kind {
1348
+ record ! ( self . per_def. fn_sig[ def_id] <- substs. as_closure( ) . sig( def_id, self . tcx) ) ;
1349
+ }
1355
1350
self . encode_generics ( def_id) ;
1356
1351
self . encode_optimized_mir ( def_id) ;
1357
1352
self . encode_promoted_mir ( def_id) ;
@@ -1560,7 +1555,6 @@ impl EncodeContext<'tcx> {
1560
1555
asyncness: hir:: IsAsync :: NotAsync ,
1561
1556
constness: hir:: Constness :: NotConst ,
1562
1557
param_names: self . encode_fn_param_names( names) ,
1563
- sig: self . lazy( tcx. fn_sig( def_id) ) ,
1564
1558
} ;
1565
1559
EntryKind :: ForeignFn ( self . lazy( data) )
1566
1560
}
@@ -1576,6 +1570,7 @@ impl EncodeContext<'tcx> {
1576
1570
self . encode_deprecation ( def_id) ;
1577
1571
self . encode_item_type ( def_id) ;
1578
1572
if let hir:: ForeignItemKind :: Fn ( ..) = nitem. kind {
1573
+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1579
1574
self . encode_variances_of ( def_id) ;
1580
1575
}
1581
1576
self . encode_generics ( def_id) ;
0 commit comments