-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustdoc DocFragment rework #80261
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dd5b243
to
0d9503d
Compare
This comment has been minimized.
This comment has been minimized.
0d9503d
to
be20bc9
Compare
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 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?
This comment has been minimized.
This comment has been minimized.
be20bc9
to
85b5825
Compare
This comment has been minimized.
This comment has been minimized.
85b5825
to
334f43f
Compare
This comment has been minimized.
This comment has been minimized.
Time to check if this approach is the right one! @bors try @rust-timer queue |
Awaiting bors try build completion. |
⌛ Trying commit 0022dfacdc697de78b17bbb298d4719df366df32 with merge 9ef3226338bac4bd516f19a1000cd1c4e741a039... |
☀️ Try build successful - checks-actions |
Queued 9ef3226338bac4bd516f19a1000cd1c4e741a039 with parent 11c94a1, future comparison URL. @rustbot label: +S-waiting-on-perf |
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 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 |
Results of the perf check:
So it seems to be a good result. Should we continue on this @jyn514 ? |
…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`
0022dfa
to
a4f0e5f
Compare
Updated! |
src/librustdoc/clean/types.rs
Outdated
let s: String = self.doc_strings.iter().collect(); | ||
if s.is_empty() { None } else { Some(s) } |
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.
This is still waiting for a response: where is this used and when would the caller expect it to be None
?
8dfd5c9
to
fab01ab
Compare
Updated! ping @jyn514 ;) |
60539b9
to
fd77d0b
Compare
LL | /// \____/ | ||
| _________^ | ||
LL | | /// | ||
| |_ |
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.
This change looks strange, do you know why it happened?
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.
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.
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.
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
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.
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:
rust/src/test/rustdoc-ui/invalid-syntax.rs
Lines 88 to 93 in df2df14
/// ``` | |
/// let x = 1; | |
/// ``` | |
/// | |
/// \____/ | |
/// |
fd77d0b
to
df2df14
Compare
@bors r+ |
📌 Commit df2df14 has been approved by |
☀️ Test successful - checks-actions |
`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.
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 ofString
. The only issue is thatDocFragment
has 3 modifications performed on it: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