Skip to content

Commit 2f88ecd

Browse files
committed
inliner: absorb callees required_items
1 parent 70612b7 commit 2f88ecd

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

compiler/rustc_middle/src/mir/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ impl<'tcx> CoroutineInfo<'tcx> {
311311
}
312312

313313
/// Some item that needs to monomorphize successfully for a MIR body to be considered well-formed.
314-
#[derive(Copy, Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)]
314+
#[derive(Copy, Clone, PartialEq, Debug, HashStable, TyEncodable, TyDecodable)]
315+
#[derive(TypeFoldable, TypeVisitable)]
315316
pub enum RequiredItem<'tcx> {
316317
Fn(DefId, GenericArgsRef<'tcx>),
317318
Drop(Ty<'tcx>),

compiler/rustc_mir_transform/src/inline.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ impl<'tcx> Inliner<'tcx> {
565565
mut callee_body: Body<'tcx>,
566566
) {
567567
let terminator = caller_body[callsite.block].terminator.take().unwrap();
568-
let TerminatorKind::Call { args, destination, unwind, target, .. } = terminator.kind else {
568+
let TerminatorKind::Call { func, args, destination, unwind, target, .. } = terminator.kind
569+
else {
569570
bug!("unexpected terminator kind {:?}", terminator.kind);
570571
};
571572

@@ -717,6 +718,18 @@ impl<'tcx> Inliner<'tcx> {
717718
Const::Val(..) | Const::Unevaluated(..) => true,
718719
},
719720
));
721+
// Now that we incorporated the callee's `required_consts`, we can remove the callee from
722+
// `required_items` -- but we have to take their `required_consts` in return.
723+
let callee_item = {
724+
// We need to reconstruct the `required_item` for the callee.
725+
let func_ty = func.ty(caller_body, self.tcx);
726+
match func_ty.kind() {
727+
ty::FnDef(def_id, args) => RequiredItem::Fn(*def_id, args),
728+
_ => bug!(),
729+
}
730+
};
731+
caller_body.required_items.retain(|item| *item != callee_item);
732+
caller_body.required_items.extend(callee_body.required_items);
720733
}
721734

722735
fn make_call_args(

compiler/rustc_monomorphize/src/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ fn visit_instance_use<'tcx>(
983983
source: Span,
984984
output: &mut MonoItems<'tcx>,
985985
) {
986-
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
986+
debug!("visit_instance_use({:?}, is_direct_call={:?})", instance, is_direct_call);
987987
if !should_codegen_locally(tcx, &instance) {
988988
return;
989989
}

0 commit comments

Comments
 (0)