Skip to content

Commit ed9ca53

Browse files
committed
don't collect #[rustc_force_inline] in eager mode
1 parent 3bf2d20 commit ed9ca53

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

compiler/rustc_monomorphize/src/collector.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion};
225225
use rustc_middle::ty::layout::ValidityRequirement;
226226
use rustc_middle::ty::print::{shrunk_instance_name, with_no_trimmed_paths};
227227
use rustc_middle::ty::{
228-
self, GenericArgs, GenericParamDefKind, Instance, InstanceKind, Ty, TyCtxt, TypeFoldable,
229-
TypeVisitableExt, VtblEntry,
228+
self, GenericArgs, GenericParamDefKind, Instance, InstanceKind, Interner, Ty, TyCtxt,
229+
TypeFoldable, TypeVisitableExt, VtblEntry,
230230
};
231231
use rustc_middle::util::Providers;
232232
use rustc_middle::{bug, span_bug};
@@ -965,7 +965,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
965965
{
966966
// `#[rustc_force_inline]` items should never be codegened. This should be caught by
967967
// the MIR validator.
968-
return false;
968+
tcx.delay_bug("attempt to codegen `#[rustc_force_inline]` item");
969969
}
970970

971971
if def_id.is_local() {
@@ -1462,7 +1462,9 @@ impl<'v> RootCollector<'_, 'v> {
14621462
fn is_root(&self, def_id: LocalDefId) -> bool {
14631463
!self.tcx.generics_of(def_id).requires_monomorphization(self.tcx)
14641464
&& match self.strategy {
1465-
MonoItemCollectionStrategy::Eager => true,
1465+
MonoItemCollectionStrategy::Eager => {
1466+
!matches!(self.tcx.codegen_fn_attrs(def_id).inline, InlineAttr::Force { .. })
1467+
}
14661468
MonoItemCollectionStrategy::Lazy => {
14671469
self.entry_fn.and_then(|(id, _)| id.as_local()) == Some(def_id)
14681470
|| self.tcx.is_reachable_non_generic(def_id)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- // MIR for `caller` before ForceInline
2+
+ // MIR for `caller` after ForceInline
3+
4+
fn caller() -> () {
5+
let mut _0: ();
6+
let _1: ();
7+
+ scope 1 (inlined callee_forced) {
8+
+ }
9+
10+
bb0: {
11+
StorageLive(_1);
12+
- _1 = callee_forced() -> [return: bb1, unwind continue];
13+
- }
14+
-
15+
- bb1: {
16+
StorageDead(_1);
17+
_0 = const ();
18+
return;
19+
}
20+
}
21+
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// EMIT_MIT_FOR_EACH_PANIC_STRATEGY
2+
//@ compile-flags: -Copt-level=0 -Clink-dead-code
3+
#![feature(rustc_attrs)]
4+
5+
#[rustc_force_inline]
6+
pub fn callee_forced() {}
7+
8+
// EMIT_MIR forced_dead_code.caller.ForceInline.diff
9+
pub fn caller() {
10+
callee_forced();
11+
// CHECK-LABEL: fn caller(
12+
// CHECK: (inlined callee_forced)
13+
}
14+
15+
fn main() {
16+
caller();
17+
}

0 commit comments

Comments
 (0)