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: Don't load all extern crates unconditionally #83738

Merged
merged 1 commit into from
Apr 3, 2021

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Apr 1, 2021

Instead, only load the crates that are linked to with intra-doc links.

This doesn't help very much with any of rustdoc's fundamental issues
with freezing the resolver, but it at least fixes a stable-to-stable
regression, and makes the crate loading model somewhat more consistent
with rustc's. I tested and it unfortunately does not help at all with #82496.

Closes #68427. Opened #83761 to track the more fundamental issues.
r? @petrochenkov cc @eddyb @ollie27

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-resolve Area: Name resolution A-metadata Area: Crate metadata labels Apr 1, 2021
@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 Apr 1, 2021
@jyn514 jyn514 force-pushed the only-load-some-crates branch from e10e1dc to 4b0178b Compare April 1, 2021 03:06
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jyn514 jyn514 force-pushed the only-load-some-crates branch from 36d6800 to 3d0961e Compare April 1, 2021 13:39
src/test/run-make/unused-extern-crate/panic-item.rs Outdated Show resolved Hide resolved
Err(_) => continue,
};
self.resolver.borrow_mut().access(|resolver| {
let _ = resolver.resolve_str_path_error(
Copy link
Contributor

Choose a reason for hiding this comment

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

If you save the resolution results for later instead of throwing them away, then you'll no longer need the resolver later on.
That's basically the idea behind fixing the resolver cloning/freezing issue.

@petrochenkov
Copy link
Contributor

Let me know if you want me to open a separate issue for not freezing the resolver.

Yes, could you create the issue?
The fix is to pretty much do what this PR does but more extensively - resolve everything that needs to be resolved early and save the results for later.
Once Resolver::clone_outputs is removed the problem can be considered fixed.

@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 Apr 1, 2021
@jyn514 jyn514 force-pushed the only-load-some-crates branch from 3d0961e to cc69c65 Compare April 1, 2021 21:57
@jyn514
Copy link
Member Author

jyn514 commented Apr 1, 2021

Yes, could you create the issue?

Sure thing, I opened #83761. I left a question about the approach, but it's not related to this PR.

@jyn514 jyn514 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 Apr 1, 2021
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Apr 2, 2021

📌 Commit cc69c65 has been approved by petrochenkov

@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 Apr 2, 2021
@jyn514 jyn514 mentioned this pull request Apr 2, 2021
6 tasks
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Apr 2, 2021
…rochenkov

rustdoc: Don't load all extern crates unconditionally

Instead, only load the crates that are linked to with intra-doc links.

This doesn't help very much with any of rustdoc's fundamental issues
with freezing the resolver, but it at least fixes a stable-to-stable
regression, and makes the crate loading model somewhat more consistent
with rustc's. I tested and it unfortunately does not help at all with rust-lang#82496.

Closes rust-lang#68427. Let me know if you want me to open a separate issue for not freezing the resolver.
r? `@petrochenkov` cc `@eddyb` `@ollie27`
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Apr 2, 2021
…rochenkov

rustdoc: Don't load all extern crates unconditionally

Instead, only load the crates that are linked to with intra-doc links.

This doesn't help very much with any of rustdoc's fundamental issues
with freezing the resolver, but it at least fixes a stable-to-stable
regression, and makes the crate loading model somewhat more consistent
with rustc's. I tested and it unfortunately does not help at all with rust-lang#82496.

Closes rust-lang#68427. Let me know if you want me to open a separate issue for not freezing the resolver.
r? ``@petrochenkov`` cc ``@eddyb`` ``@ollie27``
@jyn514
Copy link
Member Author

jyn514 commented Apr 2, 2021

Ok, I added that. Not sure how to test it worked from linux. I also had to add crate_type = "lib" or it gave a weird error about conflicting outputs:

error: the generated executable for the input file "/home/joshua/rustc3/src/test/rustdoc-ui/auxiliary/panic-item.rs" conflicts with the existing directory "/home/joshua/rustc3/build/x86_64-unknown-linux-gnu/test/rustdoc-ui/unused-extern-crate/auxiliary/panic-item"

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Apr 3, 2021

📌 Commit e4244e3 has been approved by petrochenkov

@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 Apr 3, 2021
@bors
Copy link
Contributor

bors commented Apr 3, 2021

⌛ Testing commit e4244e3 with merge 640ce99...

@bors
Copy link
Contributor

bors commented Apr 3, 2021

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 640ce99 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 3, 2021
@bors bors merged commit 640ce99 into rust-lang:master Apr 3, 2021
@rustbot rustbot added this to the 1.53.0 milestone Apr 3, 2021
@jyn514 jyn514 deleted the only-load-some-crates branch April 3, 2021 15:25
@klensy
Copy link
Contributor

klensy commented Apr 4, 2021

@jyn514
Copy link
Member Author

jyn514 commented Apr 4, 2021

@klensy this is a bug fix - it doesn't really matter what the performance is as long as it's not a giant regression. Cargo is probably lower because it has a lot of --extern crates that no longer need to be loaded.

@klensy
Copy link
Contributor

klensy commented Apr 4, 2021

@jyn514 No, i mean, look at -doc full builds: for cargo-doc there some changes in executions delta column, but literally zero changes for others in that column (didn't checked all of them).

@jyn514
Copy link
Member Author

jyn514 commented Apr 4, 2021

I don't understand what you're trying to tell me. On the "detailed self profile results" page I see no change in time, which is what I'd expect from this PR. If there's an inconsistency between that and instructions that sounds like an issue with perf.rlo, I think there's some ongoing work to measure instructions for self-profile.

@Mark-Simulacrum
Copy link
Member

Those runs suggest that there is some difference in the documented code for cargo and clap-rs, and this particular PR sees a larger improvement in terms of less queries being run on the cargo benchmark (compared to the other ones you've cited). That's not really a problem, it's pretty intentional that our benchmarks differ in what they look like to the compiler (otherwise there'd be no point in having two different ones) -- I'm trying to understand what problem or note you're trying to make :)

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 2, 2021
…crate-load, r=jyn514

Revert "Don't load all extern crates unconditionally"

Fixes rust-lang#84738.

This reverts rust-lang#83738.

For the "smart" load of external crates, we need to be able to access their items in order to check their doc comments, which seems, if not impossible, quite complicated using only the AST.

For some context, I first tried to extend the `IntraLinkCrateLoader` visitor by adding `visit_foreign_item`. Unfortunately, it never enters into this call, so definitely not the right place...

I then added `visit_use_tree` to then check all the imports outside with something like this:

```rust
let mut loader = crate::passes::collect_intra_doc_links::IntraLinkCrateLoader::new(resolver);
    ast::visit::walk_crate(&mut loader, krate);

    let mut items = Vec::new();
    for import in &loader.imports_to_check {
        if let Some(item) = krate.items.iter().find(|i| i.id == *import) {
            items.push(item);
        }
    }
    for item in items {
        ast::visit::walk_item(&mut item);
        for attr in &item.attrs {
            loader.check_attribute(attr);
        }
    }
```

This was, of course, a failure. We find the items without problems, but we still can't go into the external crate to check its items' attributes.

Finally, `@jyn514` suggested to look into the [`CrateLoader`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_metadata/creader/struct.CrateLoader.html), but it only seems to provide metadata (I went through [`CStore`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_metadata/creader/struct.CStore.html) and [`CrateMetadata`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_metadata/rmeta/decoder/struct.CrateMetadata.html)).

I think we are too limited here (with AST only) to be able to determine the crates we actually need to import, but it's very likely that I missed something. Maybe `@petrochenkov` or `@Aaron1011` have an idea?

So until we find a way to make it work completely, we need to revert it to fix the ICE. Once merged, we'll need to re-open rust-lang#68427.

r? `@jyn514`
Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 26, 2021
Reland rust-lang#83738: "rustdoc: Don't load all extern crates unconditionally"

I hopefully found all the bugs 🤞 time for a take two. See the last commit for details on what went wrong before.

r? `@petrochenkov` (but feel free to reassign to Guillaume if you don't have time.)

Closes rust-lang#68427. Includes a fix for rust-lang#84738.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 27, 2021
…arth

Rollup of 11 pull requests

Successful merges:

 - rust-lang#87832 (Fix debugger stepping behavior with `match` expressions)
 - rust-lang#88123 (Make spans for tuple patterns in E0023 more precise)
 - rust-lang#88215 (Reland rust-lang#83738: "rustdoc: Don't load all extern crates unconditionally")
 - rust-lang#88216 (Don't stabilize creation of TryReserveError instances)
 - rust-lang#88270 (Handle type ascription type ops in NLL HRTB diagnostics)
 - rust-lang#88289 (Fixes for LLVM change 0f45c16)
 - rust-lang#88320 (type_implements_trait consider obligation failure on overflow)
 - rust-lang#88332 (Add argument types tait tests)
 - rust-lang#88340 (Add `c_size_t` and `c_ssize_t` to `std::os::raw`.)
 - rust-lang#88346 (Revert "Add type of a let tait test impl trait straight in let")
 - rust-lang#88348 (Add field types tait tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 11, 2021
…trochenkov

rustdoc: Go back to loading all external crates unconditionally

This *continues* to cause regressions. This code will be unnecessary
once access to the resolver happens fully before creating the tyctxt
(rust-lang#83761), so load all crates unconditionally for now. To minimize churn, this leaves in the code for loading crates selectively.

"Fixes" rust-lang#84738. Previously: rust-lang#83738, rust-lang#85749, rust-lang#88215

r? `@petrochenkov` cc `@camelid` (this should fix the "index out of bounds" error you had while looking up `crate_name`).
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 11, 2021
…ochenkov

rustdoc: Go back to loading all external crates unconditionally

This *continues* to cause regressions. This code will be unnecessary
once access to the resolver happens fully before creating the tyctxt
(rust-lang#83761), so load all crates unconditionally for now. To minimize churn, this leaves in the code for loading crates selectively.

"Fixes" rust-lang#84738. Previously: rust-lang#83738, rust-lang#85749, rust-lang#88215

r? `@petrochenkov` cc `@camelid` (this should fix the "index out of bounds" error you had while looking up `crate_name`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-metadata Area: Crate metadata A-resolve Area: Name resolution 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.

rustdoc only: duplicate lang item panic_halt
9 participants