Skip to content

Commit b316384

Browse files
Use new PromoteTemps for promotion
1 parent 170272b commit b316384

File tree

3 files changed

+27
-48
lines changed

3 files changed

+27
-48
lines changed

src/librustc_mir/transform/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ fn mir_validated(
210210
}
211211

212212
let mut body = tcx.mir_const(def_id).steal();
213-
let qualify_and_promote_pass = qualify_consts::QualifyAndPromoteConstants::default();
213+
let promote_pass = promote_consts::PromoteTemps::default();
214214
run_passes(tcx, &mut body, InstanceDef::Item(def_id), None, MirPhase::Validated, &[
215215
// What we need to run borrowck etc.
216-
&qualify_and_promote_pass,
216+
&qualify_consts::QualifyAndPromoteConstants::default(),
217+
&promote_pass,
217218
&simplify::SimplifyCfg::new("qualify-consts"),
218219
]);
219-
let promoted = qualify_and_promote_pass.promoted.into_inner();
220+
let promoted = promote_pass.promoted_fragments.into_inner();
220221
(tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted))
221222
}
222223

src/librustc_mir/transform/qualify_consts.rs

+17-39
Original file line numberDiff line numberDiff line change
@@ -1345,56 +1345,34 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
13451345
let mode = determine_mode(tcx, hir_id, def_id);
13461346

13471347
debug!("run_pass: mode={:?}", mode);
1348-
if let Mode::NonConstFn | Mode::ConstFn = mode {
1348+
if let Mode::NonConstFn = mode {
1349+
// No need to const-check a non-const `fn` now that we don't do promotion here.
1350+
return;
1351+
} else if let Mode::ConstFn = mode {
13491352
let mut checker = Checker::new(tcx, def_id, body, mode);
1350-
if let Mode::ConstFn = mode {
1351-
let use_min_const_fn_checks =
1352-
!tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you &&
1353-
tcx.is_min_const_fn(def_id);
1354-
if use_min_const_fn_checks {
1355-
// Enforce `min_const_fn` for stable `const fn`s.
1356-
use super::qualify_min_const_fn::is_min_const_fn;
1357-
if let Err((span, err)) = is_min_const_fn(tcx, def_id, body) {
1358-
error_min_const_fn_violation(tcx, span, err);
1359-
return;
1360-
}
1361-
1362-
// `check_const` should not produce any errors, but better safe than sorry
1363-
// FIXME(#53819)
1364-
// NOTE(eddyb) `check_const` is actually needed for promotion inside
1365-
// `min_const_fn` functions.
1366-
}
1367-
1368-
// Enforce a constant-like CFG for `const fn`.
1369-
checker.check_const();
1370-
} else {
1371-
while let Some((bb, data)) = checker.rpo.next() {
1372-
checker.visit_basic_block_data(bb, data);
1353+
let use_min_const_fn_checks =
1354+
!tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you &&
1355+
tcx.is_min_const_fn(def_id);
1356+
if use_min_const_fn_checks {
1357+
// Enforce `min_const_fn` for stable `const fn`s.
1358+
use super::qualify_min_const_fn::is_min_const_fn;
1359+
if let Err((span, err)) = is_min_const_fn(tcx, def_id, body) {
1360+
error_min_const_fn_violation(tcx, span, err);
1361+
return;
13731362
}
13741363
}
13751364

1376-
// Promote only the promotable candidates.
1377-
let temps = checker.temp_promotion_state;
1378-
let candidates = promote_consts::validate_candidates(
1379-
tcx,
1380-
body,
1381-
def_id,
1382-
&temps,
1383-
&checker.unchecked_promotion_candidates,
1384-
);
1385-
1386-
// Do the actual promotion, now that we know what's viable.
1387-
self.promoted.set(
1388-
promote_consts::promote_candidates(def_id, body, tcx, temps, candidates)
1389-
);
1365+
// `check_const` should not produce any errors, but better safe than sorry
1366+
// FIXME(#53819)
1367+
// Enforce a constant-like CFG for `const fn`.
1368+
checker.check_const();
13901369
} else {
13911370
check_short_circuiting_in_const_local(tcx, body, mode);
13921371

13931372
match mode {
13941373
Mode::Const => tcx.mir_const_qualif(def_id),
13951374
_ => Checker::new(tcx, def_id, body, mode).check_const(),
13961375
};
1397-
remove_drop_and_storage_dead_on_promoted_locals(body, unimplemented!());
13981376
}
13991377

14001378
if mode == Mode::Static && !tcx.has_attr(def_id, sym::thread_local) {

src/test/mir-opt/match_false_edges.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() {
3939

4040
// END RUST SOURCE
4141
//
42-
// START rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
42+
// START rustc.full_tested_match.PromoteTemps.after.mir
4343
// bb0: {
4444
// ...
4545
// _2 = std::option::Option::<i32>::Some(const 42i32,);
@@ -108,9 +108,9 @@ fn main() {
108108
// _0 = ();
109109
// return;
110110
// }
111-
// END rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
111+
// END rustc.full_tested_match.PromoteTemps.after.mir
112112
//
113-
// START rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
113+
// START rustc.full_tested_match2.PromoteTemps.before.mir
114114
// bb0: {
115115
// ...
116116
// _2 = std::option::Option::<i32>::Some(const 42i32,);
@@ -179,9 +179,9 @@ fn main() {
179179
// _0 = ();
180180
// return;
181181
// }
182-
// END rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
182+
// END rustc.full_tested_match2.PromoteTemps.before.mir
183183
//
184-
// START rustc.main.QualifyAndPromoteConstants.before.mir
184+
// START rustc.main.PromoteTemps.before.mir
185185
// bb0: {
186186
// ...
187187
// _2 = std::option::Option::<i32>::Some(const 1i32,);
@@ -276,4 +276,4 @@ fn main() {
276276
// _0 = ();
277277
// return;
278278
// }
279-
// END rustc.main.QualifyAndPromoteConstants.before.mir
279+
// END rustc.main.PromoteTemps.before.mir

0 commit comments

Comments
 (0)