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

rustdoc DocFragment rework #80261

Merged
merged 6 commits into from
Jan 3, 2021
Merged

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Dec 21, 2020

Kind of a follow-up of #80119.

A few things are happening in this PR. I'm not sure about the impact on perf though so I'm very interested about that too (if the perf is worse, then we can just close this PR).

The idea here is mostly about reducing the memory usage by relying even more on Symbol instead of String. The only issue is that DocFragment has 3 modifications performed on it:

  1. Unindenting
  2. Collapsing similar comments into one
  3. "Beautifying" (weird JS-like comments handling).

To do so, I saved the information about unindent and the "collapse" is now on-demand (which is why I'm not sure the perf will be better, it has to be run multiple times...).

r? @jyn514

@rust-highfive

This comment has been minimized.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 21, 2020
@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 21, 2020
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

I think this should be separated into two changes: one refactoring rustdoc to work on demand, and one refactoring rustc_ast to work on Symbol instead of String. That way we can measure the performance of each more accurately, and it means that I can assign a rustc reviewer without the discussion getting intermingled. Do you mind opening a separate PR for that?

compiler/rustc_ast/src/util/comments.rs Outdated Show resolved Hide resolved
compiler/rustc_ast/src/util/comments.rs Outdated Show resolved Hide resolved
compiler/rustc_ast/src/util/comments.rs Outdated Show resolved Hide resolved
compiler/rustc_save_analysis/src/lib.rs Outdated Show resolved Hide resolved
src/librustdoc/clean/types.rs Show resolved Hide resolved
src/librustdoc/html/render/cache.rs Outdated Show resolved Hide resolved
src/librustdoc/html/render/cache.rs Outdated Show resolved Hide resolved
src/librustdoc/html/render/mod.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/collapse_docs.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

Time to check if this approach is the right one!

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@bors
Copy link
Contributor

bors commented Dec 21, 2020

⌛ Trying commit 0022dfacdc697de78b17bbb298d4719df366df32 with merge 9ef3226338bac4bd516f19a1000cd1c4e741a039...

@bors
Copy link
Contributor

bors commented Dec 21, 2020

☀️ Try build successful - checks-actions
Build commit: 9ef3226338bac4bd516f19a1000cd1c4e741a039 (9ef3226338bac4bd516f19a1000cd1c4e741a039)

@rust-timer
Copy link
Collaborator

Queued 9ef3226338bac4bd516f19a1000cd1c4e741a039 with parent 11c94a1, future comparison URL.

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

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 21, 2020
@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (9ef3226338bac4bd516f19a1000cd1c4e741a039): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 22, 2020
@GuillaumeGomez
Copy link
Member Author

Results of the perf check:

rss: -0.8%
instructions: between -0.4% and -1.8%

So it seems to be a good result. Should we continue on this @jyn514 ?

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 24, 2020
…rochenkov

Rework beautify_doc_string so that it returns a Symbol instead of a String

This commit comes from rust-lang#80261, the goal here is to inspect the impact on performance of this change on its own.

The idea of rewriting `beautify_doc_string` is to not go through `String` if we don't need to update the doc comment to be able to keep the original `Symbol` and also to have better performance.

r? `@jyn514`
@GuillaumeGomez
Copy link
Member Author

Updated!

src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
src/librustdoc/clean/types.rs Show resolved Hide resolved
Comment on lines 795 to 800
let s: String = self.doc_strings.iter().collect();
if s.is_empty() { None } else { Some(s) }
Copy link
Member

Choose a reason for hiding this comment

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

This is still waiting for a response: where is this used and when would the caller expect it to be None?

src/librustdoc/core.rs Show resolved Hide resolved
src/librustdoc/html/render/mod.rs Outdated Show resolved Hide resolved
src/librustdoc/html/render/mod.rs Outdated Show resolved Hide resolved
src/librustdoc/html/render/mod.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/calculate_doc_coverage.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/collapse_docs.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/unindent_comments/tests.rs Outdated Show resolved Hide resolved
@GuillaumeGomez
Copy link
Member Author

Updated! ping @jyn514 ;)

Comment on lines +130 to +133
LL | /// \____/
| _________^
LL | | ///
| |_
Copy link
Member

Choose a reason for hiding this comment

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

This change looks strange, do you know why it happened?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a slight difference in the markdown sent to passes::source_span_for_markdown_range.

Before this PR: --> 24..30 "```\nlet x = 1;\n```\n\n    \\____/"
With this PR:   --> 24..31 "```\nlet x = 1;\n```\n\n    \\____/\n"

So as you can see, we have an extra backline added now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Explanations about his change: in impl<'a> FromIterator<&'a DocFragment> for String {, before we simply collapsed the strings together and added a backline if the "accumulator" wasn't empty. However, we now take into account if a DocFragment requires a backline or not which is then added if necessary. This information is stored in the need_backline field and computed in the Attributes::from_ast method.

So in this case, since this is an indented codeblock, it's a different fragment kind than the one following it, which then adds the backline in the ouput. Here's what the doc fragments looks like:

-> DocFragment { line: 0, span: src/test/rustdoc-ui/invalid-syntax.rs:90:1: 90:8 (#0), parent_module: None, doc: " ```", kind: SugaredDoc, need_backline: true, indent: 1 }
-> DocFragment { line: 1, span: src/test/rustdoc-ui/invalid-syntax.rs:91:1: 91:15 (#0), parent_module: None, doc: " let x = 1;", kind: SugaredDoc, need_backline: true, indent: 1 }
-> DocFragment { line: 2, span: src/test/rustdoc-ui/invalid-syntax.rs:92:1: 92:8 (#0), parent_module: None, doc: " ```", kind: SugaredDoc, need_backline: true, indent: 1 }
-> DocFragment { line: 3, span: src/test/rustdoc-ui/invalid-syntax.rs:93:1: 93:4 (#0), parent_module: None, doc: "", kind: SugaredDoc, need_backline: true, indent: 0 }
-> DocFragment { line: 3, span: src/test/rustdoc-ui/invalid-syntax.rs:94:1: 94:15 (#0), parent_module: None, doc: "     \\____/", kind: SugaredDoc, need_backline: true, indent: 1 }
-> DocFragment { line: 4, span: src/test/rustdoc-ui/invalid-syntax.rs:95:1: 95:4 (#0), parent_module: None, doc: "", kind: SugaredDoc, need_backline: false, indent: 0 }
warning: could not parse code block as Rust code

Copy link
Member

Choose a reason for hiding this comment

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

Wow, that is confusing.

Ok, adding a trailing newline seems like the correct behavior because there's a blank doc-comment after the code block:

/// ```
/// let x = 1;
/// ```
///
/// \____/
///
. I'm not 100% why the error message changes because of that, but the new error message is reasonable too so I don't think it needs to be debugged.

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 2, 2021
@jyn514
Copy link
Member

jyn514 commented Jan 3, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Jan 3, 2021

📌 Commit df2df14 has been approved by jyn514

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 3, 2021
@bors
Copy link
Contributor

bors commented Jan 3, 2021

⌛ Testing commit df2df14 with merge e821a6e...

@bors
Copy link
Contributor

bors commented Jan 3, 2021

☀️ Test successful - checks-actions
Approved by: jyn514
Pushing e821a6e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 3, 2021
@bors bors merged commit e821a6e into rust-lang:master Jan 3, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 3, 2021
@GuillaumeGomez GuillaumeGomez deleted the attr-rework branch January 3, 2021 10:42
jyn514 added a commit to jyn514/rust that referenced this pull request Mar 1, 2021
`src/test/rustdoc-ui/deprecated-attrs.rs`
tells rustdoc to run the `collapse-docs` pass, which no longer exists
(it was removed in rust-lang#80261).
Rustdoc doesn't actually give a proper diagnostic here; instead it
prints an `error!` log. Now that tracing is compiled unconditionally,
the log is now being emitted by default, because it's at the error
level.

rustdoc shouldn't be using `error!` logging for diagnostics in the first
place, but in the meantime this change gets the testsuite to pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

7 participants