Skip to content

Commit 8f97231

Browse files
Remove semi-nondeterminism of DefPathHash ordering from inliner
1 parent c52c23b commit 8f97231

6 files changed

+4
-72
lines changed

compiler/rustc_mir_transform/src/inline.rs

-10
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,6 @@ impl<'tcx> Inliner<'tcx> {
357357
}
358358

359359
if callee_def_id.is_local() {
360-
// Avoid a cycle here by only using `instance_mir` only if we have
361-
// a lower `DefPathHash` than the callee. This ensures that the callee will
362-
// not inline us. This trick even works with incremental compilation,
363-
// since `DefPathHash` is stable.
364-
if self.tcx.def_path_hash(caller_def_id).local_hash()
365-
< self.tcx.def_path_hash(callee_def_id).local_hash()
366-
{
367-
return Ok(());
368-
}
369-
370360
// If we know for sure that the function we're calling will itself try to
371361
// call us, then we avoid inlining that function.
372362
if self.tcx.mir_callgraph_reachable((callee, caller_def_id.expect_local())) {

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
@@ -19,9 +19,5 @@ fn g() {
1919

2020
// EMIT_MIR cycle.main.Inline.diff
2121
fn main() {
22-
// CHECK-LABEL: fn main(
23-
// CHECK-NOT: inlined
24-
// CHECK: (inlined f::<fn() {g}>)
25-
// CHECK-NOT: inlined
2622
f(g);
2723
}

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
+ scope 1 (inlined <C as Call>::call) {
88
+ scope 2 (inlined <B<A> as Call>::call) {
99
+ scope 3 (inlined <A as Call>::call) {
10-
+ scope 4 (inlined <B<C> as Call>::call) {
11-
+ scope 5 (inlined <C as Call>::call) {
12-
+ }
13-
+ }
1410
+ }
1511
+ }
1612
+ }
1713

1814
bb0: {
1915
StorageLive(_1);
2016
- _1 = <C as Call>::call() -> [return: bb1, unwind unreachable];
21-
+ _1 = <B<A> as Call>::call() -> [return: bb1, unwind unreachable];
17+
+ _1 = <B<C> as Call>::call() -> [return: bb1, unwind unreachable];
2218
}
2319

2420
bb1: {

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
+ scope 1 (inlined <C as Call>::call) {
88
+ scope 2 (inlined <B<A> as Call>::call) {
99
+ scope 3 (inlined <A as Call>::call) {
10-
+ scope 4 (inlined <B<C> as Call>::call) {
11-
+ scope 5 (inlined <C as Call>::call) {
12-
+ }
13-
+ }
1410
+ }
1511
+ }
1612
+ }
1713

1814
bb0: {
1915
StorageLive(_1);
2016
- _1 = <C as Call>::call() -> [return: bb1, unwind continue];
21-
+ _1 = <B<A> as Call>::call() -> [return: bb1, unwind continue];
17+
+ _1 = <B<C> as Call>::call() -> [return: bb1, unwind continue];
2218
}
2319

2420
bb1: {

0 commit comments

Comments
 (0)