Skip to content
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

librustdoc: impl core::fmt::Write for rustdoc::html::render::Buffer #92758

Merged
merged 3 commits into from
Feb 2, 2022

Conversation

mfrw
Copy link
Contributor

@mfrw mfrw commented Jan 11, 2022

Signed-off-by: Muhammad Falak R Wani [email protected]

Fixes: #92563

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 11, 2022
@rust-highfive
Copy link
Collaborator

r? @CraftSpider

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 11, 2022
@mfrw
Copy link
Contributor Author

mfrw commented Jan 11, 2022

r? @jyn514

@@ -62,6 +62,12 @@ crate struct Buffer {
buffer: String,
}

impl core::fmt::Write for Buffer {
Copy link
Contributor

@djc djc Jan 11, 2022

Choose a reason for hiding this comment

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

I would probably just forward all three methods directly (I'm unsure about performance effects), since it's pretty trivial to do, and also annotate each of them with #[inline].

And we should probably remove the inherent write_str() and write_fmt() methods, replacing their usage with these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forwarded all the methods and then tried to use the trait methods but i could not make head or tail of the errors that came :(
I then tried to call the traits as <Self as Write>::write_fmt(....) which worked. Have not pushed those changes up though, as I am not sure if they are sane :(

@camelid
Copy link
Member

camelid commented Jan 11, 2022

r? @GuillaumeGomez

@mfrw
Copy link
Contributor Author

mfrw commented Jan 12, 2022

I tried to use the newly implemented write_str & write_fmt but faced a lot of issues during compilation.
The thing that worked for me is using something like this in impl Buffer :

impl Buffer {
  ...
  crate fn write_str(&mut self, s: &str) {
     <Self as Write>::write_str(self, s).unwrap();
  }

  crate fn write_fmt(&mut self, v: fmt::Arguments<'_>) {
     <Self as Write>::write_fmt(self, v).unwrap();
  }
  ...
}

Although, I am not sure, if this is the right approach :(
I request for some guidance please.

@djc
Copy link
Contributor

djc commented Jan 12, 2022

I meant removing the write_str() or write_fmt() methods from impl Buffer, and instead have callers rely on the methods implemented through std::fmt::Write. Have you considered doing that?

@mfrw
Copy link
Contributor Author

mfrw commented Jan 12, 2022

I meant removing the write_str() or write_fmt() methods from impl Buffer, and instead have callers rely on the methods implemented through std::fmt::Write. Have you considered doing that?

Yes, I tried that first, I was unable to get that working. Let me give it one more try.
This is what i did, please correct me if something does not feel right.

  • Remove the impld 'write_fmt & write_str` methods.
  • Use the Write::write_fmt & Write::write_str and unwrap their result, as the methods that were impl'd did not return anything.

@djc
Copy link
Contributor

djc commented Jan 12, 2022

That sounds like the right approach! How did it not work? Did you get a compiler error? If so, what?

@mfrw
Copy link
Contributor Author

mfrw commented Jan 17, 2022

That sounds like the right approach! How did it not work? Did you get a compiler error? If so, what?

I apologize, I was not taking into account that the signatures have changed & I might have to add a bunch of unwraps.
Now that I did the change, I am seeing a test-break, which I have no clue how to fix or investigate.
So I will spend some more time on learning :)

I am able to pass tests locally :)

@mfrw mfrw force-pushed the mfrw/rustdoc-impl-write branch 3 times, most recently from b284d10 to 31ea629 Compare January 17, 2022 06:28
@mfrw
Copy link
Contributor Author

mfrw commented Jan 17, 2022

@bors try

@GuillaumeGomez
Copy link
Member

Please remove your merge commits and instead use rebase. Once done, I'll start a perf check because I'm curious to see if there is any impact. Please ping once you have removed the merge commit.

@@ -140,7 +140,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer,
};

let heading = item_vars.render().unwrap();
buf.write_str(&heading);
buf.write_str(&heading).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the original point of my issue was to change this to do buf.write_fmt(format!("{}", heading)).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, let me do that activity after I resolve the git issues :)
[btw .. this process has been immense learning & apologies for me being a little slow to understand the bigger picture]

Copy link
Member

Choose a reason for hiding this comment

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

What about this @mfrw?

Copy link
Member

Choose a reason for hiding this comment

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

It's fine don't worry. If you have questions don't hesitate to ask. Thank you for working on this! :)

@djc
Copy link
Contributor

djc commented Jan 17, 2022

I regret suggesting we should change all the instances of write_str() and write_fmt() to rely on the std::fmt::Write implementation, I now see that those methods were explicitly documented as avoiding unwrapping. @mfrw if you're up for it, maybe those should be reverted? @GuillaumeGomez what do you think?

@mfrw
Copy link
Contributor Author

mfrw commented Jan 17, 2022

Please remove your merge commits and instead use rebase. Once done, I'll start a perf check because I'm curious to see if there is any impact. Please ping once you have removed the merge commit.

Take II with rebase instead of a merge.
Please take a look whenever you get a chance @GuillaumeGomez :)

@mfrw
Copy link
Contributor Author

mfrw commented Jan 17, 2022

I regret suggesting we should change all the instances of write_str() and write_fmt() to rely on the std::fmt::Write implementation, I now see that those methods were explicitly documented as avoiding unwrapping. @mfrw if you're up for it, maybe those should be reverted? @GuillaumeGomez what do you think?

Sure, this was a huge learning :)
Although, I would love to see the perf results which @GuillaumeGomez mentioned.

@GuillaumeGomez
Copy link
Member

I regret suggesting we should change all the instances of write_str() and write_fmt() to rely on the std::fmt::Write implementation, I now see that those methods were explicitly documented as avoiding unwrapping. @mfrw if you're up for it, maybe those should be reverted? @GuillaumeGomez what do you think?

If there is no perf improvement from it, I think that's what we will need to do because the increase of code for no gain isn't really worth it.

So for the perf now:

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 17, 2022
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Jan 17, 2022

Please fix the error.

@bors: try-

EDIT: And by the time I wrote this message, you did. 😆

@GuillaumeGomez
Copy link
Member

Ok, let's try again!

@bors try @rust-timer queue

@mfrw
Copy link
Contributor Author

mfrw commented Jan 27, 2022

There's no real urgency, was just wondering! I'll give you some more time, let's see how it goes next week.

Thank you Very much :)

@mfrw
Copy link
Contributor Author

mfrw commented Feb 1, 2022

@djc & @GuillaumeGomez apologies for the late turn around :(

Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

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

LGTM! Would be nice to get a perf run for this, I suppose?

@GuillaumeGomez
Copy link
Member

Absolutely!

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 1, 2022
@bors
Copy link
Contributor

bors commented Feb 1, 2022

⌛ Trying commit 62bea63 with merge 213368f0aa11b580455fc90c29d5e4b4700f73d1...

@bors
Copy link
Contributor

bors commented Feb 1, 2022

☀️ Try build successful - checks-actions
Build commit: 213368f0aa11b580455fc90c29d5e4b4700f73d1 (213368f0aa11b580455fc90c29d5e4b4700f73d1)

@rust-timer
Copy link
Collaborator

Queued 213368f0aa11b580455fc90c29d5e4b4700f73d1 with parent 547f2ba, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (213368f0aa11b580455fc90c29d5e4b4700f73d1): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking 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 led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 1, 2022
@GuillaumeGomez
Copy link
Member

Thanks for all your work on this @mfrw!

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Feb 1, 2022

📌 Commit 62bea63 has been approved by GuillaumeGomez

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 1, 2022
@djc
Copy link
Contributor

djc commented Feb 1, 2022

I don't see any doc things in the rustc-perf listing, what am I missing?

@GuillaumeGomez
Copy link
Member

You need to uncheck "Show only significant changes" and "Filter out very small changes". To have only relevant items, you can filter by using " doc".

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 2, 2022
…llaumeGomez

librustdoc: impl core::fmt::Write for rustdoc::html::render::Buffer

Signed-off-by: Muhammad Falak R Wani <[email protected]>

Fixes: rust-lang#92563
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 2, 2022
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#92758 (librustdoc: impl core::fmt::Write for rustdoc::html::render::Buffer)
 - rust-lang#92788 (Detect `::` -> `:` typo in type argument)
 - rust-lang#93420 (Improve wrapping on settings page)
 - rust-lang#93493 (Document valid values of the char type)
 - rust-lang#93531 (Fix incorrect panic message in example)
 - rust-lang#93559 (Add missing | between print options)
 - rust-lang#93560 (Fix two incorrect "it's" (typos in comments))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7117b45 into rust-lang:master Feb 2, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

impl core::fmt::Write for rustdoc::html::render::Buffer
10 participants