promotion: do not promote const-fn calls in const when that may fail without the entire const failing

This commit is contained in:
Ralf Jung 2024-02-24 17:16:05 +01:00
parent 40dcd796d0
commit 7183fa09bb
11 changed files with 198 additions and 252 deletions

View file

@ -333,13 +333,6 @@ fn mir_promoted(
body.tainted_by_errors = Some(error_reported);
}
let mut required_consts = Vec::new();
let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts);
for (bb, bb_data) in traversal::reverse_postorder(&body) {
required_consts_visitor.visit_basic_block_data(bb, bb_data);
}
body.required_consts = required_consts;
// What we need to run borrowck etc.
let promote_pass = promote_consts::PromoteTemps::default();
pm::run_passes(
@ -349,6 +342,14 @@ fn mir_promoted(
Some(MirPhase::Analysis(AnalysisPhase::Initial)),
);
// Promotion generates new consts; we run this after promotion to ensure they are accounted for.
let mut required_consts = Vec::new();
let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts);
for (bb, bb_data) in traversal::reverse_postorder(&body) {
required_consts_visitor.visit_basic_block_data(bb, bb_data);
}
body.required_consts = required_consts;
let promoted = promote_pass.promoted_fragments.into_inner();
(tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted))
}