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

Revert "Don't load all extern crates unconditionally" #85749

Merged

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented May 27, 2021

Fixes #84738.

This reverts #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:

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, but it only seems to provide metadata (I went through CStore and CrateMetadata).

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 #68427.

r? @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 27, 2021
@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label May 27, 2021
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the revert-smart-extern-crate-load branch from a9ed792 to 6903f2d Compare May 27, 2021 14:32
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the revert-smart-extern-crate-load branch from 6903f2d to e9dc8c3 Compare May 27, 2021 14:47
@jyn514
Copy link
Member

jyn514 commented May 27, 2021

Please remember to re-open #68427 if this gets merged.

@jyn514
Copy link
Member

jyn514 commented May 27, 2021

I will not have time to review this for a while.

r? @petrochenkov

@rust-highfive rust-highfive assigned petrochenkov and unassigned jyn514 May 27, 2021
@GuillaumeGomez
Copy link
Member Author

Please remember to re-open #68427 if this gets merged.

It's in the first message already. ;)

@jyn514 jyn514 added the A-metadata Area: Crate metadata label May 27, 2021
@petrochenkov
Copy link
Contributor

petrochenkov commented May 30, 2021

I'd prefer to actually fix #84738 instead of reverting the PR and re-introducing other bugs.

Waiting on minimized reproduction for #84738 - https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/crate.20loading.20during.20link.20resolution/near/240747900

@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 May 30, 2021
@GuillaumeGomez GuillaumeGomez 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 Jun 11, 2021
@TheBlueMatt
Copy link

TheBlueMatt commented Jun 17, 2021

Does https://github.com/rust-bitcoin/rust-lightning/blob/main/lightning-background-processor/src/lib.rs qualify as a minimized reproduction? Its only a few method crate and tickles the bug. The version on crates.io hits it.

@petrochenkov
Copy link
Contributor

(I've returned from vacation and will look at this next weekend.)

@GuillaumeGomez
Copy link
Member Author

\o/

@bors
Copy link
Contributor

bors commented Jul 1, 2021

☔ The latest upstream changes (presumably #86489) made this pull request unmergeable. Please resolve the merge conflicts.

@jyn514
Copy link
Member

jyn514 commented Jul 1, 2021

r=me, this has been causing lots of trouble and we can always do a more proper fix later. @GuillaumeGomez can you fix the conflict real quick?

@GuillaumeGomez
Copy link
Member Author

On it!

@jyn514 jyn514 added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 1, 2021
@jyn514 jyn514 self-assigned this Jul 1, 2021
@GuillaumeGomez GuillaumeGomez force-pushed the revert-smart-extern-crate-load branch from e9dc8c3 to 44424a3 Compare July 1, 2021 14:41
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the revert-smart-extern-crate-load branch from 44424a3 to 4188476 Compare July 1, 2021 15:09
@GuillaumeGomez GuillaumeGomez force-pushed the revert-smart-extern-crate-load branch from 5386c93 to 5f0c54d Compare July 1, 2021 16:26
@jyn514
Copy link
Member

jyn514 commented Jul 1, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Jul 1, 2021

📌 Commit 5f0c54d has been approved by jyn514

@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 Jul 1, 2021
@jyn514
Copy link
Member

jyn514 commented Jul 1, 2021

@rust-lang/rustdoc are you ok with backporting this? For context, this fixes a regression from 1.52 to 1.53 (an ICE on code when generating intra doc links). It does reintroduce the bug from #68427, but that's a very narrow edge case I don't expect most people to run into.

@Manishearth
Copy link
Member

I'm okay with the backport

@GuillaumeGomez
Copy link
Member Author

I am as well. I think you can set the label. :)

@jyn514 jyn514 added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jul 1, 2021
@GuillaumeGomez GuillaumeGomez force-pushed the revert-smart-extern-crate-load branch 2 times, most recently from 4181738 to 5f0c54d Compare July 2, 2021 08:43
@GuillaumeGomez
Copy link
Member Author

I erroneously pushed on this branch from another PR so I need to re-approve it.

@bors: r=jyn514

@bors
Copy link
Contributor

bors commented Jul 2, 2021

📌 Commit 5f0c54d has been approved by jyn514

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 2, 2021
…laumeGomez

Rollup of 5 pull requests

Successful merges:

 - rust-lang#85749 (Revert "Don't load all extern crates unconditionally")
 - rust-lang#86714 (Add linked list cursor end methods)
 - rust-lang#86737 (Document rustfmt on nightly-rustc)
 - rust-lang#86776 (Skip layout query when computing integer type size during mangling)
 - rust-lang#86797 (Stabilize `Bound::cloned()`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b7654a3 into rust-lang:master Jul 2, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 2, 2021
@GuillaumeGomez GuillaumeGomez deleted the revert-smart-extern-crate-load branch July 2, 2021 14:28
@cuviper cuviper mentioned this pull request Jul 2, 2021
@cuviper cuviper modified the milestones: 1.55.0, 1.54.0 Jul 2, 2021
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 2, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 2, 2021
[beta] backports

- rustfmt: load nested out-of-line mods correctly rust-lang#86424
- Re-add support for parsing (and pretty-printing) inner-attributes in match body rust-lang#85193
- Revert "List trait impls before methods from deref in the sidebar ..." rust-lang#86564
- Revert "Don't load all extern crates unconditionally" rust-lang#85749

r? `@Mark-Simulacrum`
@camelid
Copy link
Member

camelid commented Jul 4, 2021

It looks like #68427 is still closed?

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 beta-accepted Accepted for backporting to the compiler in the beta channel. 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.

Index out of bounds when running cargo doc in rustc_metadata/src/creader.rs