Skip to content

Commit 114c928

Browse files
committed
Check history earlier.
1 parent 5999f34 commit 114c928

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

compiler/rustc_mir_transform/src/inline.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ impl<'tcx> Inliner<'tcx> {
263263
return None;
264264
}
265265

266+
if self.history.contains(&callee) {
267+
return None;
268+
}
269+
266270
let fn_sig = self.tcx.bound_fn_sig(def_id).subst(self.tcx, substs);
267271

268272
return Some(CallSite {
@@ -407,22 +411,9 @@ impl<'tcx> Inliner<'tcx> {
407411
}
408412

409413
TerminatorKind::Call { func: Operand::Constant(ref f), cleanup, .. } => {
410-
if let ty::FnDef(def_id, substs) =
414+
if let ty::FnDef(def_id, _) =
411415
*callsite.callee.subst_mir(self.tcx, &f.literal.ty()).kind()
412416
{
413-
if let Ok(substs) =
414-
self.tcx.try_normalize_erasing_regions(self.param_env, substs)
415-
{
416-
if let Ok(Some(instance)) =
417-
Instance::resolve(self.tcx, self.param_env, def_id, substs)
418-
{
419-
if callsite.callee.def_id() == instance.def_id() {
420-
return Err("self-recursion");
421-
} else if self.history.contains(&instance) {
422-
return Err("already inlined");
423-
}
424-
}
425-
}
426417
// Don't give intrinsics the extra penalty for calls
427418
if tcx.is_intrinsic(def_id) {
428419
cost += INSTR_COST;

src/test/mir-opt/inline/inline_cycle.one.Inline.diff

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
let mut _0: (); // return place in scope 0 at $DIR/inline-cycle.rs:13:10: 13:10
66
let _1: (); // in scope 0 at $DIR/inline-cycle.rs:14:5: 14:24
77
+ scope 1 (inlined <C as Call>::call) { // at $DIR/inline-cycle.rs:14:5: 14:24
8+
+ scope 2 (inlined <A<C> as Call>::call) { // at $DIR/inline-cycle.rs:43:9: 43:23
9+
+ scope 3 (inlined <B<C> as Call>::call) { // at $DIR/inline-cycle.rs:28:9: 28:31
10+
+ }
11+
+ }
812
+ }
913

1014
bb0: {
1115
StorageLive(_1); // scope 0 at $DIR/inline-cycle.rs:14:5: 14:24
1216
- _1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle.rs:14:5: 14:24
13-
+ _1 = <A<C> as Call>::call() -> bb1; // scope 1 at $DIR/inline-cycle.rs:43:9: 43:23
17+
+ _1 = <C as Call>::call() -> bb1; // scope 3 at $DIR/inline-cycle.rs:36:9: 36:28
1418
// mir::Constant
1519
- // + span: $DIR/inline-cycle.rs:14:5: 14:22
16-
- // + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
17-
+ // + span: $DIR/inline-cycle.rs:43:9: 43:21
18-
+ // + literal: Const { ty: fn() {<A<C> as Call>::call}, val: Value(Scalar(<ZST>)) }
20+
+ // + span: $DIR/inline-cycle.rs:36:9: 36:26
21+
// + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
1922
}
2023

2124
bb1: {

src/test/mir-opt/inline/inline_cycle.two.Inline.diff

+15-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
+ let _3: (); // in scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
1212
+ let mut _4: fn() {f}; // in scope 1 at $DIR/inline-cycle.rs:54:5: 54:6
1313
+ scope 2 (inlined <fn() {f} as FnOnce<()>>::call_once - shim(fn() {f})) { // at $DIR/inline-cycle.rs:54:5: 54:8
14+
+ scope 3 (inlined f) { // at $SRC_DIR/core/src/ops/function.rs:LL:COL
15+
+ let _6: (); // in scope 3 at $DIR/inline-cycle.rs:59:5: 59:12
16+
+ }
1417
+ }
1518
+ }
1619

@@ -21,19 +24,26 @@
2124
+ _2 = f; // scope 0 at $DIR/inline-cycle.rs:49:5: 49:12
2225
// mir::Constant
2326
- // + span: $DIR/inline-cycle.rs:49:5: 49:9
24-
- // + literal: Const { ty: fn(fn() {f}) {call::<fn() {f}>}, val: Value(Scalar(<ZST>)) }
25-
- // mir::Constant
26-
// + span: $DIR/inline-cycle.rs:49:10: 49:11
27-
// + literal: Const { ty: fn() {f}, val: Value(Scalar(<ZST>)) }
27+
+ // + span: $DIR/inline-cycle.rs:49:10: 49:11
28+
+ // + literal: Const { ty: fn() {f}, val: Value(Scalar(<ZST>)) }
2829
+ StorageLive(_3); // scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
2930
+ StorageLive(_4); // scope 1 at $DIR/inline-cycle.rs:54:5: 54:6
3031
+ _4 = move _2; // scope 1 at $DIR/inline-cycle.rs:54:5: 54:6
3132
+ StorageLive(_5); // scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
3233
+ _5 = const (); // scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
33-
+ _3 = move _4() -> bb1; // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
34+
+ StorageLive(_6); // scope 3 at $DIR/inline-cycle.rs:59:5: 59:12
35+
+ _6 = call::<fn() {f}>(f) -> bb1; // scope 3 at $DIR/inline-cycle.rs:59:5: 59:12
36+
+ // mir::Constant
37+
+ // + span: $DIR/inline-cycle.rs:59:5: 59:9
38+
// + literal: Const { ty: fn(fn() {f}) {call::<fn() {f}>}, val: Value(Scalar(<ZST>)) }
39+
// mir::Constant
40+
- // + span: $DIR/inline-cycle.rs:49:10: 49:11
41+
+ // + span: $DIR/inline-cycle.rs:59:10: 59:11
42+
// + literal: Const { ty: fn() {f}, val: Value(Scalar(<ZST>)) }
3443
}
3544

3645
bb1: {
46+
+ StorageDead(_6); // scope 3 at $DIR/inline-cycle.rs:59:12: 59:13
3747
+ StorageDead(_5); // scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
3848
+ StorageDead(_4); // scope 1 at $DIR/inline-cycle.rs:54:7: 54:8
3949
+ StorageDead(_3); // scope 1 at $DIR/inline-cycle.rs:54:8: 54:9

src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@
44
fn main() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/inline-cycle-generic.rs:8:11: 8:11
66
let _1: (); // in scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
7+
+ scope 1 (inlined <C as Call>::call) { // at $DIR/inline-cycle-generic.rs:9:5: 9:24
8+
+ scope 2 (inlined <B<A> as Call>::call) { // at $DIR/inline-cycle-generic.rs:38:9: 38:31
9+
+ scope 3 (inlined <A as Call>::call) { // at $DIR/inline-cycle-generic.rs:31:9: 31:28
10+
+ scope 4 (inlined <B<C> as Call>::call) { // at $DIR/inline-cycle-generic.rs:23:9: 23:31
11+
+ }
12+
+ }
13+
+ }
14+
+ }
715

816
bb0: {
917
StorageLive(_1); // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
10-
_1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
18+
- _1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
19+
+ _1 = <C as Call>::call() -> bb1; // scope 4 at $DIR/inline-cycle-generic.rs:31:9: 31:28
1120
// mir::Constant
12-
// + span: $DIR/inline-cycle-generic.rs:9:5: 9:22
21+
- // + span: $DIR/inline-cycle-generic.rs:9:5: 9:22
22+
+ // + span: $DIR/inline-cycle-generic.rs:31:9: 31:26
1323
// + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
1424
}
1525

1626
bb1: {
1727
StorageDead(_1); // scope 0 at $DIR/inline-cycle-generic.rs:9:24: 9:25
1828
_0 = const (); // scope 0 at $DIR/inline-cycle-generic.rs:8:11: 10:2
1929
return; // scope 0 at $DIR/inline-cycle-generic.rs:10:2: 10:2
30+
+ }
31+
+
32+
+ bb2 (cleanup): {
33+
+ resume; // scope 0 at $DIR/inline-cycle-generic.rs:8:1: 10:2
2034
}
2135
}
2236

0 commit comments

Comments
 (0)