Skip to content

Fix MIR inliner cycle detection for mutual recursion - #163030

Open
kulinsky wants to merge 1 commit into
rust-lang:mainfrom
kulinsky:fix-161234-mir-inline-cycle
Open

kulinsky wants to merge 1 commit into
rust-lang:mainfrom
kulinsky:fix-161234-mir-inline-cycle

Conversation

@kulinsky

@kulinsky kulinsky commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #161234

The problem is that the false value conflates two states:

  1. there is no path to the root;
  2. the traversal is not yet complete.

I fixed this by separating the states. Proven reachability to the root is now stored separately. For callees currently being processed, we store back-edges. Once it becomes clear that a path to the root exists, we propagate the result backwards. This requires additional memory to store the graph's back-edges.

I added a regression test to verify the traversal order.

The algorithm's complexity is O(V+E).

I would like to see the results of the compiler performance testing.

I used an LLM as a reviewer; the implementation and testing were done manually.

@rustbot

rustbot commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 19, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 19, 2026
@rustbot

rustbot commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, mir, mir-opt
  • compiler, mir, mir-opt expanded to 77 candidates
  • Random selection from 19 candidates

@saethlin

Copy link
Copy Markdown
Member

Tested with:

This section of PR descriptions is synthesized by LLM assistants, and is uniquely foolish to add in this repo because we, you know, have CI that runs all the tests. Please write PR descriptions by hand.

@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 20, 2026
@tmiasko

tmiasko commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 20, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 20, 2026
Fix MIR inliner cycle detection for mutual recursion
@rust-bors

rust-bors Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: cda6272 (cda6272c207dede0c6ff3fe0eaca141dcdbde2d9)
Base parent: feaadee (feaadeeaca7db0594da854e7c8c07495341c7439)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (cda6272): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.2%] 2
All ❌✅ (primary) 0.2% [0.2%, 0.2%] 1

Max RSS (memory usage)

Results (primary -2.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.9% [-2.9%, -2.9%] 1

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 502.551s -> 496.731s (-1.16%)
Artifact size: 406.86 MiB -> 406.80 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 20, 2026
@kulinsky

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 20, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

r? mir-opt

@rustbot rustbot assigned saethlin and unassigned JonathanBrouwer Sep 28, 2026
@rust-bors

rust-bors Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #166456) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Valid mutually recursive functions fail with E0391 at opt-level 2 and 3

7 participants