Skip to content

Commit

Permalink
filter required_consts during inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 23, 2024
1 parent 173d1bd commit 8436045
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8436045

Please sign in to comment.