rustdoc: Cleanup CacheBuilder code for building search index#128578
Merged
bors merged 7 commits intorust-lang:masterfrom Aug 4, 2024
Merged
rustdoc: Cleanup CacheBuilder code for building search index#128578bors merged 7 commits intorust-lang:masterfrom
CacheBuilder code for building search index#128578bors merged 7 commits intorust-lang:masterfrom
Conversation
Many of the code paths it handled were actually impossible. In other cases, the various checks and transformations were spread around in such a way that it was hard to tell what was going on.
0f96d56 to
220c2d8
Compare
Member
Author
|
I realized that these changes are actually completely independent, so this is no longer based on the |
This comment has been minimized.
This comment has been minimized.
Member
Author
|
Well that's weird... those tests passed locally. |
notriddle
reviewed
Aug 3, 2024
Contributor
notriddle
left a comment
There was a problem hiding this comment.
Here's a suggested fix, along with a much longer comment for a remaining, ugly fact of the search engine builder:
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index d2d0f5a4380..6454bc58cd6 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -486,10 +486,26 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
ParentStackItem::Type(item_id) => item_id.as_def_id(),
};
let Some(parent_did) = parent_did else { return };
- // The current stack not necessarily has correlation
- // for where the type was defined. On the other
- // hand, `paths` always has the right
- // information if present.
+ // The current stack reflects the CacheBuilder's recursive
+ // walk over HIR. For associated items, this is the module
+ // where the `impl` block is defined. That's an implementation
+ // detail that we don't want to affect the search engine.
+ //
+ // In particular, you can arrange things like this:
+ //
+ // #![crate_name="me"]
+ // mod private_mod {
+ // impl Clone for MyThing { fn clone(&self) -> MyThing { MyThing } }
+ // }
+ // pub struct MyThing;
+ //
+ // When that happens, we need to:
+ // - ignore the `cache.stripped_mod` flag, since the Clone impl is actually
+ // part of the public API even though it's defined in a private module
+ // - present the method as `me::MyThing::clone`, its publicly-visible path
+ // - deal with the fact that the recursive walk hasn't actually reached `MyThing`
+ // until it's already past `private_mod`, since that's first, and doesn't know
+ // yet if `MyThing` will actually be public or not (it could be re-exported)
match cache.paths.get(&parent_did) {
Some((fqp, _)) => (Some(parent_did), &fqp[..fqp.len() - 1]),
None => {
@@ -500,7 +516,8 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
}
_ => {
// Don't index if item is crate root, which is inserted later on when serializing the index.
- if item_def_id.is_crate_root() {
+ // Don't index if containing module is stripped (i.e., private),
+ if item_def_id.is_crate_root() || cache.stripped_mod {
return;
}
(None, &*cache.stack)Co-authored-by: Michael Howell <michael@notriddle.com>
Contributor
|
@bors r+ |
Collaborator
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Aug 4, 2024
…riddle rustdoc: Cleanup `CacheBuilder` code for building search index This code was very convoluted and hard to reason about. It is now (I hope) much clearer and more suitable for both future enhancements and future cleanups. I'm doing this as a precursor, with no UI changes, to changing rustdoc to [ignore blanket impls][1] in type-based search. [1]: rust-lang#128471 (comment) r? `@notriddle`
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Aug 4, 2024
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#128362 (add test for symbol visibility of `#[naked]` functions) - rust-lang#128526 (time.rs: remove "Basic usage text") - rust-lang#128531 (Miri: add a flag to do recursive validity checking) - rust-lang#128578 (rustdoc: Cleanup `CacheBuilder` code for building search index) - rust-lang#128589 (allow setting `link-shared` and `static-libstdcpp` with CI LLVM) - rust-lang#128615 (rustdoc: make the hover trail for doc anchors a bit bigger) - rust-lang#128620 (Update rinja version to 0.3.0) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Aug 4, 2024
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#128305 (improve error message when `global_asm!` uses `asm!` operands) - rust-lang#128526 (time.rs: remove "Basic usage text") - rust-lang#128531 (Miri: add a flag to do recursive validity checking) - rust-lang#128578 (rustdoc: Cleanup `CacheBuilder` code for building search index) - rust-lang#128589 (allow setting `link-shared` and `static-libstdcpp` with CI LLVM) - rust-lang#128615 (rustdoc: make the hover trail for doc anchors a bit bigger) - rust-lang#128620 (Update rinja version to 0.3.0) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Aug 4, 2024
Rollup merge of rust-lang#128578 - camelid:cache-index-cleanup, r=notriddle rustdoc: Cleanup `CacheBuilder` code for building search index This code was very convoluted and hard to reason about. It is now (I hope) much clearer and more suitable for both future enhancements and future cleanups. I'm doing this as a precursor, with no UI changes, to changing rustdoc to [ignore blanket impls][1] in type-based search. [1]: rust-lang#128471 (comment) r? ``@notriddle``
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This code was very convoluted and hard to reason about. It is now (I hope) much
clearer and more suitable for both future enhancements and future cleanups.
I'm doing this as a precursor, with no UI changes, to changing rustdoc to
ignore blanket impls in type-based search.
r? @notriddle