Skip to content

Commit 5806516

Browse files
committed
Remove the DefPathHash check
1 parent d4c86cf commit 5806516

File tree

6 files changed

+4
-110
lines changed

6 files changed

+4
-110
lines changed

compiler/rustc_mir_transform/src/inline.rs

-10
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,6 @@ impl<'tcx> Inliner<'tcx> {
332332
}
333333

334334
if callee_def_id.is_local() {
335-
// Avoid a cycle here by only using `instance_mir` only if we have
336-
// a lower `DefPathHash` than the callee. This ensures that the callee will
337-
// not inline us. This trick even works with incremental compilation,
338-
// since `DefPathHash` is stable.
339-
if self.tcx.def_path_hash(caller_def_id).local_hash()
340-
< self.tcx.def_path_hash(callee_def_id).local_hash()
341-
{
342-
return Ok(());
343-
}
344-
345335
// If we know for sure that the function we're calling will itself try to
346336
// call us, then we avoid inlining that function.
347337
if self.tcx.mir_callgraph_reachable((*callee, caller_def_id.expect_local())) {

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

+1-20
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,16 @@
44
fn g() -> () {
55
let mut _0: ();
66
let _1: ();
7-
+ let mut _2: fn() {main};
8-
+ scope 1 (inlined f::<fn() {main}>) {
9-
+ debug g => _2;
10-
+ let mut _3: &fn() {main};
11-
+ let _4: ();
12-
+ }
137

148
bb0: {
159
StorageLive(_1);
16-
- _1 = f::<fn() {main}>(main) -> [return: bb1, unwind unreachable];
17-
+ StorageLive(_2);
18-
+ _2 = main;
19-
+ StorageLive(_4);
20-
+ StorageLive(_3);
21-
+ _3 = &_2;
22-
+ _4 = <fn() {main} as Fn<()>>::call(move _3, const ()) -> [return: bb2, unwind unreachable];
10+
_1 = f::<fn() {main}>(main) -> [return: bb1, unwind unreachable];
2311
}
2412

2513
bb1: {
26-
+ StorageDead(_4);
27-
+ StorageDead(_2);
2814
StorageDead(_1);
2915
_0 = const ();
3016
return;
31-
+ }
32-
+
33-
+ bb2: {
34-
+ StorageDead(_3);
35-
+ drop(_2) -> [return: bb1, unwind unreachable];
3617
}
3718
}
3819

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

+1-28
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,16 @@
44
fn g() -> () {
55
let mut _0: ();
66
let _1: ();
7-
+ let mut _2: fn() {main};
8-
+ scope 1 (inlined f::<fn() {main}>) {
9-
+ debug g => _2;
10-
+ let mut _3: &fn() {main};
11-
+ let _4: ();
12-
+ }
137

148
bb0: {
159
StorageLive(_1);
16-
- _1 = f::<fn() {main}>(main) -> [return: bb1, unwind continue];
17-
+ StorageLive(_2);
18-
+ _2 = main;
19-
+ StorageLive(_4);
20-
+ StorageLive(_3);
21-
+ _3 = &_2;
22-
+ _4 = <fn() {main} as Fn<()>>::call(move _3, const ()) -> [return: bb2, unwind: bb3];
10+
_1 = f::<fn() {main}>(main) -> [return: bb1, unwind continue];
2311
}
2412

2513
bb1: {
26-
+ StorageDead(_4);
27-
+ StorageDead(_2);
2814
StorageDead(_1);
2915
_0 = const ();
3016
return;
31-
+ }
32-
+
33-
+ bb2: {
34-
+ StorageDead(_3);
35-
+ drop(_2) -> [return: bb1, unwind continue];
36-
+ }
37-
+
38-
+ bb3 (cleanup): {
39-
+ drop(_2) -> [return: bb4, unwind terminate(cleanup)];
40-
+ }
41-
+
42-
+ bb4 (cleanup): {
43-
+ resume;
4417
}
4518
}
4619

tests/mir-opt/inline/cycle.main.Inline.panic-abort.diff

+1-20
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,16 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: ();
7-
+ let mut _2: fn() {g};
8-
+ scope 1 (inlined f::<fn() {g}>) {
9-
+ debug g => _2;
10-
+ let mut _3: &fn() {g};
11-
+ let _4: ();
12-
+ }
137

148
bb0: {
159
StorageLive(_1);
16-
- _1 = f::<fn() {g}>(g) -> [return: bb1, unwind unreachable];
17-
+ StorageLive(_2);
18-
+ _2 = g;
19-
+ StorageLive(_4);
20-
+ StorageLive(_3);
21-
+ _3 = &_2;
22-
+ _4 = <fn() {g} as Fn<()>>::call(move _3, const ()) -> [return: bb2, unwind unreachable];
10+
_1 = f::<fn() {g}>(g) -> [return: bb1, unwind unreachable];
2311
}
2412

2513
bb1: {
26-
+ StorageDead(_4);
27-
+ StorageDead(_2);
2814
StorageDead(_1);
2915
_0 = const ();
3016
return;
31-
+ }
32-
+
33-
+ bb2: {
34-
+ StorageDead(_3);
35-
+ drop(_2) -> [return: bb1, unwind unreachable];
3617
}
3718
}
3819

tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff

+1-28
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,16 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: ();
7-
+ let mut _2: fn() {g};
8-
+ scope 1 (inlined f::<fn() {g}>) {
9-
+ debug g => _2;
10-
+ let mut _3: &fn() {g};
11-
+ let _4: ();
12-
+ }
137

148
bb0: {
159
StorageLive(_1);
16-
- _1 = f::<fn() {g}>(g) -> [return: bb1, unwind continue];
17-
+ StorageLive(_2);
18-
+ _2 = g;
19-
+ StorageLive(_4);
20-
+ StorageLive(_3);
21-
+ _3 = &_2;
22-
+ _4 = <fn() {g} as Fn<()>>::call(move _3, const ()) -> [return: bb2, unwind: bb3];
10+
_1 = f::<fn() {g}>(g) -> [return: bb1, unwind continue];
2311
}
2412

2513
bb1: {
26-
+ StorageDead(_4);
27-
+ StorageDead(_2);
2814
StorageDead(_1);
2915
_0 = const ();
3016
return;
31-
+ }
32-
+
33-
+ bb2: {
34-
+ StorageDead(_3);
35-
+ drop(_2) -> [return: bb1, unwind continue];
36-
+ }
37-
+
38-
+ bb3 (cleanup): {
39-
+ drop(_2) -> [return: bb4, unwind terminate(cleanup)];
40-
+ }
41-
+
42-
+ bb4 (cleanup): {
43-
+ resume;
4417
}
4518
}
4619

tests/mir-opt/inline/cycle.rs

-4
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ fn f(g: impl Fn()) {
1414
fn g() {
1515
// CHECK-LABEL: fn g(
1616
// CHECK-NOT: inlined
17-
// CHECK: (inlined f::<fn() {main}>)
18-
// CHECK-NOT: inlined
1917
f(main);
2018
}
2119

2220
// EMIT_MIR cycle.main.Inline.diff
2321
fn main() {
2422
// CHECK-LABEL: fn main(
2523
// CHECK-NOT: inlined
26-
// CHECK: (inlined f::<fn() {g}>)
27-
// CHECK-NOT: inlined
2824
f(g);
2925
}

0 commit comments

Comments
 (0)