rustdoc: heavily simplify the synthesis of auto trait impls by fmease · Pull Req...
source link: https://github.com/rust-lang/rust/pull/123340
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
gd --numstat HEAD~2 HEAD src/librustdoc/clean/auto_trait.rs
+315 -705 🟩🟥🟥🟥⬛
As outlined in issue #113015, there are currently 31 large separate routines that “clean” rustc_middle::ty
data types related to generics & predicates to rustdoc data types. Every single one has their own kinds of bugs. While I've patched a lot of bugs in each of the routines in the past, it's about time to unify them. This PR is only the first in a series. It completely yanks the custom “bounds cleaning” of mod auto_trait
and reuses the routines found in mod simplify
. As alluded to, simplify
is also flawed but it's still more complete than auto_trait
's routines. See also my review comment over at tests/rustdoc/synthetic_auto/bounds.rs
.
This is preparatory work for rewriting “bounds cleaning” from scratch in follow-up PRs in order to finally [fix] #113015.
Apart from that, I've eliminated all potential sources of instability in the rendered output.
See also #119597. I'm pretty sure this fixes #119597.
This PR does not attempt to fix any other issues related to synthetic auto trait impls.
However, it's definitely meant to be a stepping stone by making auto_trait
more contributor-friendly.
- Replace
FxHash{Map,Set}
withFxIndex{Map,Set}
to guarantee a stable iteration order- Or as a perf opt,
UnordSet
(a thin wrapper aroundFxHashSet
) in cases where we never iterate over the set. - Yes, we do make use of
swap_remove
but that shouldn't matter since all the callers are deterministic. It does make the output less “predictable” but it's still better than before. Ofc, I rely onrustc_infer
being deterministic. I hope that holds.
- Or as a perf opt,
- Utilizing
clean::simplify
over the custom “bounds cleaning” routines wipes out the last reference tocollect_referenced_late_bound_regions
in rustdoc (simplify
usesbound_vars
) which was a source of instability / unpredictability (cc rustdoc: fix & clean up handling of cross-crate higher-ranked parameters #116388) - Remove the types
RegionTarget
andRegionDeps
fromlibrustdoc
. They were duplicates of the identical types found inrustc
. Just import them fromrustc
. For some reason, they were duplicated when splittingauto_trait
in two in Refactor auto trait handling in librustdoc to be accessible from librustc. #49711. - Get rid of the useless “type namespace”
AutoTraitFinder
inlibrustdoc
- The struct only held a
DocContext
, it was over-engineered - Turn the associated functions into free ones
- Eliminates rightward drift; increases legibility
rustc
also contains a uselessAutoTraitFinder
struct but I plan on removing that in a follow-up PR
- The struct only held a
- Rename a bunch of methods to be way more descriptive
- Eliminate
use super::*;
- Lead to
clean/mod.rs
accumulating a lot of unnecessary imports - Made
auto_traits
less modular
- Lead to
- Eliminate a custom
TypeFolder
: We can just use the rustc helperfold_regions
which does that for us
I plan on adding extensive documentation to librustdoc
's auto_trait
in follow-up PRs.
I don't want to do that in this PR because further refactoring & bug fix PRs may alter the overall structure of librustdoc
's & rustc
's auto_trait
modules to a great degree. I'm slowly digging into the dark details of rustc
's auto_trait
module again and once I have the full picture I will be able to provide proper docs.
While this PR does indeed touch rustc
's auto_trait
— mostly tiny refactorings — I argue this PR doesn't need any compiler reviewers next to rustdoc ones since that module falls under the purview of rustdoc — it used to be part of librustdoc
after all (#49711).
Sorry for not having split this into more commits. If you'd like me to I can try to split it into more atomic commits retroactively. However, I don't know if that would actually make reviewing easier. I think the best way to review this might just be to place the master version of auto_trait
on the left of your screen and the patched one on the right, not joking.
Footnotes
-
Or even 4 depending on the way you're counting. ↩
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK