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: Start cleaning up search index generation #92340

Merged
merged 8 commits into from
Dec 29, 2021

Conversation

camelid
Copy link
Member

@camelid camelid commented Dec 28, 2021

I'm trying to simplify and clean up the code, partly to make #90779 easier.

r? @GuillaumeGomez

The old name wasn't very clear, while the new one makes it clear that
this is the code responsible for creating the search index.
Based on
rust-lang#80883 (comment).
The `tcx` parameters do seem to be used though, so I only removed the
`cache` parameters.
It was previously defined in `render::search_index` but wasn't used at
all there. `clean::types` seems like a better fit since that's where
`ExternalCrate` is defined.
Now the only two crate-public items are `build_index` and
`get_index_search_type` (because for some reason the latter is also used
in `formats::cache`).
@camelid camelid added A-rustdoc-search Area: Rustdoc's search feature C-cleanup Category: PRs that clean code up or issues documenting cleanup. labels Dec 28, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in clean/types.rs.

cc @camelid

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 28, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 28, 2021
@camelid
Copy link
Member Author

camelid commented Dec 28, 2021

I recommend reviewing this commit-by-commit.

) {
fn insert_ty(
res: &mut Vec<TypeWithKind>,
tcx: TyCtxt<'_>,
ty: Type,
mut generics: Vec<TypeWithKind>,
_cache: &Cache,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is the right move because of:

} else if let Some(kind) = ty.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) {

We are replacing def_id_no_primitives calls, so we need to keep the Cache.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I see what you mean, but the Cache can easily be re-added later. As of now, passing around the Cache is just dead code that might be sitting there for a while.

Copy link
Member

Choose a reason for hiding this comment

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

I reviewed a PR doing exactly that today (but of course, can't find it again...). I'd prefer to avoid having removals/adds following but not sure it matters much since it's just about git history here...

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you're thinking of #92342? I'd rather remove the dead code for now – e.g., that PR may not work and end up being closed, and then the dead code will still be there.

Copy link
Member

Choose a reason for hiding this comment

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

I don't fully agree with you but it's fine. Let's move forward then!

@@ -378,10 +378,12 @@ fn get_real_types<'tcx>(
/// i.e. `fn foo<A: Display, B: Option<A>>(x: u32, y: B)` will return
/// `[u32, Display, Option]`.
fn get_all_types<'tcx>(
generics: &Generics,
decl: &FnDecl,
func: &Function,
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

clean::BorrowedRef { ref type_, .. } => get_index_type_name(type_, accept_generic),
clean::Generic(_)
| clean::BareFunction(_)
clean::BorrowedRef { ref type_, .. } => get_index_type_name(type_),
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

@GuillaumeGomez
Copy link
Member

Overall, this is really great, thanks! Just one change that would be problematic and I think it'd be better to remove it.

@GuillaumeGomez
Copy link
Member

r=me once CI pass.

@rust-log-analyzer

This comment has been minimized.

This issue was fixed using a hacky recursion "fuel" argument, but the
issue was never minimized nor was a regression test added. The
underlying bug is still unfixed, so this test should help with fixing it
and removing the `recurse` hack.
@camelid
Copy link
Member Author

camelid commented Dec 28, 2021

@bors r=GuillaumeGomez

@bors
Copy link
Contributor

bors commented Dec 28, 2021

📌 Commit 908a9d4 has been approved by GuillaumeGomez

@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 Dec 28, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 29, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#92075 (rustdoc: Only special case struct fields for intra-doc links, not enum variants)
 - rust-lang#92118 (Parse and suggest moving where clauses after equals for type aliases)
 - rust-lang#92237 (Visit expressions in-order when resolving pattern bindings)
 - rust-lang#92340 (rustdoc: Start cleaning up search index generation)
 - rust-lang#92351 (Add long error explanation for E0227)
 - rust-lang#92371 (Remove pretty printer space inside block with only outer attrs)
 - rust-lang#92372 (Print space after formal generic params in fn type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0e41194 into rust-lang:master Dec 29, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 29, 2021
@camelid camelid deleted the search-index-cleanup branch December 29, 2021 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-search Area: Rustdoc's search feature C-cleanup Category: PRs that clean code up or issues documenting cleanup. 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.

6 participants