Skip to content

rustdoc: Pre-calculate traits that are in scope for doc links#88679

Merged
bors merged 1 commit intorust-lang:masterfrom
petrochenkov:doctrscope
Jan 26, 2022
Merged

rustdoc: Pre-calculate traits that are in scope for doc links#88679
bors merged 1 commit intorust-lang:masterfrom
petrochenkov:doctrscope

Conversation

@petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Sep 5, 2021

This eliminates one more late use of resolver (part of #83761).
At early doc link resolution time we go through parent modules of items from the current crate, reexports of items from other crates, trait items, and impl items collected by collect-intra-doc-links pass, determine traits that are in scope in each such module, and put those traits into a map used by later rustdoc passes.
r? @jyn514

@rust-highfive
Copy link
Contributor

Some changes occurred in intra-doc-links.

cc @jyn514

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 5, 2021
@jyn514
Copy link
Member

jyn514 commented Sep 6, 2021

@bors try @rust-timer queue

Since encoding and decoding are performance sensitive.

@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 Sep 6, 2021
@bors
Copy link
Collaborator

bors commented Sep 6, 2021

⌛ Trying commit 1514df2159ed22849eaddfd75c5e57cf801de6d4 with merge 2aadece0d9989be6855d4e96bac0f4ec08f23c91...

@rust-log-analyzer

This comment has been minimized.

@bors

This comment has been minimized.

@bors bors 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 Sep 6, 2021
@jyn514 jyn514 added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 6, 2021
@bors

This comment has been minimized.

@petrochenkov
Copy link
Contributor Author

petrochenkov commented Sep 12, 2021

Blocked on #88677 and #88872.

@petrochenkov petrochenkov added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 12, 2021
@mati865
Copy link
Member

mati865 commented Sep 12, 2021

Typo? #88679 is this PR.

@petrochenkov
Copy link
Contributor Author

@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 Sep 16, 2021
@bors
Copy link
Collaborator

bors commented Sep 16, 2021

⌛ Trying commit 1ed1f29e01aedafd3a4dcb253de4be5da9a9eade with merge eec63217b0c2bd2bd82596fe0f8f6ccc5b9cc1a0...

@bors
Copy link
Collaborator

bors commented Jan 25, 2022

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

@rust-timer
Copy link
Collaborator

Queued 25308acc28ea882d78437b7fe14d09b78b93277b with parent e7825f2, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (25308acc28ea882d78437b7fe14d09b78b93277b): comparison url.

Summary: This change led to large relevant regressions 😿 in compiler performance.

  • Large regression in instruction counts (up to 4.5% on full builds of cranelift-codegen doc)

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

@petrochenkov
Copy link
Contributor Author

petrochenkov commented Jan 25, 2022

Would it be possible to save the results of traits_in_scope in metadata or would it be too big?

This #88679 (comment) is the result of implementing that suggestion.
So it's possible to significantly reduce the overhead this way.

I'll save the optimization on a branch (https://github.com/petrochenkov/rust/tree/doctrscope4), but I don't want to land it now, because this PR is an intermediate step and I want to finish the whole resolver cloning removal before starting to encode more data for rustdoc, maybe we'll have different bottlenecks and need a different set of data in the end.

This eliminates one more late use of resolver
@camelid
Copy link
Member

camelid commented Jan 25, 2022

I still feel a bit uncomfortable with landing such a large regression, but I won't block this since I understand that it's an important refactoring. I'll let Guillaume take it from here.

@GuillaumeGomez
Copy link
Member

@petrochenkov Let's go with this then. Can you open an issue with the next steps please (with explanations too, it'd be very much appreciated!). Once done, r=me. Thanks a lot for working on this!

@petrochenkov
Copy link
Contributor Author

@GuillaumeGomez
#83761 is the issue, #83761 (comment) is the next step.

@bors r=GuillaumeGomez

@bors
Copy link
Collaborator

bors commented Jan 26, 2022

📌 Commit 00ba815 has been approved by GuillaumeGomez

@bors
Copy link
Collaborator

bors commented Jan 26, 2022

⌛ Testing commit 00ba815 with merge 788b1fe...

@bors
Copy link
Collaborator

bors commented Jan 26, 2022

☀️ Test successful - checks-actions
Approved by: GuillaumeGomez
Pushing 788b1fe to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (788b1fe): comparison url.

Summary: This benchmark run shows 43 relevant regressions 😿 to instruction counts.

  • Average relevant regression: 5.4%
  • Largest regression in instruction counts: 9.1% on full builds of regression-31157 doc

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

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

@trevyn
Copy link
Contributor

trevyn commented Jan 28, 2022

@petrochenkov FYI, this seems to have broken one of my nightly CI runs, not sure if that's expected:

https://github.com/trevyn/turbosql/runs/4960657119?check_suite_focus=true

 Documenting turbosql-impl v0.4.0 (/home/runner/work/turbosql/turbosql/turbosql-impl)
Error: thread 'rustc' panicked at 'no entry found for key', src/librustdoc/passes/collect_intra_doc_links.rs:929:16
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

error: Unrecognized option: 'crate-version'

error: could not document `turbosql-impl`

@petrochenkov
Copy link
Contributor Author

@trevyn
Could you make a minimized self-contained reproduction?
I'll look at this tomorrow, and having such a reproduction would make it much faster.

@trevyn
Copy link
Contributor

trevyn commented Jan 28, 2022

Ok, apparently this is enough to trigger it on my side, not sure I feel like minimizing rusqlite right now:

Cargo.toml:

[package]
edition = "2018"
name = "test"
version = "0.1.0"

[dependencies]
rusqlite = "0.26"

lib.rs:

use rusqlite;

@jyn514
Copy link
Member

jyn514 commented Jan 28, 2022

@petrochenkov #93428

@petrochenkov
Copy link
Contributor Author

The panic in #88679 (comment) happens because an inherent impl from rusqlite (impl Connection from mod busy) gets inlined into the current crate.

How is that even possible?
If I remove the doc link to make the documentation process to succeed, then that impl is not even in the generated documentation.

@camelid
Copy link
Member

camelid commented Jan 29, 2022

I think it would happen if Connection was inlined. Is Connection inlined?

@petrochenkov
Copy link
Contributor Author

Maybe it's inlined internally, but it doesn't end up in the generated doc.
The documented crate in #88679 (comment) is just a single private import (it doesn't reexport Connection in particular), nothing should be inlined in that case.

@camelid
Copy link
Member

camelid commented Jan 31, 2022

Weird. I have no idea why that impl is being inlined then.

@petrochenkov
Copy link
Contributor Author

I didn't figure out why that specific impl was inlined, but there are legitimate cases where inherent impls are inlined correctly, but traits in scope are not collected for them:

// Dependency crate

#[derive(Clone)]
pub struct PublicStruct;

mod inner {
    use super::PublicStruct;

    impl PublicStruct {
        /// [PublicStruct::clone]
        pub fn method() {}
    }
}
// Main crate

pub use dependency::PublicStruct;

@petrochenkov
Copy link
Contributor Author

Both cases (#88679 (comment) and #88679 (comment)) are fixed in #93539.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-resolve Area: Name/path resolution done by `rustc_resolve` specifically merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. 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.