filter required_consts during inlining

This commit is contained in:
Ralf Jung 2024-03-21 14:04:10 +01:00
parent 173d1bd36b
commit 8436045e24
2 changed files with 8 additions and 5 deletions

View File

@ -245,11 +245,10 @@ impl<'tcx> Const<'tcx> {
match self {
Const::Ty(c) => match c.kind() {
ty::ConstKind::Value(_) => false, // already a value, cannot error
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => true, // these are errors or could be replaced by errors
_ => bug!("is_required_const: unexpected ty::ConstKind {:#?}", c),
_ => true,
},
Const::Unevaluated(..) => true,
Const::Val(..) => false, // already a value, cannot error
Const::Unevaluated(..) => true,
}
}

View File

@ -720,8 +720,12 @@ impl<'tcx> Inliner<'tcx> {
kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) },
});
// Copy required constants from the callee_body into the caller_body.
caller_body.required_consts.extend(callee_body.required_consts);
// Copy required constants from the callee_body into the caller_body. Although we are only
// pushing unevaluated consts to `required_consts`, here they may have been evaluated
// because we are calling `instantiate_and_normalize_erasing_regions` -- so we filter again.
caller_body.required_consts.extend(
callee_body.required_consts.into_iter().filter(|ct| ct.const_.is_required_const()),
);
// Now that we incorporated the callee's `required_consts`, we can remove the callee from
// `mentioned_items` -- but we have to take their `mentioned_items` in return. This does
// some extra work here to save the monomorphization collector work later. It helps a lot,