@@ -1122,18 +1122,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
1122
1122
1123
1123
sess. time ( "layout_testing" , || layout_test:: test_layout ( tcx) ) ;
1124
1124
sess. time ( "abi_testing" , || abi_test:: test_abi ( tcx) ) ;
1125
-
1126
- // If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item
1127
- // (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs
1128
- // in MIR optimizations that may only be reachable through codegen, or other codepaths
1129
- // that requires the optimized/ctfe MIR, coroutine bodies, or evaluating consts.
1130
- if tcx. sess . opts . unstable_opts . validate_mir {
1131
- sess. time ( "ensuring_final_MIR_is_computable" , || {
1132
- tcx. par_hir_body_owners ( |def_id| {
1133
- tcx. instance_mir ( ty:: InstanceKind :: Item ( def_id. into ( ) ) ) ;
1134
- } ) ;
1135
- } ) ;
1136
- }
1137
1125
}
1138
1126
1139
1127
/// Runs the type-checking, region checking and other miscellaneous analysis
@@ -1199,6 +1187,20 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
1199
1187
// we will fail to emit overlap diagnostics. Thus we invoke it here unconditionally.
1200
1188
let _ = tcx. all_diagnostic_items ( ( ) ) ;
1201
1189
} ) ;
1190
+
1191
+ // If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item
1192
+ // (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs
1193
+ // in MIR optimizations that may only be reachable through codegen, or other codepaths
1194
+ // that requires the optimized/ctfe MIR, coroutine bodies, or evaluating consts.
1195
+ // Nevertheless, wait after type checking is finished, as optimizing code that does not
1196
+ // type-check is very prone to ICEs.
1197
+ if tcx. sess . opts . unstable_opts . validate_mir {
1198
+ sess. time ( "ensuring_final_MIR_is_computable" , || {
1199
+ tcx. par_hir_body_owners ( |def_id| {
1200
+ tcx. instance_mir ( ty:: InstanceKind :: Item ( def_id. into ( ) ) ) ;
1201
+ } ) ;
1202
+ } ) ;
1203
+ }
1202
1204
}
1203
1205
1204
1206
/// Runs the codegen backend, after which the AST and analysis can
0 commit comments