@@ -71,6 +71,7 @@ struct PerDefTables<'tcx> {
7171 deprecation : PerDefTable < Lazy < attr:: Deprecation > > ,
7272
7373 ty : PerDefTable < Lazy < Ty < ' tcx > > > ,
74+ fn_sig : PerDefTable < Lazy < ty:: PolyFnSig < ' tcx > > > ,
7475 inherent_impls : PerDefTable < Lazy < [ DefIndex ] > > ,
7576 variances : PerDefTable < Lazy < [ ty:: Variance ] > > ,
7677 generics : PerDefTable < Lazy < ty:: Generics > > ,
@@ -509,6 +510,7 @@ impl<'tcx> EncodeContext<'tcx> {
509510 deprecation : self . per_def . deprecation . encode ( & mut self . opaque ) ,
510511
511512 ty : self . per_def . ty . encode ( & mut self . opaque ) ,
513+ fn_sig : self . per_def . fn_sig . encode ( & mut self . opaque ) ,
512514 inherent_impls : self . per_def . inherent_impls . encode ( & mut self . opaque ) ,
513515 variances : self . per_def . variances . encode ( & mut self . opaque ) ,
514516 generics : self . per_def . generics . encode ( & mut self . opaque ) ,
@@ -637,13 +639,7 @@ impl EncodeContext<'tcx> {
637639 let data = VariantData {
638640 ctor_kind : variant. ctor_kind ,
639641 discr : variant. discr ,
640- // FIXME(eddyb) deduplicate these with `encode_enum_variant_ctor`.
641642 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- } ,
647643 } ;
648644
649645 let enum_id = tcx. hir ( ) . as_local_hir_id ( enum_did) . unwrap ( ) ;
@@ -662,6 +658,11 @@ impl EncodeContext<'tcx> {
662658 self . encode_deprecation ( def_id) ;
663659 self . encode_item_type ( def_id) ;
664660 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?
665666 self . encode_variances_of ( def_id) ;
666667 }
667668 self . encode_generics ( def_id) ;
@@ -681,15 +682,11 @@ impl EncodeContext<'tcx> {
681682 let def_id = variant. ctor_def_id . unwrap ( ) ;
682683 debug ! ( "EncodeContext::encode_enum_variant_ctor({:?})" , def_id) ;
683684
685+ // FIXME(eddyb) encode only the `CtorKind` for constructors.
684686 let data = VariantData {
685687 ctor_kind : variant. ctor_kind ,
686688 discr : variant. discr ,
687689 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- }
693690 } ;
694691
695692 // Variant constructors have the same visibility as the parent enums, unless marked as
@@ -708,6 +705,7 @@ impl EncodeContext<'tcx> {
708705 self . encode_deprecation ( def_id) ;
709706 self . encode_item_type ( def_id) ;
710707 if variant. ctor_kind == CtorKind :: Fn {
708+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
711709 self . encode_variances_of ( def_id) ;
712710 }
713711 self . encode_generics ( def_id) ;
@@ -782,11 +780,6 @@ impl EncodeContext<'tcx> {
782780 ctor_kind : variant. ctor_kind ,
783781 discr : variant. discr ,
784782 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- }
790783 } ;
791784
792785 let struct_id = tcx. hir ( ) . as_local_hir_id ( adt_def_id) . unwrap ( ) ;
@@ -813,6 +806,7 @@ impl EncodeContext<'tcx> {
813806 self . encode_deprecation ( def_id) ;
814807 self . encode_item_type ( def_id) ;
815808 if variant. ctor_kind == CtorKind :: Fn {
809+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
816810 self . encode_variances_of ( def_id) ;
817811 }
818812 self . encode_generics ( def_id) ;
@@ -881,7 +875,6 @@ impl EncodeContext<'tcx> {
881875 asyncness: m_sig. header. asyncness,
882876 constness: hir:: Constness :: NotConst ,
883877 param_names,
884- sig: self . lazy( tcx. fn_sig( def_id) ) ,
885878 }
886879 } else {
887880 bug!( )
@@ -913,6 +906,7 @@ impl EncodeContext<'tcx> {
913906 ty:: AssocKind :: OpaqueTy => unreachable ! ( ) ,
914907 }
915908 if trait_item. kind == ty:: AssocKind :: Method {
909+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
916910 self . encode_variances_of ( def_id) ;
917911 }
918912 self . encode_generics ( def_id) ;
@@ -959,7 +953,6 @@ impl EncodeContext<'tcx> {
959953 asyncness: sig. header. asyncness,
960954 constness: sig. header. constness,
961955 param_names: self . encode_fn_param_names_for_body( body) ,
962- sig: self . lazy( tcx. fn_sig( def_id) ) ,
963956 }
964957 } else {
965958 bug!( )
@@ -980,6 +973,7 @@ impl EncodeContext<'tcx> {
980973 self . encode_deprecation ( def_id) ;
981974 self . encode_item_type ( def_id) ;
982975 if impl_item. kind == ty:: AssocKind :: Method {
976+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
983977 self . encode_variances_of ( def_id) ;
984978 }
985979 self . encode_generics ( def_id) ;
@@ -1088,7 +1082,6 @@ impl EncodeContext<'tcx> {
10881082 asyncness: header. asyncness,
10891083 constness: header. constness,
10901084 param_names: self . encode_fn_param_names_for_body( body) ,
1091- sig: self . lazy( tcx. fn_sig( def_id) ) ,
10921085 } ;
10931086
10941087 EntryKind :: Fn ( self . lazy( data) )
@@ -1116,7 +1109,6 @@ impl EncodeContext<'tcx> {
11161109 ctor_kind: variant. ctor_kind,
11171110 discr: variant. discr,
11181111 ctor,
1119- ctor_sig: None ,
11201112 } ) , adt_def. repr)
11211113 }
11221114 hir:: ItemKind :: Union ( ..) => {
@@ -1127,7 +1119,6 @@ impl EncodeContext<'tcx> {
11271119 ctor_kind: variant. ctor_kind,
11281120 discr: variant. discr,
11291121 ctor: None ,
1130- ctor_sig: None ,
11311122 } ) , adt_def. repr)
11321123 }
11331124 hir:: ItemKind :: Impl ( _, _, defaultness, ..) => {
@@ -1232,6 +1223,9 @@ impl EncodeContext<'tcx> {
12321223 hir:: ItemKind :: Impl ( ..) => self . encode_item_type ( def_id) ,
12331224 _ => { }
12341225 }
1226+ if let hir:: ItemKind :: Fn ( ..) = item. kind {
1227+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1228+ }
12351229 self . encode_inherent_implementations ( def_id) ;
12361230 match item. kind {
12371231 hir:: ItemKind :: Enum ( ..) |
@@ -1328,10 +1322,12 @@ impl EncodeContext<'tcx> {
13281322 fn encode_info_for_closure ( & mut self , def_id : DefId ) {
13291323 debug ! ( "EncodeContext::encode_info_for_closure({:?})" , def_id) ;
13301324
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.
13321327 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) ;
13331329
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 {
13351331 ty:: Generator ( def_id, ..) => {
13361332 let layout = self . tcx. generator_layout( def_id) ;
13371333 let data = GeneratorData {
@@ -1340,18 +1336,17 @@ impl EncodeContext<'tcx> {
13401336 EntryKind :: Generator ( self . lazy( data) )
13411337 }
13421338
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 ,
13481340
13491341 _ => bug!( "closure that is neither generator nor closure" ) ,
13501342 } ) ;
13511343 record ! ( self . per_def. visibility[ def_id] <- ty:: Visibility :: Public ) ;
13521344 record ! ( self . per_def. span[ def_id] <- self . tcx. def_span( def_id) ) ;
13531345 record ! ( self . per_def. attributes[ def_id] <- & self . tcx. get_attrs( def_id) [ ..] ) ;
13541346 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+ }
13551350 self . encode_generics ( def_id) ;
13561351 self . encode_optimized_mir ( def_id) ;
13571352 self . encode_promoted_mir ( def_id) ;
@@ -1560,7 +1555,6 @@ impl EncodeContext<'tcx> {
15601555 asyncness: hir:: IsAsync :: NotAsync ,
15611556 constness: hir:: Constness :: NotConst ,
15621557 param_names: self . encode_fn_param_names( names) ,
1563- sig: self . lazy( tcx. fn_sig( def_id) ) ,
15641558 } ;
15651559 EntryKind :: ForeignFn ( self . lazy( data) )
15661560 }
@@ -1576,6 +1570,7 @@ impl EncodeContext<'tcx> {
15761570 self . encode_deprecation ( def_id) ;
15771571 self . encode_item_type ( def_id) ;
15781572 if let hir:: ForeignItemKind :: Fn ( ..) = nitem. kind {
1573+ record ! ( self . per_def. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
15791574 self . encode_variances_of ( def_id) ;
15801575 }
15811576 self . encode_generics ( def_id) ;
0 commit comments