Skip to content

Commit 5573c08

Browse files
committed
experiment: do not mess about with required_consts and mentioned_items in inliner
1 parent 30c5fee commit 5573c08

File tree

2 files changed

+7
-38
lines changed

2 files changed

+7
-38
lines changed

compiler/rustc_mir_transform/src/inline.rs

+1-38
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,7 @@ 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 { func, args, destination, unwind, target, .. } = terminator.kind
569-
else {
568+
let TerminatorKind::Call { args, destination, unwind, target, .. } = terminator.kind else {
570569
bug!("unexpected terminator kind {:?}", terminator.kind);
571570
};
572571

@@ -705,42 +704,6 @@ impl<'tcx> Inliner<'tcx> {
705704
source_info: callsite.source_info,
706705
kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) },
707706
});
708-
709-
// Copy only unevaluated constants from the callee_body into the caller_body.
710-
// Although we are only pushing `ConstKind::Unevaluated` consts to
711-
// `required_consts`, here we may not only have `ConstKind::Unevaluated`
712-
// because we are calling `instantiate_and_normalize_erasing_regions`.
713-
caller_body.required_consts.extend(callee_body.required_consts.iter().copied().filter(
714-
|&ct| match ct.const_ {
715-
Const::Ty(_) => {
716-
bug!("should never encounter ty::UnevaluatedConst in `required_consts`")
717-
}
718-
Const::Val(..) | Const::Unevaluated(..) => true,
719-
},
720-
));
721-
// Now that we incorporated the callee's `required_consts`, we can remove the callee from
722-
// `mentioned_items` -- but we have to take their `mentioned_items` in return.
723-
// This does some extra work here to save the monomorphization collector work later.
724-
// FIXME: benchmark which option is better.
725-
let callee_item = {
726-
// We need to reconstruct the `required_item` for the callee so that we can find and
727-
// remove it.
728-
let func_ty = func.ty(caller_body, self.tcx);
729-
match func_ty.kind() {
730-
ty::FnDef(def_id, args) => MentionedItem::Fn(*def_id, args),
731-
_ => bug!(),
732-
}
733-
};
734-
if let Some(idx) =
735-
caller_body.mentioned_items.iter().position(|item| item.node == callee_item)
736-
{
737-
// We found the callee, so remove it and add its items instead.
738-
caller_body.mentioned_items.remove(idx);
739-
caller_body.mentioned_items.extend(callee_body.mentioned_items);
740-
} else {
741-
// If we can't find the callee, there's no point in adding its items.
742-
// Probably it already got removed by being inlined elsewhere in the same function.
743-
}
744707
}
745708

746709
fn make_call_args(

tests/ui/inline-const/required-const.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ note: erroneous constant encountered
1212
LL | const { panic!() }
1313
| ^^^^^^^^^^^^^^^^^^
1414

15+
note: the above error was encountered while instantiating `fn foo::<i32>`
16+
--> $DIR/required-const.rs:12:5
17+
|
18+
LL | foo::<i32>();
19+
| ^^^^^^^^^^
20+
1521
error: aborting due to 1 previous error
1622

1723
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)