Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b154623

Browse files
committed
Include drops in mir_inliner_callees
1 parent 7d0ba2d commit b154623

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

‎compiler/rustc_mir_transform/src/inline/cycle.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
22
use rustc_data_structures::stack::ensure_sufficient_stack;
33
use rustc_hir::def_id::{DefId, LocalDefId};
4+
use rustc_hir::LangItem;
45
use rustc_middle::mir::TerminatorKind;
5-
use rustc_middle::ty::{self, GenericArgsRef, InstanceKind, TyCtxt, TypeVisitableExt};
6+
use rustc_middle::ty::{self, GenericArg,GenericArgsRef, InstanceKind, TyCtxt, TypeVisitableExt};
67
use rustc_session::Limit;
78
use rustc_span::sym;
89
use tracing::{instrument, trace};
@@ -191,6 +192,18 @@ pub(crate) fn mir_inliner_callees<'tcx>(
191192
};
192193
calls.insert(call);
193194
}
195+
// This query is called on *analysis* MIR, which doesn't have drops elaborated,
196+
// let alone any of the later runtime MIR optimizations.
197+
if let TerminatorKind::Drop { place, .. } = &terminator.kind {
198+
let dropped_ty = place.ty(&body.local_decls, tcx).ty;
199+
let param_env = tcx.param_env_reveal_all_normalized(instance.def_id());
200+
if dropped_ty.needs_drop(tcx, param_env) {
201+
let drop_in_place_fn =
202+
tcx.require_lang_item(LangItem::DropInPlace, Some(terminator.source_info.span));
203+
let args = tcx.mk_args(&[GenericArg::from(dropped_ty)]);
204+
calls.insert((drop_in_place_fn, args));
205+
}
206+
}
194207
}
195208
tcx.arena.alloc_from_iter(calls.iter().copied())
196209
}

‎tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
let mut _4: i32;
1010
let mut _5: !;
1111
let _6: !;
12-
+ scope 1 (inlined panic) {
13-
+ let mut _7: !;
12+
+ scope 1 (inlined calls_panic) {
13+
+ let _7: !;
1414
+ }
1515

1616
bb0: {
@@ -34,9 +34,9 @@
3434
bb2: {
3535
StorageDead(_3);
3636
StorageLive(_6);
37-
- _6 = panic() -> unwind unreachable;
37+
- _6 = calls_panic() -> unwind unreachable;
3838
+ StorageLive(_7);
39-
+ _7 = begin_panic::<&str>(const "explicit panic") -> unwind unreachable;
39+
+ _7 = panic_cold_explicit() -> unwind unreachable;
4040
}
4141
}
4242

‎tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
let mut _4: i32;
1010
let mut _5: !;
1111
let _6: !;
12-
+ scope 1 (inlined panic) {
13-
+ let mut _7: !;
12+
+ scope 1 (inlined calls_panic) {
13+
+ let _7: !;
1414
+ }
1515

1616
bb0: {
@@ -34,9 +34,9 @@
3434
bb2: {
3535
StorageDead(_3);
3636
StorageLive(_6);
37-
- _6 = panic() -> unwind continue;
37+
- _6 = calls_panic() -> unwind continue;
3838
+ StorageLive(_7);
39-
+ _7 = begin_panic::<&str>(const "explicit panic") -> unwind continue;
39+
+ _7 = panic_cold_explicit() -> unwind continue;
4040
}
4141
}
4242

‎tests/mir-opt/inline/inline_diverging.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Tests inlining of diverging calls.
22
//
33
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
4-
//@ compile-flags: -Zinline-mir-hint-threshold=1000 -C debuginfo=full
4+
//@ compile-flags: -Zinline-mir-hint-threshold=1000 -C debuginfo=full --edition=2021
55
#![crate_type = "lib"]
66

77
// EMIT_MIR inline_diverging.f.Inline.diff
@@ -17,8 +17,8 @@ pub fn g(i: i32) -> u32 {
1717
i as u32
1818
} else {
1919
// CHECK-LABEL: fn g(
20-
// CHECK: (inlined panic)
21-
panic();
20+
// CHECK: (inlined calls_panic)
21+
calls_panic();
2222
}
2323
}
2424

@@ -38,7 +38,7 @@ pub fn call_twice<R, F: Fn() -> R>(f: F) -> (R, R) {
3838
}
3939

4040
#[inline(always)]
41-
fn panic() -> ! {
41+
fn calls_panic() -> ! {
4242
panic!();
4343
}
4444

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /