Skip to content

Commit 4bd6f7f

Browse files
authored
Rollup merge of #108786 - saethlin:free-regions-check, r=oli-obk
Check for free regions in MIR validation This turns #108720 into a MIR validation failure that will reproduce without debug-assertions enabled. ``` error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:296 ~ futures_util[3805]::future::future::remote_handle::{impl#3}::poll), const_param_did: None }) (after pass ScalarReplacementOfAggregates) at bb0[0]: Free regions in optimized runtime-post-cleanup MIR --> /home/ben/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.26/src/future/future/remote_handle.rs:96:13 | 96 | let this = self.project(); | ^^^^ ```
2 parents 1866ea1 + cb4ebc1 commit 4bd6f7f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+11
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ impl<'tcx> MirPass<'tcx> for Validator {
7272
};
7373
checker.visit_body(body);
7474
checker.check_cleanup_control_flow();
75+
76+
if let MirPhase::Runtime(_) = body.phase {
77+
if let ty::InstanceDef::Item(_) = body.source.instance {
78+
if body.has_free_regions() {
79+
checker.fail(
80+
Location::START,
81+
format!("Free regions in optimized {} MIR", body.phase.name()),
82+
);
83+
}
84+
}
85+
}
7586
}
7687
}
7788

compiler/rustc_mir_transform/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,6 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -
416416

417417
pm::run_passes(tcx, &mut body, &[&ctfe_limit::CtfeLimit], None);
418418

419-
debug_assert!(!body.has_free_regions(), "Free regions in MIR for CTFE");
420-
421419
body
422420
}
423421

@@ -626,8 +624,6 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
626624
debug!("body: {:#?}", body);
627625
run_optimization_passes(tcx, &mut body);
628626

629-
debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");
630-
631627
body
632628
}
633629

@@ -651,7 +647,5 @@ fn promoted_mir(
651647
run_analysis_to_runtime_passes(tcx, body);
652648
}
653649

654-
debug_assert!(!promoted.has_free_regions(), "Free regions in promoted MIR");
655-
656650
tcx.arena.alloc(promoted)
657651
}

0 commit comments

Comments
 (0)