@@ -792,9 +792,12 @@ impl EncodeContext<'a, 'tcx> {
792
792
self . encode_generics ( def_id) ;
793
793
self . encode_explicit_predicates ( def_id) ;
794
794
self . encode_inferred_outlives ( def_id) ;
795
- self . encode_mir_for_ctfe ( def_id. expect_local ( ) ) ;
796
- self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
795
+ let opt_mir = tcx. sess . opts . debugging_opts . always_encode_mir || self . emit_codegen_mir ;
796
+ if opt_mir {
797
+ self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
798
+ }
797
799
self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
800
+ self . encode_mir_for_ctfe ( def_id. expect_local ( ) ) ;
798
801
}
799
802
800
803
fn encode_info_for_mod ( & mut self , id : hir:: HirId , md : & hir:: Mod < ' _ > , attrs : & [ ast:: Attribute ] ) {
@@ -900,7 +903,10 @@ impl EncodeContext<'a, 'tcx> {
900
903
self . encode_generics ( def_id) ;
901
904
self . encode_explicit_predicates ( def_id) ;
902
905
self . encode_inferred_outlives ( def_id) ;
903
- self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
906
+ let opt_mir = tcx. sess . opts . debugging_opts . always_encode_mir || self . emit_codegen_mir ;
907
+ if opt_mir {
908
+ self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
909
+ }
904
910
self . encode_mir_for_ctfe ( def_id. expect_local ( ) ) ;
905
911
self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
906
912
}
@@ -1029,14 +1035,25 @@ impl EncodeContext<'a, 'tcx> {
1029
1035
}
1030
1036
}
1031
1037
ty:: AssocKind :: Fn => {
1032
- if self . tcx . mir_keys ( LOCAL_CRATE ) . contains ( & def_id. expect_local ( ) ) {
1033
- self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
1034
- self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
1038
+ let opt_mir =
1039
+ tcx. sess . opts . debugging_opts . always_encode_mir || self . emit_codegen_mir ;
1040
+ if opt_mir {
1041
+ if self . tcx . mir_keys ( LOCAL_CRATE ) . contains ( & def_id. expect_local ( ) ) {
1042
+ self . encode_optimized_mir ( def_id. expect_local ( ) ) ;
1043
+ self . encode_promoted_mir ( def_id. expect_local ( ) ) ;
1044
+ }
1035
1045
}
1036
1046
}
1037
1047
}
1038
1048
}
1039
1049
1050
+ fn should_encode_fn_opt_mir ( & self , def_id : DefId ) -> bool {
1051
+ self . tcx . sess . opts . debugging_opts . always_encode_mir
1052
+ || ( self . emit_codegen_mir
1053
+ && ( self . tcx . generics_of ( def_id) . requires_monomorphization ( self . tcx )
1054
+ || self . tcx . codegen_fn_attrs ( def_id) . requests_inline ( ) ) )
1055
+ }
1056
+
1040
1057
fn encode_info_for_impl_item ( & mut self , def_id : DefId ) {
1041
1058
debug ! ( "EncodeContext::encode_info_for_impl_item({:?})" , def_id) ;
1042
1059
let tcx = self . tcx ;
@@ -1105,10 +1122,7 @@ impl EncodeContext<'a, 'tcx> {
1105
1122
let ( mir, mir_const) = match ast_item. kind {
1106
1123
hir:: ImplItemKind :: Const ( ..) => ( false , true ) ,
1107
1124
hir:: ImplItemKind :: Fn ( ref sig, _) => {
1108
- let opt_mir = tcx. sess . opts . debugging_opts . always_encode_mir
1109
- || ( self . emit_codegen_mir
1110
- && ( tcx. generics_of ( def_id) . requires_monomorphization ( tcx)
1111
- || tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) ) ) ;
1125
+ let opt_mir = self . should_encode_fn_opt_mir ( def_id) ;
1112
1126
let is_const_fn = sig. header . constness == hir:: Constness :: Const ;
1113
1127
( opt_mir, is_const_fn)
1114
1128
}
@@ -1432,10 +1446,7 @@ impl EncodeContext<'a, 'tcx> {
1432
1446
let ( mir, const_mir) = match item. kind {
1433
1447
hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => ( false , true ) ,
1434
1448
hir:: ItemKind :: Fn ( ref sig, ..) => {
1435
- let opt_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir
1436
- || ( self . emit_codegen_mir
1437
- && ( tcx. generics_of ( def_id) . requires_monomorphization ( tcx)
1438
- || tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) ) ) ;
1449
+ let opt_mir = self . should_encode_fn_opt_mir ( def_id) ;
1439
1450
let is_const_fn = sig. header . constness == hir:: Constness :: Const ;
1440
1451
// We don't need the optimized MIR for const fns.
1441
1452
( opt_mir, is_const_fn)
@@ -1498,8 +1509,11 @@ impl EncodeContext<'a, 'tcx> {
1498
1509
record ! ( self . tables. fn_sig[ def_id] <- substs. as_closure( ) . sig( ) ) ;
1499
1510
}
1500
1511
self . encode_generics ( def_id. to_def_id ( ) ) ;
1501
- self . encode_optimized_mir ( def_id) ;
1502
- self . encode_promoted_mir ( def_id) ;
1512
+ let opt_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir || self . emit_codegen_mir ;
1513
+ if opt_mir {
1514
+ self . encode_optimized_mir ( def_id) ;
1515
+ self . encode_promoted_mir ( def_id) ;
1516
+ }
1503
1517
}
1504
1518
1505
1519
fn encode_info_for_anon_const ( & mut self , def_id : LocalDefId ) {
0 commit comments