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: Skip doc link resolution for non-exported items #107932

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

petrochenkov
Copy link
Contributor

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Feb 11, 2023

r? @jsha

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 11, 2023
@petrochenkov
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

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

bors commented Feb 11, 2023

⌛ Trying commit 80beaa506705af5943b272dd0bc262e4668f47db with merge aac432a34739ec6dd1fd66a287cf34e17a8c49f8...

@bors
Copy link
Contributor

bors commented Feb 11, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (aac432a34739ec6dd1fd66a287cf34e17a8c49f8): comparison URL.

Overall result: no relevant changes - no action needed

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 may lead to changes in compiler perf.

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

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

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.

mean range count
Regressions ❌
(primary)
3.2% [3.2%, 3.2%] 1
Regressions ❌
(secondary)
2.2% [1.5%, 3.1%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.6% [-1.6%, -1.6%] 1
All ❌✅ (primary) 3.2% [3.2%, 3.2%] 1

Cycles

Results

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) - - 0

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 11, 2023
@petrochenkov
Copy link
Contributor Author

Are benchmarks run with --document-private-items by chance?

Anyway, this is a cheap optimization that can skip extra work in some cases, and it's done in other situations (ResolveDocLinks::ExportedMetadata), so it still makes sense to land it.

@bors

This comment was marked as resolved.

@apiraino
Copy link
Contributor

apiraino commented Mar 22, 2023

@rustbot r? compiler

who can have a second look at this from the perspective of T-compiler?

edit: for context, this PR was discussed in a previous T-compiler meeting (on zulip) trying to stimulate a review but apparently the domain of knowledge involved in the review does not allow a simple random review assignment. We need another T-compiler person able to review these changes

@rustbot rustbot assigned eholk and unassigned jsha Mar 22, 2023
@eholk
Copy link
Contributor

eholk commented Mar 22, 2023

@rustbot r? @jyn514

@rustbot rustbot assigned jyn514 and unassigned eholk Mar 22, 2023
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.

The code looks good and the change makes sense to me (this is just a perf optimization, right, it shouldn't affect behavior?).

r=me with the suggested test case added.

if !self.cx.render_options.document_private
&& let Some(def_id) = item.item_id.as_def_id()
&& let Some(def_id) = def_id.as_local()
&& !self.cx.tcx.effective_visibilities(()).is_exported(def_id)
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure is_exported is the correct thing here, and not is_reachable? Can you add a test case for

mod private {
  /// [core::str::FromStr]
  pub struct Bar;
}

pub fn foo() -> private::Bar {
    private::Bar
}

and make sure it behaves the same both before and after this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In both cases Bar is not documented and Bar in pub fn foo() -> Bar in the generated doc is not a link.

Rustdoc uses is_reachable in only one place when it generates json output, and I'm not sure why.

@jyn514
Copy link
Member

jyn514 commented Mar 22, 2023

Actually hold on - all private items should already be stripped from the crate at this point (see

/// Strip private items from the point of view of a crate or externally from a
/// crate, specified by the `xcrate` flag.
pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
). I think that's why this isn't showing a perf improvement, it's not actually affecting rustdoc's behavior. What issue were you running into before you added the !is_exported() check to the intra-doc links pass?

@petrochenkov petrochenkov 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 Mar 22, 2023
@bors

This comment was marked as resolved.

@petrochenkov
Copy link
Contributor Author

petrochenkov commented Mar 23, 2023

@jyn514

What issue were you running into before you added the !is_exported() check to the intra-doc links pass?

And ICE when documenting liballoc.

Documenting alloc v0.0.0 (C:\msys64\home\we\rust\library\alloc)
thread 'rustc' panicked at 'no resolutions for a doc link', compiler\rustc_metadata\src\rmeta\encoder.rs:2251:18

rustdoc still tries to request resolution for a link on some non-exported item.

It seems like it doesn't happen often due to the item stripping pass, so there's no effect on performance, but does happen.

@petrochenkov
Copy link
Contributor Author

Inner doc comment on the alloc::vec::in_place_collect module, which is indeed not exported (it's fully private).

[src\librustdoc\passes\collect_intra_doc_links.rs:377] path_str = "Vec"
[src\librustdoc\passes\collect_intra_doc_links.rs:377] ns = MacroNS
[src\librustdoc\passes\collect_intra_doc_links.rs:377] item_id = DefId(0:6408 ~ alloc[76f0]::vec::in_place_collect)
[src\librustdoc\passes\collect_intra_doc_links.rs:377] module_id = DefId(0:6408 ~ alloc[76f0]::vec::in_place_collect)
thread 'rustc' panicked at 'no resolutions for a doc link', compiler\rustc_metadata\src\rmeta\encoder.rs:2255:18

@petrochenkov
Copy link
Contributor Author

@rustbot ready

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

jyn514 commented Mar 24, 2023

rustdoc still tries to request resolution for a link on some non-exported item.

It seems like it doesn't happen often due to the item stripping pass, so there's no effect on performance, but does happen.

This seems like a pre-existing bug I would like to investigate, but it doesn't have to block this PR.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 24, 2023

📌 Commit bec4eab has been approved by jyn514

It is now in the queue for this repository.

@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 Mar 24, 2023
@bors
Copy link
Contributor

bors commented Mar 24, 2023

⌛ Testing commit bec4eab with merge fd46bb408dba5d3e0a34a4e490ef1f838264f616...

@bors
Copy link
Contributor

bors commented Mar 24, 2023

💔 Test failed - checks-actions

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

ehuss commented Mar 24, 2023

@bors retry

github incident

@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 Mar 24, 2023
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Mar 24, 2023

⌛ Testing commit bec4eab with merge 8be3c2b...

@bors
Copy link
Contributor

bors commented Mar 24, 2023

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 24, 2023
@bors bors merged commit 8be3c2b into rust-lang:master Mar 24, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 24, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8be3c2b): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.5% [1.1%, 1.7%] 3
Improvements ✅
(primary)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
-1.3% [-3.1%, -0.5%] 6
All ❌✅ (primary) -0.8% [-0.8%, -0.8%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

None yet