@@ -8,6 +8,7 @@ use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LocalDefId,
88use rustc:: hir:: GenericParamKind ;
99use rustc:: hir:: map:: definitions:: DefPathTable ;
1010use rustc_data_structures:: fingerprint:: Fingerprint ;
11+ use rustc_data_structures:: indexed_vec:: IndexVec ;
1112use rustc:: middle:: dependency_format:: Linkage ;
1213use rustc:: middle:: exported_symbols:: { ExportedSymbol , SymbolExportLevel ,
1314 metadata_symbol_name} ;
@@ -623,6 +624,7 @@ impl EncodeContext<'tcx> {
623624 predicates_defined_on : None ,
624625
625626 mir : self . encode_optimized_mir ( def_id) ,
627+ promoted_mir : self . encode_promoted_mir ( def_id) ,
626628 }
627629 }
628630
@@ -677,6 +679,7 @@ impl EncodeContext<'tcx> {
677679 predicates_defined_on : None ,
678680
679681 mir : self . encode_optimized_mir ( def_id) ,
682+ promoted_mir : self . encode_promoted_mir ( def_id) ,
680683 }
681684 }
682685
@@ -713,7 +716,8 @@ impl EncodeContext<'tcx> {
713716 predicates : None ,
714717 predicates_defined_on : None ,
715718
716- mir : None
719+ mir : None ,
720+ promoted_mir : None ,
717721 }
718722 }
719723
@@ -748,6 +752,7 @@ impl EncodeContext<'tcx> {
748752 predicates_defined_on : None ,
749753
750754 mir : None ,
755+ promoted_mir : None ,
751756 }
752757 }
753758
@@ -808,6 +813,7 @@ impl EncodeContext<'tcx> {
808813 predicates_defined_on : None ,
809814
810815 mir : self . encode_optimized_mir ( def_id) ,
816+ promoted_mir : self . encode_promoted_mir ( def_id) ,
811817 }
812818 }
813819
@@ -923,6 +929,7 @@ impl EncodeContext<'tcx> {
923929 predicates_defined_on : None ,
924930
925931 mir : self . encode_optimized_mir ( def_id) ,
932+ promoted_mir : self . encode_promoted_mir ( def_id) ,
926933 }
927934 }
928935
@@ -1022,6 +1029,7 @@ impl EncodeContext<'tcx> {
10221029 predicates_defined_on : None ,
10231030
10241031 mir : if mir { self . encode_optimized_mir ( def_id) } else { None } ,
1032+ promoted_mir : if mir { self . encode_promoted_mir ( def_id) } else { None } ,
10251033 }
10261034 }
10271035
@@ -1052,6 +1060,16 @@ impl EncodeContext<'tcx> {
10521060 }
10531061 }
10541062
1063+ fn encode_promoted_mir ( & mut self , def_id : DefId ) -> Option < Lazy < IndexVec < mir:: Promoted , mir:: Body < ' tcx > > > > {
1064+ debug ! ( "EncodeContext::encode_promoted_mir({:?})" , def_id) ;
1065+ if self . tcx . mir_keys ( LOCAL_CRATE ) . contains ( & def_id) {
1066+ let promoted = self . tcx . promoted_mir ( def_id) ;
1067+ Some ( self . lazy ( promoted) )
1068+ } else {
1069+ None
1070+ }
1071+ }
1072+
10551073 // Encodes the inherent implementations of a structure, enumeration, or trait.
10561074 fn encode_inherent_implementations ( & mut self , def_id : DefId ) -> Lazy < [ DefIndex ] > {
10571075 debug ! ( "EncodeContext::encode_inherent_implementations({:?})" , def_id) ;
@@ -1202,6 +1220,20 @@ impl EncodeContext<'tcx> {
12021220 hir:: ItemKind :: Use ( ..) => bug ! ( "cannot encode info for item {:?}" , item) ,
12031221 } ;
12041222
1223+ let mir = match item. node {
1224+ hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => true ,
1225+ hir:: ItemKind :: Fn ( _, header, ..) => {
1226+ let generics = tcx. generics_of ( def_id) ;
1227+ let needs_inline =
1228+ ( generics. requires_monomorphization ( tcx) ||
1229+ tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) ) &&
1230+ !self . metadata_output_only ( ) ;
1231+ let always_encode_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir ;
1232+ needs_inline || header. constness == hir:: Constness :: Const || always_encode_mir
1233+ }
1234+ _ => false ,
1235+ } ;
1236+
12051237 Entry {
12061238 kind,
12071239 visibility : self . lazy ( ty:: Visibility :: from_hir ( & item. vis , item. hir_id , tcx) ) ,
@@ -1301,29 +1333,8 @@ impl EncodeContext<'tcx> {
13011333 _ => None , // not *wrong* for other kinds of items, but not needed
13021334 } ,
13031335
1304- mir : match item. node {
1305- hir:: ItemKind :: Static ( ..) => {
1306- self . encode_optimized_mir ( def_id)
1307- }
1308- hir:: ItemKind :: Const ( ..) => self . encode_optimized_mir ( def_id) ,
1309- hir:: ItemKind :: Fn ( _, header, ..) => {
1310- let generics = tcx. generics_of ( def_id) ;
1311- let needs_inline =
1312- ( generics. requires_monomorphization ( tcx) ||
1313- tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) ) &&
1314- !self . metadata_output_only ( ) ;
1315- let always_encode_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir ;
1316- if needs_inline
1317- || header. constness == hir:: Constness :: Const
1318- || always_encode_mir
1319- {
1320- self . encode_optimized_mir ( def_id)
1321- } else {
1322- None
1323- }
1324- }
1325- _ => None ,
1326- } ,
1336+ mir : if mir { self . encode_optimized_mir ( def_id) } else { None } ,
1337+ promoted_mir : if mir { self . encode_promoted_mir ( def_id) } else { None } ,
13271338 }
13281339 }
13291340
@@ -1350,6 +1361,7 @@ impl EncodeContext<'tcx> {
13501361 predicates : None ,
13511362 predicates_defined_on : None ,
13521363 mir : None ,
1364+ promoted_mir : None ,
13531365 }
13541366 }
13551367
@@ -1376,6 +1388,7 @@ impl EncodeContext<'tcx> {
13761388 predicates_defined_on : None ,
13771389
13781390 mir : None ,
1391+ promoted_mir : None ,
13791392 }
13801393 }
13811394
@@ -1436,6 +1449,7 @@ impl EncodeContext<'tcx> {
14361449 predicates_defined_on : None ,
14371450
14381451 mir : self . encode_optimized_mir ( def_id) ,
1452+ promoted_mir : self . encode_promoted_mir ( def_id) ,
14391453 }
14401454 }
14411455
@@ -1464,6 +1478,7 @@ impl EncodeContext<'tcx> {
14641478 predicates_defined_on : None ,
14651479
14661480 mir : self . encode_optimized_mir ( def_id) ,
1481+ promoted_mir : self . encode_promoted_mir ( def_id) ,
14671482 }
14681483 }
14691484
@@ -1675,6 +1690,7 @@ impl EncodeContext<'tcx> {
16751690 predicates_defined_on : None ,
16761691
16771692 mir : None ,
1693+ promoted_mir : None ,
16781694 }
16791695 }
16801696}
0 commit comments