@@ -758,8 +758,6 @@ impl EncodeContext<'a, 'tcx> {
758
758
self . encode_generics ( def_id) ;
759
759
self . encode_explicit_predicates ( def_id) ;
760
760
self . encode_inferred_outlives ( def_id) ;
761
- self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
762
- self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
763
761
}
764
762
765
763
fn encode_enum_variant_ctor ( & mut self , def : & ty:: AdtDef , index : VariantIdx ) {
@@ -789,6 +787,7 @@ impl EncodeContext<'a, 'tcx> {
789
787
self . encode_generics ( def_id) ;
790
788
self . encode_explicit_predicates ( def_id) ;
791
789
self . encode_inferred_outlives ( def_id) ;
790
+ self . encode_mir_for_ctfe ( def_id. expect_local ( ) ) ;
792
791
self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
793
792
self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
794
793
}
@@ -897,6 +896,7 @@ impl EncodeContext<'a, 'tcx> {
897
896
self . encode_explicit_predicates ( def_id) ;
898
897
self . encode_inferred_outlives ( def_id) ;
899
898
self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
899
+ self . encode_mir_for_ctfe ( def_id. expect_local ( ) ) ;
900
900
self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
901
901
}
902
902
@@ -1015,8 +1015,21 @@ impl EncodeContext<'a, 'tcx> {
1015
1015
self . encode_inferred_outlives ( def_id) ;
1016
1016
1017
1017
// This should be kept in sync with `PrefetchVisitor.visit_trait_item`.
1018
- self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
1019
- self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
1018
+ match trait_item. kind {
1019
+ ty:: AssocKind :: Type => { }
1020
+ ty:: AssocKind :: Const => {
1021
+ if self . tcx . mir_keys ( LOCAL_CRATE ) . contains ( & def_id. expect_local ( ) ) {
1022
+ self . encode_mir_for_ctfe ( def_id. expect_local ( ) ) ;
1023
+ self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
1024
+ }
1025
+ }
1026
+ ty:: AssocKind :: Fn => {
1027
+ if self . tcx . mir_keys ( LOCAL_CRATE ) . contains ( & def_id. expect_local ( ) ) {
1028
+ self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
1029
+ self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
1030
+ }
1031
+ }
1032
+ }
1020
1033
}
1021
1034
1022
1035
fn metadata_output_only ( & self ) -> bool {
@@ -1089,23 +1102,28 @@ impl EncodeContext<'a, 'tcx> {
1089
1102
1090
1103
// The following part should be kept in sync with `PrefetchVisitor.visit_impl_item`.
1091
1104
1092
- let mir = match ast_item. kind {
1093
- hir:: ImplItemKind :: Const ( ..) => true ,
1105
+ let ( mir, mir_const ) = match ast_item. kind {
1106
+ hir:: ImplItemKind :: Const ( ..) => ( false , true ) ,
1094
1107
hir:: ImplItemKind :: Fn ( ref sig, _) => {
1095
1108
let generics = self . tcx . generics_of ( def_id) ;
1096
1109
let needs_inline = ( generics. requires_monomorphization ( self . tcx )
1097
1110
|| tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) )
1098
1111
&& !self . metadata_output_only ( ) ;
1099
1112
let is_const_fn = sig. header . constness == hir:: Constness :: Const ;
1100
1113
let always_encode_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir ;
1101
- needs_inline || is_const_fn || always_encode_mir
1114
+ ( needs_inline || always_encode_mir, is_const_fn )
1102
1115
}
1103
- hir:: ImplItemKind :: TyAlias ( ..) => false ,
1116
+ hir:: ImplItemKind :: TyAlias ( ..) => ( false , false ) ,
1104
1117
} ;
1105
1118
if mir {
1106
1119
self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
1120
+ }
1121
+ if mir || mir_const {
1107
1122
self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
1108
1123
}
1124
+ if mir_const {
1125
+ self . encode_mir_for_ctfe ( def_id. expect_local ( ) ) ;
1126
+ }
1109
1127
}
1110
1128
1111
1129
fn encode_fn_param_names_for_body ( & mut self , body_id : hir:: BodyId ) -> Lazy < [ Ident ] > {
@@ -1116,28 +1134,34 @@ impl EncodeContext<'a, 'tcx> {
1116
1134
self . lazy ( param_names. iter ( ) )
1117
1135
}
1118
1136
1119
- fn encode_optimized_mir ( & mut self , def_id : LocalDefId ) {
1120
- debug ! ( "EntryBuilder::encode_mir({:?})" , def_id) ;
1121
- if self . tcx . mir_keys ( LOCAL_CRATE ) . contains ( & def_id) {
1122
- record ! ( self . tables. mir[ def_id. to_def_id( ) ] <- self . tcx. optimized_mir( def_id) ) ;
1137
+ fn encode_mir_for_ctfe ( & mut self , def_id : LocalDefId ) {
1138
+ debug ! ( "EntryBuilder::encode_mir_for_ctfe({:?})" , def_id) ;
1139
+ record ! ( self . tables. mir_for_ctfe[ def_id. to_def_id( ) ] <- self . tcx. mir_for_ctfe( def_id) ) ;
1123
1140
1124
- let unused = self . tcx . unused_generic_params ( def_id) ;
1125
- if !unused. is_empty ( ) {
1126
- record ! ( self . tables. unused_generic_params[ def_id. to_def_id( ) ] <- unused) ;
1127
- }
1141
+ let unused = self . tcx . unused_generic_params ( def_id) ;
1142
+ if !unused. is_empty ( ) {
1143
+ record ! ( self . tables. unused_generic_params[ def_id. to_def_id( ) ] <- unused) ;
1144
+ }
1128
1145
1129
- let abstract_const = self . tcx . mir_abstract_const ( def_id) ;
1130
- if let Ok ( Some ( abstract_const) ) = abstract_const {
1131
- record ! ( self . tables. mir_abstract_consts[ def_id. to_def_id( ) ] <- abstract_const) ;
1132
- }
1146
+ let abstract_const = self . tcx . mir_abstract_const ( def_id) ;
1147
+ if let Ok ( Some ( abstract_const) ) = abstract_const {
1148
+ record ! ( self . tables. mir_abstract_consts[ def_id. to_def_id( ) ] <- abstract_const) ;
1149
+ }
1150
+ }
1151
+
1152
+ fn encode_optimized_mir ( & mut self , def_id : LocalDefId ) {
1153
+ debug ! ( "EntryBuilder::encode_optimized_mir({:?})" , def_id) ;
1154
+ record ! ( self . tables. mir[ def_id. to_def_id( ) ] <- self . tcx. optimized_mir( def_id) ) ;
1155
+
1156
+ let unused = self . tcx . unused_generic_params ( def_id) ;
1157
+ if !unused. is_empty ( ) {
1158
+ record ! ( self . tables. unused_generic_params[ def_id. to_def_id( ) ] <- unused) ;
1133
1159
}
1134
1160
}
1135
1161
1136
1162
fn encode_promoted_mir ( & mut self , def_id : LocalDefId ) {
1137
1163
debug ! ( "EncodeContext::encode_promoted_mir({:?})" , def_id) ;
1138
- if self . tcx . mir_keys ( LOCAL_CRATE ) . contains ( & def_id) {
1139
- record ! ( self . tables. promoted_mir[ def_id. to_def_id( ) ] <- self . tcx. promoted_mir( def_id) ) ;
1140
- }
1164
+ record ! ( self . tables. promoted_mir[ def_id. to_def_id( ) ] <- self . tcx. promoted_mir( def_id) ) ;
1141
1165
}
1142
1166
1143
1167
// Encodes the inherent implementations of a structure, enumeration, or trait.
@@ -1406,22 +1430,31 @@ impl EncodeContext<'a, 'tcx> {
1406
1430
1407
1431
// The following part should be kept in sync with `PrefetchVisitor.visit_item`.
1408
1432
1409
- let mir = match item. kind {
1410
- hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => true ,
1433
+ let ( mir, const_mir ) = match item. kind {
1434
+ hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => ( false , true ) ,
1411
1435
hir:: ItemKind :: Fn ( ref sig, ..) => {
1412
1436
let generics = tcx. generics_of ( def_id) ;
1413
1437
let needs_inline = ( generics. requires_monomorphization ( tcx)
1414
1438
|| tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) )
1415
1439
&& !self . metadata_output_only ( ) ;
1440
+
1441
+ let is_const_fn = sig. header . constness == hir:: Constness :: Const ;
1416
1442
let always_encode_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir ;
1417
- needs_inline || sig. header . constness == hir:: Constness :: Const || always_encode_mir
1443
+ let mir = needs_inline || always_encode_mir;
1444
+ // We don't need the optimized MIR for const fns.
1445
+ ( mir, is_const_fn)
1418
1446
}
1419
- _ => false ,
1447
+ _ => ( false , false ) ,
1420
1448
} ;
1421
1449
if mir {
1422
1450
self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
1451
+ }
1452
+ if mir || const_mir {
1423
1453
self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
1424
1454
}
1455
+ if const_mir {
1456
+ self . encode_mir_for_ctfe ( def_id. expect_local ( ) ) ;
1457
+ }
1425
1458
}
1426
1459
1427
1460
/// Serialize the text of exported macros
@@ -1486,7 +1519,7 @@ impl EncodeContext<'a, 'tcx> {
1486
1519
self . encode_generics ( def_id. to_def_id ( ) ) ;
1487
1520
self . encode_explicit_predicates ( def_id. to_def_id ( ) ) ;
1488
1521
self . encode_inferred_outlives ( def_id. to_def_id ( ) ) ;
1489
- self . encode_optimized_mir ( def_id) ;
1522
+ self . encode_mir_for_ctfe ( def_id) ;
1490
1523
self . encode_promoted_mir ( def_id) ;
1491
1524
}
1492
1525
@@ -1951,6 +1984,12 @@ struct PrefetchVisitor<'tcx> {
1951
1984
}
1952
1985
1953
1986
impl < ' tcx > PrefetchVisitor < ' tcx > {
1987
+ fn prefetch_ctfe_mir ( & self , def_id : LocalDefId ) {
1988
+ if self . mir_keys . contains ( & def_id) {
1989
+ self . tcx . ensure ( ) . mir_for_ctfe ( def_id) ;
1990
+ self . tcx . ensure ( ) . promoted_mir ( def_id) ;
1991
+ }
1992
+ }
1954
1993
fn prefetch_mir ( & self , def_id : LocalDefId ) {
1955
1994
if self . mir_keys . contains ( & def_id) {
1956
1995
self . tcx . ensure ( ) . optimized_mir ( def_id) ;
@@ -1965,42 +2004,57 @@ impl<'tcx, 'v> ParItemLikeVisitor<'v> for PrefetchVisitor<'tcx> {
1965
2004
let tcx = self . tcx ;
1966
2005
match item. kind {
1967
2006
hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => {
1968
- self . prefetch_mir ( tcx. hir ( ) . local_def_id ( item. hir_id ) )
2007
+ self . prefetch_ctfe_mir ( tcx. hir ( ) . local_def_id ( item. hir_id ) )
1969
2008
}
1970
2009
hir:: ItemKind :: Fn ( ref sig, ..) => {
1971
2010
let def_id = tcx. hir ( ) . local_def_id ( item. hir_id ) ;
1972
2011
let generics = tcx. generics_of ( def_id. to_def_id ( ) ) ;
1973
2012
let needs_inline = generics. requires_monomorphization ( tcx)
1974
2013
|| tcx. codegen_fn_attrs ( def_id. to_def_id ( ) ) . requests_inline ( ) ;
1975
- if needs_inline || sig . header . constness == hir :: Constness :: Const {
2014
+ if needs_inline {
1976
2015
self . prefetch_mir ( def_id)
1977
2016
}
2017
+ if sig. header . constness == hir:: Constness :: Const {
2018
+ self . prefetch_ctfe_mir ( def_id) ;
2019
+ }
1978
2020
}
1979
2021
_ => ( ) ,
1980
2022
}
1981
2023
}
1982
2024
1983
2025
fn visit_trait_item ( & self , trait_item : & ' v hir:: TraitItem < ' v > ) {
1984
2026
// This should be kept in sync with `encode_info_for_trait_item`.
1985
- self . prefetch_mir ( self . tcx . hir ( ) . local_def_id ( trait_item. hir_id ) ) ;
2027
+ let def_id = self . tcx . hir ( ) . local_def_id ( trait_item. hir_id ) ;
2028
+ match trait_item. kind {
2029
+ hir:: TraitItemKind :: Type ( ..) => { }
2030
+ hir:: TraitItemKind :: Const ( ..) => {
2031
+ self . prefetch_ctfe_mir ( def_id) ;
2032
+ }
2033
+ hir:: TraitItemKind :: Fn ( ..) => {
2034
+ self . prefetch_mir ( def_id) ;
2035
+ }
2036
+ }
1986
2037
}
1987
2038
1988
2039
fn visit_impl_item ( & self , impl_item : & ' v hir:: ImplItem < ' v > ) {
1989
2040
// This should be kept in sync with `encode_info_for_impl_item`.
1990
2041
let tcx = self . tcx ;
1991
2042
match impl_item. kind {
1992
2043
hir:: ImplItemKind :: Const ( ..) => {
1993
- self . prefetch_mir ( tcx. hir ( ) . local_def_id ( impl_item. hir_id ) )
2044
+ self . prefetch_ctfe_mir ( tcx. hir ( ) . local_def_id ( impl_item. hir_id ) )
1994
2045
}
1995
2046
hir:: ImplItemKind :: Fn ( ref sig, _) => {
1996
2047
let def_id = tcx. hir ( ) . local_def_id ( impl_item. hir_id ) ;
1997
2048
let generics = tcx. generics_of ( def_id. to_def_id ( ) ) ;
1998
2049
let needs_inline = generics. requires_monomorphization ( tcx)
1999
2050
|| tcx. codegen_fn_attrs ( def_id. to_def_id ( ) ) . requests_inline ( ) ;
2000
2051
let is_const_fn = sig. header . constness == hir:: Constness :: Const ;
2001
- if needs_inline || is_const_fn {
2052
+ if needs_inline {
2002
2053
self . prefetch_mir ( def_id)
2003
2054
}
2055
+ if is_const_fn {
2056
+ self . prefetch_ctfe_mir ( def_id) ;
2057
+ }
2004
2058
}
2005
2059
hir:: ImplItemKind :: TyAlias ( ..) => ( ) ,
2006
2060
}
0 commit comments