Skip to content

Commit

Permalink
Rollup merge of rust-lang#108786 - saethlin:free-regions-check, r=oli…
Browse files Browse the repository at this point in the history
…-obk

Check for free regions in MIR validation

This turns rust-lang#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();
   |             ^^^^
```
  • Loading branch information
matthiaskrgr authored Mar 6, 2023
2 parents f617ee3 + cb4ebc1 commit 773a533
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 11 additions & 0 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ impl<'tcx> MirPass<'tcx> for Validator {
};
checker.visit_body(body);
checker.check_cleanup_control_flow();

if let MirPhase::Runtime(_) = body.phase {
if let ty::InstanceDef::Item(_) = body.source.instance {
if body.has_free_regions() {
checker.fail(
Location::START,
format!("Free regions in optimized {} MIR", body.phase.name()),
);
}
}
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,6 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -

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

debug_assert!(!body.has_free_regions(), "Free regions in MIR for CTFE");

body
}

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

debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");

body
}

Expand All @@ -651,7 +647,5 @@ fn promoted_mir(
run_analysis_to_runtime_passes(tcx, body);
}

debug_assert!(!promoted.has_free_regions(), "Free regions in promoted MIR");

tcx.arena.alloc(promoted)
}

0 comments on commit 773a533

Please sign in to comment.