Skip to content

rustdoc: skip blanket impls on recursive types - #160173

Open
im-lunex wants to merge 1 commit into
rust-lang:mainfrom
im-lunex:fix_#160105
Open

rustdoc: skip blanket impls on recursive types#160173
im-lunex wants to merge 1 commit into
rust-lang:mainfrom
im-lunex:fix_#160105

Conversation

@im-lunex

@im-lunex im-lunex commented Jul 29, 2026

Copy link
Copy Markdown

When a type contains itself through its fields (e.g. struct A(B<A>)),
evaluating blanket impl obligations on it can hang or take exponential
time. Skip blanket impl synthesis entirely for such types.

Adds a TypeVisitor that walks field types with cycle detection and
returns early from synthesize_blanket_impls when a recursive ADT
is found.

fixes #160105.

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

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @notriddle (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: rustdoc
  • rustdoc expanded to 8 candidates
  • Random selection from GuillaumeGomez, camelid, lolbinarycat, notriddle

@im-lunex
im-lunex marked this pull request as draft July 29, 2026 18:56
@rustbot rustbot 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 Jul 29, 2026
@im-lunex im-lunex changed the title rustdoc: speed up blanket impl synthesis for recursive types rustdoc: skip blanket impls on recursive types Jul 30, 2026
@rust-log-analyzer

This comment has been minimized.

@im-lunex
im-lunex marked this pull request as ready for review July 30, 2026 10:23
@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 Jul 30, 2026
@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Jul 30, 2026
@rustbot rustbot removed the has-merge-commits PR has merge commits, merge with caution. label Jul 30, 2026
@notriddle

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 Jul 30, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 30, 2026
rustdoc: skip blanket impls on recursive types
@rust-bors

rust-bors Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 1701156 (1701156946ac94f71ac6fe1ac6110e8762eb2841)
Base parent: be3d26d (be3d26db984c6f96335faca1f254dc04873cb1c1)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (1701156): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never rustc-perf
@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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.0% [-3.5%, -0.2%] 9
Improvements ✅
(secondary)
-1.4% [-2.4%, -0.3%] 3
All ❌✅ (primary) -1.0% [-3.5%, -0.2%] 9

Max RSS (memory usage)

Results (primary 0.5%, secondary -1.6%)

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

mean range count
Regressions ❌
(primary)
2.7% [0.4%, 4.1%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.2% [-2.1%, -0.4%] 4
Improvements ✅
(secondary)
-1.6% [-1.6%, -1.6%] 1
All ❌✅ (primary) 0.5% [-2.1%, 4.1%] 7

Cycles

Results (primary -0.6%, secondary -2.6%)

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

mean range count
Regressions ❌
(primary)
0.7% [0.4%, 1.0%] 2
Regressions ❌
(secondary)
1.2% [0.4%, 3.7%] 12
Improvements ✅
(primary)
-1.0% [-3.2%, -0.4%] 7
Improvements ✅
(secondary)
-6.4% [-21.5%, -0.4%] 12
All ❌✅ (primary) -0.6% [-3.2%, 1.0%] 9

Binary size

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

Bootstrap: 489.155s -> 489.631s (0.10%)
Artifact size: 390.64 MiB -> 390.69 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 30, 2026
use crate::core::DocContext;

/// Detects recursive types to avoid infinite loops in blanket impl evaluation.
fn contains_recursive_type(tcx: TyCtxt<'_>, item_def_id: DefId) -> bool {

@fmease fmease Jul 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an extremely targeted fix that's also way too broad as it means that rustdoc stops showing blanket impls for all recursive data types which I don't consider acceptable.

The linked issue #160105 likely has the same root cause as #155759 and #114891.

The problem isn't with rustdoc's blanket impl synthesis, it's with the current trait solver. The next trait solver fixes this class of issues. Hence, I consider PR #125907 to be the principled fix (which is still blocked by some perf regressions caused by the switch).

What you're doing here is trying to patch faults of the trait solver from the outside just like PR #155765 which I'm also not a fan of.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmease thanks for looking into it. I see the issue and i will love to have my time to look deeper into it.. and will inform as soon as i get something.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmease soo i dont see any way to fix this with the old trait solver. this must go under the new_trait_solver.. that you are already working on (#125907) here. soo you can close this PR..

@rustbot rustbot 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 Jul 30, 2026
@rustbot

rustbot commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustdoc extreme slowdown with cyclic generic structures

6 participants