@@ -1122,18 +1122,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
11221122
11231123 sess. time ( "layout_testing" , || layout_test:: test_layout ( tcx) ) ;
11241124 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- }
11371125}
11381126
11391127/// Runs the type-checking, region checking and other miscellaneous analysis
@@ -1199,6 +1187,20 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
11991187 // we will fail to emit overlap diagnostics. Thus we invoke it here unconditionally.
12001188 let _ = tcx. all_diagnostic_items ( ( ) ) ;
12011189 } ) ;
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+ }
12021204}
12031205
12041206/// Runs the codegen backend, after which the AST and analysis can
0 commit comments