-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustdoc: heavily simplify the synthesis of auto trait impls #123340
rustdoc: heavily simplify the synthesis of auto trait impls #123340
Conversation
Some changes occurred in src/librustdoc/clean/types.rs cc @camelid |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
|
||
impl<T> std::marker::Unpin for Inner<T> | ||
where | ||
T: for<'any> Trait<A = (), B<'any> = (), X = ()>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On master, this gets rendered as:
T: Trait<A = ()> + Trait<B<'any> = ()> + SuperTrait<X = ()>,
…mpl-synth, r=<try> rustdoc: heavily simplify the synthesis of auto trait impls `gd --numstat HEAD~2 HEAD src/librustdoc/clean/auto_trait.rs` **+315 -705** 🟩🟥🟥🟥⬛ --- As outlined in issue rust-lang#113015, there are currently 3[^1] 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 mentioned, `simplify` is also flawed but still it's 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” in follow-up PRs in order to finally [fix] rust-lang#113015. Apart from that, I've eliminated all potential sources of *unstable rendering output*. See also rust-lang#119597. I'm pretty sure this fixes rust-lang#119597. This PR does not attempt to fix [any other issues related to synthetic auto trait impls](https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AA-synthetic-impls%20label%3AA-auto-traits). However, it's definitely meant to be a *stepping stone* by making `auto_trait` more contributor friendly. --- * Replace `FxHash{Map,Set}` with `FxIndex{Map,Set}` to guarantee a stable / more predictable iteration order * Or as a perf opt, `UnordSet` (a thin wrapper around `FxHashSet`) in cases where we never iterate over the set. * Remove the types `RegionTarget` and `RegionDeps` from `librustdoc`. They were duplicates of the identical types found in `rustc`. Just import them from `rustc`. For some reason, they were duplicated when splitting `auto_trait` in two in rust-lang#49711. * Get rid of the useless “type namespace” `AutoTraitFinder` in `librustdoc` * 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 useless `AutoTraitFinder` struct but I plan on removing that in a follow-up PR * Rename a bunch of methods to be way more descriptive * Eliminate `use super::*;` * Lead to `clean/mod.rs` accumulating a lot of unnecessary imports and therefore * made `auto_traits` less modular 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 (rust-lang#49711). Sorry for not having split this into more commits. If you'd like me to I can try to retroactively separate it into more atomic commits. However, I don't know if that would actually make reviewing this PR easier. r? `@GuillaumeGomez` [^1]: Or even 4 depending on the way you're counting.
@@ -494,7 +485,7 @@ pub(crate) fn get_auto_trait_and_blanket_impls( | |||
.sess() | |||
.prof | |||
.generic_activity("get_auto_trait_impls") | |||
.run(|| AutoTraitFinder::new(cx).get_auto_trait_impls(item_def_id)); | |||
.run(|| synthesize_auto_trait_impls(cx, item_def_id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the new name synthesize_auto_trait_impls
is inconsistent with the established terminology “get […] impls” like get_auto_trait_and_blanket_impls
, get_blanket_impls
etc. I plan on updating the old terminology in follow-up PRs. “Get” is super misleading and nondescript. We are in fact “computing” those impls. I chose the new term “synthesize” because we call them “synthetic impls” in other places, too. However, I could also go for “generate” if you'd like me to.
@@ -502,14 +498,17 @@ fn projection_to_path_segment<'tcx>( | |||
|
|||
fn clean_generic_param_def<'tcx>( | |||
def: &ty::GenericParamDef, | |||
defaults: ParamDefaults, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit this could be perceived as introducing a weird non-modular coupling between clean
and clean::auto_trait
. Previously, auto_trait
would just clean_ty_generics
(which calls this function) and then remove the generic parameter defaults afterwards (in a for-loop). This felt a bit unclean.
Adding this param allows us to get rid of the for-loop in auto_trait
. Furthermore, it avoids executing the rustc queries type_of
& const_param_default
and the functions clean_middle_ty
& to_string
(only to throw away the results) in auto_trait
which boosts perf in theory.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
785787f
to
c8070f5
Compare
This comment has been minimized.
This comment has been minimized.
c8070f5
to
069e7f2
Compare
Finished benchmarking commit (ce8cfc5): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 666.866s -> 666.631s (-0.04%) |
This is awesome! Changes look good to me currently so r=me if the PR is ready. |
Yes, it's ready. |
@bors rollup- |
☀️ Test successful - checks-actions |
Finished benchmarking commit (5dbaafd): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 667.665s -> 667.636s (-0.00%) |
spurious, not a |
…uillaumeGomez rustdoc: synthetic auto trait impls: accept unresolved region vars for now rust-lang#123348 (comment): > Right, [in rust-lang#123340] I've intentionally changed a `vid_map.get(vid).unwrap_or(r)` to a `vid_map[vid]` making rustdoc panic if `rustc::AutoTraitFinder` returns a region inference variable that cannot be resolved because that is really fishy. I can change it back with a `FIXME: investigate` […]. [O]nce I [fully] understand [the arcane] `rustc::AutoTraitFinder` [I] can fix the underlying issue if there's one. > > `rustc::AutoTraitFinder` can also return placeholder regions `RePlaceholder` which doesn't seem right either and which makes rustdoc ICE, too (we have a GitHub issue for that already[, namely rust-lang#120606]). Fixes rust-lang#123370. Fixes rust-lang#112242. r? `@GuillaumeGomez`
…uillaumeGomez rustdoc: synthetic auto trait impls: accept unresolved region vars for now rust-lang#123348 (comment): > Right, [in rust-lang#123340] I've intentionally changed a `vid_map.get(vid).unwrap_or(r)` to a `vid_map[vid]` making rustdoc panic if `rustc::AutoTraitFinder` returns a region inference variable that cannot be resolved because that is really fishy. I can change it back with a `FIXME: investigate` […]. [O]nce I [fully] understand [the arcane] `rustc::AutoTraitFinder` [I] can fix the underlying issue if there's one. > > `rustc::AutoTraitFinder` can also return placeholder regions `RePlaceholder` which doesn't seem right either and which makes rustdoc ICE, too (we have a GitHub issue for that already[, namely rust-lang#120606]). Fixes rust-lang#123370. Fixes rust-lang#112242. r? ``@GuillaumeGomez``
Rollup merge of rust-lang#123375 - fmease:rustdoc-sati-re-hotfix, r=GuillaumeGomez rustdoc: synthetic auto trait impls: accept unresolved region vars for now rust-lang#123348 (comment): > Right, [in rust-lang#123340] I've intentionally changed a `vid_map.get(vid).unwrap_or(r)` to a `vid_map[vid]` making rustdoc panic if `rustc::AutoTraitFinder` returns a region inference variable that cannot be resolved because that is really fishy. I can change it back with a `FIXME: investigate` […]. [O]nce I [fully] understand [the arcane] `rustc::AutoTraitFinder` [I] can fix the underlying issue if there's one. > > `rustc::AutoTraitFinder` can also return placeholder regions `RePlaceholder` which doesn't seem right either and which makes rustdoc ICE, too (we have a GitHub issue for that already[, namely rust-lang#120606]). Fixes rust-lang#123370. Fixes rust-lang#112242. r? ``@GuillaumeGomez``
…, r=GuillaumeGomez rustdoc: heavily simplify the synthesis of auto trait impls `gd --numstat HEAD~2 HEAD src/librustdoc/clean/auto_trait.rs` **+315 -705** 🟩🟥🟥🟥⬛ --- As outlined in issue #113015, there are currently 3[^1] 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`](rust-lang/rust#123340 (comment)). 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](https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AA-synthetic-impls%20label%3AA-auto-traits). However, it's definitely meant to be a *stepping stone* by making `auto_trait` more contributor-friendly. --- * Replace `FxHash{Map,Set}` with `FxIndex{Map,Set}` to guarantee a stable iteration order * Or as a perf opt, `UnordSet` (a thin wrapper around `FxHashSet`) 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 on `rustc_infer` being deterministic. I hope that holds. * Utilizing `clean::simplify` over the custom “bounds cleaning” routines wipes out the last reference to `collect_referenced_late_bound_regions` in rustdoc (`simplify` uses `bound_vars`) which was a source of instability / unpredictability (cc #116388) * Remove the types `RegionTarget` and `RegionDeps` from `librustdoc`. They were duplicates of the identical types found in `rustc`. Just import them from `rustc`. For some reason, they were duplicated when splitting `auto_trait` in two in #49711. * Get rid of the useless “type namespace” `AutoTraitFinder` in `librustdoc` * 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 useless `AutoTraitFinder` struct but I plan on removing that in a follow-up PR * 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 * Eliminate a custom `TypeFolder`: We can just use the rustc helper `fold_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. r? `@GuillaumeGomez` [^1]: Or even 4 depending on the way you're counting.
Auto trait bounds have changed in one of: - rust-lang/rust#123340. - rust-lang/rust#123375.
I believe this PR might have changed the bounds on auto trait impls. See aya-rs/aya#920. |
Thanks for bringing this to my attention I will look into it later. I tried very hard not add extraneous bounds (for now; cc #111101) |
Auto trait bounds have changed in one of: - rust-lang/rust#123340. - rust-lang/rust#123375.
…, r=GuillaumeGomez rustdoc: heavily simplify the synthesis of auto trait impls `gd --numstat HEAD~2 HEAD src/librustdoc/clean/auto_trait.rs` **+315 -705** 🟩🟥🟥🟥⬛ --- As outlined in issue #113015, there are currently 3[^1] 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`](rust-lang/rust#123340 (comment)). 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](https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AA-synthetic-impls%20label%3AA-auto-traits). However, it's definitely meant to be a *stepping stone* by making `auto_trait` more contributor-friendly. --- * Replace `FxHash{Map,Set}` with `FxIndex{Map,Set}` to guarantee a stable iteration order * Or as a perf opt, `UnordSet` (a thin wrapper around `FxHashSet`) 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 on `rustc_infer` being deterministic. I hope that holds. * Utilizing `clean::simplify` over the custom “bounds cleaning” routines wipes out the last reference to `collect_referenced_late_bound_regions` in rustdoc (`simplify` uses `bound_vars`) which was a source of instability / unpredictability (cc #116388) * Remove the types `RegionTarget` and `RegionDeps` from `librustdoc`. They were duplicates of the identical types found in `rustc`. Just import them from `rustc`. For some reason, they were duplicated when splitting `auto_trait` in two in #49711. * Get rid of the useless “type namespace” `AutoTraitFinder` in `librustdoc` * 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 useless `AutoTraitFinder` struct but I plan on removing that in a follow-up PR * 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 * Eliminate a custom `TypeFolder`: We can just use the rustc helper `fold_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. r? `@GuillaumeGomez` [^1]: Or even 4 depending on the way you're counting.
…pls-synth, r=camelid rustdoc: slightly clean up the synthesis of blanket impls Small follow-up to rust-lang#123340 as promised in rust-lang#123340 (comment). No functional changes whatsoever. * inline the over-engineered “type namespace” (struct) `BlanketImplFinder` just like I did with `AutoTraitFinder` in rust-lang#123340 * use the new `synthesize_*` terminology over the old nondescript / misleading `get_*` one * inline a `use super::*;` (not super modular, lead to `clean/mod.rs` (!) accumulating cruft) * use `tracing` properly r? GuillaumeGomez or rustdoc
Rollup merge of rust-lang#123647 - fmease:rustdoc-clean-up-blanket-impls-synth, r=camelid rustdoc: slightly clean up the synthesis of blanket impls Small follow-up to rust-lang#123340 as promised in rust-lang#123340 (comment). No functional changes whatsoever. * inline the over-engineered “type namespace” (struct) `BlanketImplFinder` just like I did with `AutoTraitFinder` in rust-lang#123340 * use the new `synthesize_*` terminology over the old nondescript / misleading `get_*` one * inline a `use super::*;` (not super modular, lead to `clean/mod.rs` (!) accumulating cruft) * use `tracing` properly r? GuillaumeGomez or rustdoc
…m-param-env-clauses, r=GuillaumeGomez rustdoc: synthetic auto: filter out clauses from the implementor's ParamEnv ... not just the elaborated clauses. Fixes another regression introduced by me in rust-lang#123340, oops! Fixes rust-lang#123340 (comment), cc `@tamird.` An earlier local iteration of branch `rustdoc-simplify-auto-trait-impl-synth` (PR rust-lang#123340) contained a fix for issue rust-lang#111101 before I decided to limit the scope. I must've introduced this bug when manually reverting that part of the code. r? `@GuillaumeGomez` or rustdoc
…m-param-env-clauses, r=GuillaumeGomez rustdoc: synthetic auto: filter out clauses from the implementor's ParamEnv ... not just the elaborated clauses. Fixes another regression introduced by me in rust-lang#123340, oops! Fixes rust-lang#123340 (comment), cc ``@tamird.`` An earlier local iteration of branch `rustdoc-simplify-auto-trait-impl-synth` (PR rust-lang#123340) contained a fix for issue rust-lang#111101 before I decided to limit the scope. I must've introduced this bug when manually reverting that part of the code. r? ``@GuillaumeGomez`` or rustdoc
Rollup merge of rust-lang#123638 - fmease:rustdoc-synth-auto-yeet-item-param-env-clauses, r=GuillaumeGomez rustdoc: synthetic auto: filter out clauses from the implementor's ParamEnv ... not just the elaborated clauses. Fixes another regression introduced by me in rust-lang#123340, oops! Fixes rust-lang#123340 (comment), cc ``@tamird.`` An earlier local iteration of branch `rustdoc-simplify-auto-trait-impl-synth` (PR rust-lang#123340) contained a fix for issue rust-lang#111101 before I decided to limit the scope. I must've introduced this bug when manually reverting that part of the code. r? ``@GuillaumeGomez`` or rustdoc
…, r=GuillaumeGomez rustdoc: heavily simplify the synthesis of auto trait impls `gd --numstat HEAD~2 HEAD src/librustdoc/clean/auto_trait.rs` **+315 -705** 🟩🟥🟥🟥⬛ --- As outlined in issue #113015, there are currently 3[^1] 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`](rust-lang/rust#123340 (comment)). 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](https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AA-synthetic-impls%20label%3AA-auto-traits). However, it's definitely meant to be a *stepping stone* by making `auto_trait` more contributor-friendly. --- * Replace `FxHash{Map,Set}` with `FxIndex{Map,Set}` to guarantee a stable iteration order * Or as a perf opt, `UnordSet` (a thin wrapper around `FxHashSet`) 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 on `rustc_infer` being deterministic. I hope that holds. * Utilizing `clean::simplify` over the custom “bounds cleaning” routines wipes out the last reference to `collect_referenced_late_bound_regions` in rustdoc (`simplify` uses `bound_vars`) which was a source of instability / unpredictability (cc #116388) * Remove the types `RegionTarget` and `RegionDeps` from `librustdoc`. They were duplicates of the identical types found in `rustc`. Just import them from `rustc`. For some reason, they were duplicated when splitting `auto_trait` in two in #49711. * Get rid of the useless “type namespace” `AutoTraitFinder` in `librustdoc` * 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 useless `AutoTraitFinder` struct but I plan on removing that in a follow-up PR * 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 * Eliminate a custom `TypeFolder`: We can just use the rustc helper `fold_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. r? `@GuillaumeGomez` [^1]: Or even 4 depending on the way you're counting.
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 modauto_trait
and reuses the routines found in modsimplify
. As alluded to,simplify
is also flawed but it's still more complete thanauto_trait
's routines. See also my review comment over attests/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.FxHash{Map,Set}
withFxIndex{Map,Set}
to guarantee a stable iteration orderUnordSet
(a thin wrapper aroundFxHashSet
) in cases where we never iterate over the set.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.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)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.AutoTraitFinder
inlibrustdoc
DocContext
, it was over-engineeredrustc
also contains a uselessAutoTraitFinder
struct but I plan on removing that in a follow-up PRuse super::*;
clean/mod.rs
accumulating a lot of unnecessary importsauto_traits
less modularTypeFolder
: We can just use the rustc helperfold_regions
which does that for usI plan on adding extensive documentation to
librustdoc
'sauto_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
'sauto_trait
modules to a great degree. I'm slowly digging into the dark details ofrustc
'sauto_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
'sauto_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 oflibrustdoc
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.r? @GuillaumeGomez
Footnotes
Or even 4 depending on the way you're counting. ↩