1
Fork 0

Create stable metric to measure long computation in Const Eval

This patch adds a `MirPass` that tracks the number of back-edges and
function calls in the CFG, adds a new MIR instruction to increment a
counter every time they are encountered during Const Eval, and emit a
warning if a configured limit is breached.
This commit is contained in:
Bryan Garza 2022-12-20 00:51:17 +00:00
parent c8e6a9e8b6
commit 360db516cc
37 changed files with 233 additions and 9 deletions

View file

@ -55,6 +55,7 @@ mod const_goto;
mod const_prop;
mod const_prop_lint;
mod coverage;
mod ctfe_limit;
mod dataflow_const_prop;
mod dead_store_elimination;
mod deaggregator;
@ -349,11 +350,14 @@ fn mir_promoted(
/// Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
fn mir_for_ctfe(tcx: TyCtxt<'_>, def_id: DefId) -> &Body<'_> {
let did = def_id.expect_local();
if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
let body = if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
tcx.mir_for_ctfe_of_const_arg(def)
} else {
tcx.arena.alloc(inner_mir_for_ctfe(tcx, ty::WithOptConstParam::unknown(did)))
}
};
//info!("MIR_FOR_CTFE (DefId = {def_id:?}) body res: {:#?}", body);
info!("MIR_FOR_CTFE (DefId = {def_id:?})");
body
}
/// Same as `mir_for_ctfe`, but used to get the MIR of a const generic parameter.
@ -447,6 +451,7 @@ fn mir_drops_elaborated_and_const_checked(
run_analysis_to_runtime_passes(tcx, &mut body);
//info!("MIR after runtime passes: {:#?}", body);
tcx.alloc_steal_mir(body)
}
@ -517,6 +522,7 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// CTFE support for aggregates.
&deaggregator::Deaggregator,
&Lint(const_prop_lint::ConstProp),
&ctfe_limit::CtfeLimit,
];
pm::run_passes_no_validate(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::Initial)));
}
@ -617,6 +623,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::NotConst);
debug!("body: {:#?}", body);
run_optimization_passes(tcx, &mut body);
//info!("body after OPTIMIZATION: {:#?}", body);
debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");