-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustdoc: Remove distinction between "regular" and "collapsed" docs #91072
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
Conversation
They seem to be very similar; I think they don't need to be separate.
They're unneeded now that `doc_value()` and `collapsed_doc_value()` are the same.
Some changes occurred in intra-doc-links. cc @jyn514 |
Might as well see if the Crate shrinkage improved perf. @bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 157d1db9b17ae9637cf92273bab45da869e22b78 with merge 68b8e770b5409b48c66862743fdff57a63ae8bfd... |
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'm not sure this has the same behavior ... some things are obviously a win like turning FromIterator
into a function, but I would like to see more examples of the behavior for different doc types before and after.
src/librustdoc/clean/types.rs
Outdated
let mut iter = self.doc_strings.iter(); | ||
|
||
let ori = iter.next()?; | ||
let mut out = String::new(); | ||
add_doc_fragment(&mut out, ori); | ||
for new_frag in iter { | ||
if new_frag.kind != ori.kind || new_frag.parent_module != ori.parent_module { | ||
break; | ||
} | ||
add_doc_fragment(&mut out, new_frag); | ||
} | ||
if out.is_empty() { None } else { Some(out) } | ||
self.collapsed_doc_value() |
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 not the same behavior. The FromIterator
impl below is missing the new_frag.kind != ori.kind || new_frag.parent_module != ori.parent_module
check.
I'm not sure if it matters in practice, but it seems like something we should have tests for ... could you try and find one or two, or add a new one if not?
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.
Before merging collapsed and un-collapsed, I tried removing one part of this conditional and all the tests passed. I'll try removing the whole conditional too (with no other changes) to see what happens.
I agree it'd be good to have more test coverage. I'll see if I can come up with some test cases.
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.
All tests pass with master + this diff:
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index 41ebf270ba6..5a02a6c6259 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -1083,9 +1083,6 @@ fn update_need_backline(doc_strings: &mut Vec<DocFragment>) {
let mut out = String::new();
add_doc_fragment(&mut out, ori);
for new_frag in iter {
- if new_frag.kind != ori.kind || new_frag.parent_module != ori.parent_module {
- break;
- }
add_doc_fragment(&mut out, new_frag);
}
if out.is_empty() { None } else { Some(out) }
So either that conditional is useless or we don't have any test coverage for 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.
Adding enough test coverage around this code to know for sure that nothing is changing will take a long time. What about if I open a PR to remove this conditional, we land it, and wait to see if any regressions pop up? If there are any regressions, then we can do a quick revert since it's just a few lines. If we don't find any regressions, then we can move forward with a bigger change.
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.
Hmm, I'm ok with that, but let's wait until after the beta branch on friday.
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.
Opened #91305.
@@ -1083,7 +1080,11 @@ impl Attributes { | |||
/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined | |||
/// with newlines. | |||
crate fn doc_value(&self) -> Option<String> { |
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.
not necessarily in this pr, but it would be nice to remove the Option
here
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 we check the is_some
to generate differently the doc block. From my point of view, this forces us to keep this check so might be better to keep 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 don't really understand why None
is treated differently from Some("")
though. What if someone writes #[doc = ""]
? Won't that return Some("")
instead of None
? And why do we need to special-case the absence of doc attrs so much?
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.
Another difference between doc_value
and collapsed_doc_value
- doc_value
returns None if the combined string is empty, collapsed_doc_value
returns None if there are no lines. The difference matters if there's empty lines, like below:
///
///
///
pub fn foo() {}
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.
@CraftSpider I see the following comment in rustdoc-json-types
:
/// The full markdown docstring of this item. Absent if there is no documentation at all,
/// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`).
pub docs: Option<String>,
Is that an important distinction? Or can I just make that field a simple String
?
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
Let's restart the perf check: @bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 157d1db9b17ae9637cf92273bab45da869e22b78 with merge c5a55b2dfca7383f1932664496103fe59a330016... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
Ugh, it'll be nice to have
|
The FromIterator was only used once and made the code much harder to understand. The types don't make sense until you realize there's a custom FromIterator impl.
⌛ Trying commit 1891548 with merge 33fc15df6db1037b483198fb978ecdd109b9776d... |
☀️ Try build successful - checks-actions |
Queued 33fc15df6db1037b483198fb978ecdd109b9776d with parent 3d78974, future comparison URL. |
Finished benchmarking commit (33fc15df6db1037b483198fb978ecdd109b9776d): comparison url. Summary: This benchmark run did not return any relevant changes. 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 |
Very small improvements but overall we're moving in the right direction! :D |
Blocked on #91305. |
I need to remove this conditional for rust-lang#91072, but while it seems unnecessary, we are not certain. So, the plan is to first remove the conditional and see if any regressions pop up before doing the refactor. This way, it will be easier to revert if there are subtle regressions.
rustdoc: Remove apparently unnecessary conditional in `doc_value` I need to remove this conditional for rust-lang#91072, but while it seems unnecessary, we are not certain. So, the plan is to first remove the conditional and see if any regressions pop up before doing the refactor. This way, it will be easier to revert if there are subtle regressions. r? `@jyn514`
I need to remove this conditional for rust-lang#91072, but while it seems unnecessary, we are not certain. So, the plan is to first remove the conditional and see if any regressions pop up before doing the refactor. This way, it will be easier to revert if there are subtle regressions.
The PR this has been blocked on, #91305, is on stable as of a week and a half ago. As of yet, I don't know of any regressions that have been reported. So, I think in a month or two, we should be able to merge this PR as well! |
@camelid this is waiting on a rebase |
Thanks, it's on my list. I might not get to it for a bit since there are so many conflicts. |
There actually seems to be no difference.
r? @GuillaumeGomez
cc @jyn514