rustdoc: skip blanket impls on recursive types - #160173
Conversation
|
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 (
Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rustdoc: skip blanket impls on recursive types
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (1701156): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking 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 Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
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.
CyclesResults (primary -0.6%, secondary -2.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 489.155s -> 489.631s (0.10%) |
| 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
|
Reminder, once the PR becomes ready for a review, use |
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_implswhen a recursive ADTis found.
fixes #160105.