Skip to content

Commit

Permalink
Auto merge of #114459 - cjgillot:simplify-ctfe, r=oli-obk
Browse files Browse the repository at this point in the history
Do not run ConstProp on mir_for_ctfe.

This pass does not seem to be useful any more. The const-prop lints are now run by `tcx.mir_drops_elaborated_and_const_checked`, and the const-prop opt should never emit any diagnostic.
  • Loading branch information
bors committed Aug 5, 2023
2 parents 67626b8 + e223098 commit 1cabb8e
Showing 1 changed file with 0 additions and 29 deletions.
29 changes: 0 additions & 29 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,38 +338,9 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
return shim::build_adt_ctor(tcx, def.to_def_id());
}

let context = tcx
.hir()
.body_const_context(def)
.expect("mir_for_ctfe should not be used for runtime functions");

let body = tcx.mir_drops_elaborated_and_const_checked(def).borrow().clone();

let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::Const);

match context {
// Do not const prop functions, either they get executed at runtime or exported to metadata,
// so we run const prop on them, or they don't, in which case we const evaluate some control
// flow paths of the function and any errors in those paths will get emitted as const eval
// errors.
hir::ConstContext::ConstFn => {}
// Static items always get evaluated, so we can just let const eval see if any erroneous
// control flow paths get executed.
hir::ConstContext::Static(_) => {}
// Associated constants get const prop run so we detect common failure situations in the
// crate that defined the constant.
// Technically we want to not run on regular const items, but oli-obk doesn't know how to
// conveniently detect that at this point without looking at the HIR.
hir::ConstContext::Const => {
pm::run_passes(
tcx,
&mut body,
&[&const_prop::ConstProp],
Some(MirPhase::Runtime(RuntimePhase::Optimized)),
);
}
}

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

body
Expand Down

0 comments on commit 1cabb8e

Please sign in to comment.