-
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
Refactor fmt::Display
impls in rustdoc
#135494
Conversation
src/librustdoc/clean/cfg.rs
Outdated
@@ -389,98 +390,84 @@ fn write_with_opt_paren<T: fmt::Display>( | |||
Ok(()) | |||
} | |||
|
|||
impl Display<'_> { | |||
fn display_quantified_sub_cfgs( |
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 really don't think this is a great name for this function, but couldn't come up with a better one 😅
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 would just go for display_sub_cfgs
since the only constructs (of the cfg
sublanguage) that may have sub-cfgs are all
and any
.
I guess “quantified” is not wrong since it's true that the sub cfgs are quantified by either
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.
Renamed. I just looked up "common term for ALL and ANY" or something haha. Math is not my strong suit, so thanks for the thorough explanation, I appreciate it 😁
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 was considering making a Quantifier
enum with Any
or All
variants to make this function a bit easier to understand, but not sure if it's not too verbose. Leaving at is as is for now, unless you think it's a good idea.
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Refactor `fmt::Display` impls in rustdoc This PR does a couple of things, with the intention of cleaning up and streamlining some of the `fmt::Display` impls in rustdoc: 1. Use the unstable [`fmt::from_fn`](rust-lang#117729) instead of open-coding it. 2. Replace bespoke implementations of `Itertools::format` with the method itself. 3. Some more minor cleanups - DRY, remove unnecessary calls to `Symbol::as_str()`, replace some `format!()` calls with lazier options The changes are mostly cosmetic but some of them might have a slight positive effect on performance.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (6b19da6): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (secondary 9.9%)This 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: 765.975s -> 765.445s (-0.07%) |
@aDotInTheVoid should I do something about the perf results? AFAIR rustc-perf doesn't actually benchmark |
@yotamofek It does benchmark rustdoc. There are 4 profile=doc (aka rustdoc) regressions, the check one is spurious. |
Oh, ok, I see it now. So it's definitely a real regression. |
16e9fe6
to
37c30a0
Compare
I removed the commit with the usages of |
@bors try @rust-timer queue |
Refactor `fmt::Display` impls in rustdoc This PR does a couple of things, with the intention of cleaning up and streamlining some of the `fmt::Display` impls in rustdoc: 1. Use the unstable [`fmt::from_fn`](rust-lang#117729) instead of open-coding it. 2. Replace bespoke implementations of `Itertools::format` with the method itself. 3. Some more minor cleanups - DRY, remove unnecessary calls to `Symbol::as_str()`, replace some `format!()` calls with lazier options The changes are mostly cosmetic but some of them might have a slight positive effect on performance.
☀️ Try build successful - checks-actions |
@rust-timer ping |
@rust-timer build 109d05c |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (109d05c): comparison URL. Overall result: ✅ improvements - 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 is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (secondary 2.0%)This 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: 764.328s -> 765.066s (0.10%) |
37c30a0
to
57de8b7
Compare
Actually, that was needed to make it easier to adopt |
This comment has been minimized.
This comment has been minimized.
57de8b7
to
48b5481
Compare
Ah, I see. Thanks for the correction, that makes perfect sense! @bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (fc0094f): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (secondary 1.6%)This 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.
CyclesResults (primary -2.2%)This 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: 776.757s -> 778.767s (0.26%) |
…rrowLii Use `fmt::from_fn` in more places in the compiler Use the unstable functions from rust-lang#117729 in more places in the compiler, follow up to rust-lang#135494
Rollup merge of rust-lang#135951 - yotamofek:use-debug-helpers, r=SparrowLii Use `fmt::from_fn` in more places in the compiler Use the unstable functions from rust-lang#117729 in more places in the compiler, follow up to rust-lang#135494
[WIP: perf] attempt to prevent regressions in that originally happened in rust-lang#135494 This implements something similar to [`Itertools::format`](https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.format), but on `Fn`s returning iterators instead of directly on iterators, to allow implementing `Display` without the use of a `Cell` (to handle the possibility of `fmt` being called multiple times while receiving `&self`). This is WIP, I just want to get a perf run first to see if the regression I saw in rust-lang#135494 is fixed
[WIP: perf] attempt to prevent regressions in that originally happened in rust-lang#135494 This implements something similar to [`Itertools::format`](https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.format), but on `Fn`s returning iterators instead of directly on iterators, to allow implementing `Display` without the use of a `Cell` (to handle the possibility of `fmt` being called multiple times while receiving `&self`). This is WIP, I just want to get a perf run first to see if the regression I saw in rust-lang#135494 is fixed
[WIP: perf] attempt to prevent regressions in that originally happened in rust-lang#135494 This implements something similar to [`Itertools::format`](https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.format), but on `Fn`s returning iterators instead of directly on iterators, to allow implementing `Display` without the use of a `Cell` (to handle the possibility of `fmt` being called multiple times while receiving `&self`). This is WIP, I just want to get a perf run first to see if the regression I saw in rust-lang#135494 is fixed
… r=dtolnay Mark `std::fmt::from_fn` as `#[must_use]` While working on rust-lang#135494 I managed to shoot my own foot a few times by forgetting to actually use the result of `fmt::from_fn`, so I think a `#[must_use]` could be appropriate! Didn't have a good message to put in the attr so left it blank, still unstable so we can come back to it I guess? cc rust-lang#117729 (and a huge +1 for getting it stabilized, it's very useful IMHO)
…illaumeGomez librustdoc: create a helper for separating elements of an iterator instead of implementing it multiple times This implements something similar to [`Itertools::format`](https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.format), but on `Fn`s returning iterators instead of directly on iterators, to allow implementing `Display` without the use of a `Cell` (to handle the possibility of `fmt` being called multiple times while receiving `&self`). ~This is WIP, I just want to get a perf run first to see if the regression I saw in rust-lang#135494 is fixed~ This was originally part of rust-lang#135494 , but originally caused a perf regression that was since fixed: https://github.com/rust-lang/rust/blob/7d5ae1863aa66847a4edf8d2ef9420717df65c5d/src/librustdoc/html/format.rs#L507
… r=dtolnay Mark `std::fmt::from_fn` as `#[must_use]` While working on rust-lang#135494 I managed to shoot my own foot a few times by forgetting to actually use the result of `fmt::from_fn`, so I think a `#[must_use]` could be appropriate! Didn't have a good message to put in the attr so left it blank, still unstable so we can come back to it I guess? cc rust-lang#117729 (and a huge +1 for getting it stabilized, it's very useful IMHO)
Rollup merge of rust-lang#136502 - yotamofek:pr/fmt-from-fn-must-use, r=dtolnay Mark `std::fmt::from_fn` as `#[must_use]` While working on rust-lang#135494 I managed to shoot my own foot a few times by forgetting to actually use the result of `fmt::from_fn`, so I think a `#[must_use]` could be appropriate! Didn't have a good message to put in the attr so left it blank, still unstable so we can come back to it I guess? cc rust-lang#117729 (and a huge +1 for getting it stabilized, it's very useful IMHO)
This PR does a couple of things, with the intention of cleaning up and streamlining some of the
fmt::Display
impls in rustdoc:fmt::from_fn
instead of open-coding it.Replace bespoke implementations ofItertools::format
with the method itself.Symbol::as_str()
, replace someformat!()
calls with lazier optionsThe changes are mostly cosmetic but some of them might have a slight positive effect on performance.