Skip to content

Commit 0680d6b

Browse files
authored
rustdoc: docs for search deduplication (rust-lang#1850)
1 parent 43b743c commit 0680d6b

File tree

1 file changed

+73
-3
lines changed
  • src/doc/rustc-dev-guide/src/rustdoc-internals

1 file changed

+73
-3
lines changed

src/doc/rustc-dev-guide/src/rustdoc-internals/search.md

+73-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ For space savings, it's also written without newlines or spaces.
2626
"q": [[0, "crate_name"]],
2727
// parent type
2828
"i": [2, 0],
29+
// type dictionary
30+
"p": [[1, "i32"], [1, "str"], [5, "Data", 0]],
2931
// function signature
3032
"f": "{{gb}{d}}`", // [[3, 1], [2]]
3133
// impl disambiguator
@@ -34,12 +36,12 @@ For space savings, it's also written without newlines or spaces.
3436
"c": "OjAAAAAAAAA=", // empty bitmap
3537
// empty description flag
3638
"e": "OjAAAAAAAAA=", // empty bitmap
37-
// type dictionary
38-
"p": [[1, "i32"], [1, "str"], [5, "crate_name::Data"]],
3939
// aliases
4040
"a": [["get_name", 0]],
4141
// description shards
4242
"D": "g", // 3
43+
// inlined re-exports
44+
"r": [],
4345
}]
4446
]
4547
```
@@ -355,6 +357,74 @@ The bloom filter checks none of these things,
355357
and, on top of that, can have false positives.
356358
But it's fast and uses very little memory, so the bloom filter helps.
357359

360+
## Re-exports
361+
362+
[Re-export inlining] allows the same item to be found by multiple names.
363+
Search supports this by giving the same item multiple entries and tracking a canonical path
364+
for any items where that differs from the given path.
365+
366+
For example, this sample index has a single struct exported from two paths:
367+
368+
```json
369+
[
370+
[ "crate_name", {
371+
"doc": "Documentation",
372+
"n": ["Data", "Data"],
373+
"t": "FF",
374+
"d": ["The data struct", "The data struct"],
375+
"q": [[0, "crate_name"], [1, "crate_name::submodule"]],
376+
"i": [0, 0],
377+
"p": [],
378+
"f": "``",
379+
"b": [],
380+
"c": [],
381+
"a": [],
382+
"r": [[0, 1]],
383+
}]
384+
]
385+
```
386+
387+
The important part of this example is the `r` array,
388+
which indicates that path entry 1 in the `q` array is
389+
the canonical path for item 0.
390+
That is, `crate_name::Data` has a canonical path of `crate_name::submodule::Data`.
391+
392+
This might sound like a strange design, since it has the duplicate data.
393+
It's done that way because inlining can happen across crates,
394+
which are compiled separately and might not all be present in the docs.
395+
396+
```json
397+
[
398+
[ "crate_name", ... ],
399+
[ "crate_name_2", { "q": [[0, "crate_name::submodule"], [5, "core::option"]], ... }]
400+
]
401+
```
402+
403+
In the above example, a canonical path actually comes from a dependency,
404+
and another one comes from an inlined standard library item:
405+
the canonical path isn't even in the index!
406+
The canonical path might also be private.
407+
In either case, it's never shown to the user, and is only used for deduplication.
408+
409+
Associated types, like methods, store them differently.
410+
These types are connected with an entry in `p` (their "parent")
411+
and each one has an optional third tuple element:
412+
413+
"p": [[5, "Data", 0, 1]]
414+
415+
That's:
416+
417+
- 5: It's a struct
418+
- "Data": Its name
419+
- 0: Its display path, "crate_name"
420+
- 1: Its canonical path, "crate_name::submodule"
421+
422+
In both cases, the canonical path might not be public at all,
423+
or it might be from another crate that isn't in the docs,
424+
so it's never shown to the user, but is used for deduplication.
425+
426+
[Re-export inlining]: https://doc.rust-lang.org/nightly/rustdoc/write-documentation/re-exports.html
427+
358428
## Testing the search engine
359429

360430
While the generated UI is tested using `rustdoc-gui` tests, the
@@ -453,4 +523,4 @@ const EXPECTED = [
453523
returned: [],
454524
},
455525
]
456-
```
526+
```

0 commit comments

Comments
 (0)