Skip to content

rustdoc-search: search backend with partitioned suffix tree #144476

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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d832570
rustdoc: redesign toolbar with a separate "Search" button
notriddle Nov 22, 2024
e6eb656
Bump stringdex version with bugfix
notriddle Aug 6, 2025
f5eaae6
Fix incorrect button grab
notriddle Aug 6, 2025
9700a23
Fix styles and
notriddle Aug 7, 2025
918cb29
Fix alignment
notriddle Aug 7, 2025
5eafbb6
Fix another stringdex bug in that heap algo
notriddle Aug 7, 2025
9270ebb
Fix nitpicks and a random perf problem that I found
notriddle Aug 8, 2025
dcf3ac6
Loading throbber
notriddle Aug 8, 2025
19b5e4d
Show loading throbber on the input field during initial load
notriddle Aug 8, 2025
86a58ed
Update src/librustdoc/html/static/js/main.js
notriddle Aug 11, 2025
9b25b0e
Update src/librustdoc/html/static/js/rustdoc.d.ts
notriddle Aug 11, 2025
21c4839
Stop redundantly base64 encoding bitmaps into bytestrings
notriddle Aug 11, 2025
ed454bf
Fix alias and unstable sorting
notriddle Aug 11, 2025
dc2015c
rustdoc-search: sort typ-based inverted indexes by length
notriddle Aug 11, 2025
36d10b6
rustdoc-search: address getAliasPointer nit
notriddle Aug 12, 2025
8ca6716
rustdoc-search: address typescript nit
notriddle Aug 12, 2025
6cb1081
rustdoc-search: remove pointless branch from getFunctionData
notriddle Aug 12, 2025
1cb4274
Upgrade buggy stringdex decoder
notriddle Aug 12, 2025
249e54f
Factor search process out to a function
notriddle Aug 12, 2025
e0cc467
Update src/librustdoc/html/static/js/search.js
notriddle Aug 12, 2025
16b4ccc
Fix typescript error
notriddle Aug 12, 2025
3c93f68
rustdoc-search: prevent struct fields from blocking functions
notriddle Aug 13, 2025
59a9236
Fix bug where three tabs are show, only one matters
notriddle Aug 13, 2025
fa5468d
Avoid redundant loading
notriddle Aug 13, 2025
fb52fe0
Remove outdated comment
notriddle Aug 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4811,6 +4811,7 @@ dependencies = [
"serde_json",
"sha2",
"smallvec",
"stringdex",
"tempfile",
"threadpool",
"tracing",
Expand Down Expand Up @@ -5224,6 +5225,15 @@ dependencies = [
"quote",
]

[[package]]
name = "stringdex"
version = "0.0.1-alpha4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2841fd43df5b1ff1b042e167068a1fe9b163dc93041eae56ab2296859013a9a0"
dependencies = [
"stacker",
]

[[package]]
name = "strsim"
version = "0.11.1"
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/tidy/eslint.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.6.0
8.57.1
6 changes: 6 additions & 0 deletions src/etc/htmldocck.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import re
import shlex
from collections import namedtuple
from pathlib import Path

try:
from html.parser import HTMLParser
Expand Down Expand Up @@ -242,6 +243,11 @@ def resolve_path(self, path):
return self.last_path

def get_absolute_path(self, path):
if "*" in path:
paths = list(Path(self.root).glob(path))
if len(paths) != 1:
raise FailedCheck("glob path does not resolve to one file")
path = str(paths[0])
return os.path.join(self.root, path)

def get_file(self, path):
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rustdoc-json-types = { path = "../rustdoc-json-types" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
smallvec = "1.8.1"
stringdex = { version = "0.0.1-alpha4" }
tempfile = "3"
threadpool = "1.8.1"
tracing = "0.1"
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn main() {
"static/css/normalize.css",
"static/js/main.js",
"static/js/search.js",
"static/js/stringdex.js",
"static/js/settings.js",
"static/js/src-script.js",
"static/js/storage.js",
Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::mem;

use rustc_ast::join_path_syms;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_hir::StabilityLevel;
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet};
Expand Down Expand Up @@ -574,7 +573,6 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
clean::ItemKind::ImportItem(import) => import.source.did.unwrap_or(item_def_id),
_ => item_def_id,
};
let path = join_path_syms(parent_path);
let impl_id = if let Some(ParentStackItem::Impl { item_id, .. }) = cache.parent_stack.last() {
item_id.as_def_id()
} else {
Expand All @@ -593,11 +591,11 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
ty: item.type_(),
defid: Some(defid),
name,
path,
module_path: parent_path.to_vec(),
desc,
parent: parent_did,
parent_idx: None,
exact_path: None,
exact_module_path: None,
impl_id,
search_type,
aliases,
Expand Down
52 changes: 51 additions & 1 deletion src/librustdoc/formats/item_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;

use rustc_hir::def::{CtorOf, DefKind};
use rustc_span::hygiene::MacroKind;
use serde::{Serialize, Serializer};
use serde::{Deserialize, Deserializer, Serialize, Serializer, de};

use crate::clean;

Expand Down Expand Up @@ -68,6 +68,52 @@ impl Serialize for ItemType {
}
}

impl<'de> Deserialize<'de> for ItemType {
fn deserialize<D>(deserializer: D) -> Result<ItemType, D::Error>
where
D: Deserializer<'de>,
{
struct ItemTypeVisitor;
impl<'de> de::Visitor<'de> for ItemTypeVisitor {
type Value = ItemType;
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "an integer between 0 and 25")
}
fn visit_u64<E: de::Error>(self, v: u64) -> Result<ItemType, E> {
Ok(match v {
0 => ItemType::Keyword,
1 => ItemType::Primitive,
2 => ItemType::Module,
3 => ItemType::ExternCrate,
4 => ItemType::Import,
5 => ItemType::Struct,
6 => ItemType::Enum,
7 => ItemType::Function,
8 => ItemType::TypeAlias,
9 => ItemType::Static,
10 => ItemType::Trait,
11 => ItemType::Impl,
12 => ItemType::TyMethod,
13 => ItemType::Method,
14 => ItemType::StructField,
15 => ItemType::Variant,
16 => ItemType::Macro,
17 => ItemType::AssocType,
18 => ItemType::Constant,
19 => ItemType::AssocConst,
20 => ItemType::Union,
21 => ItemType::ForeignType,
23 => ItemType::ProcAttribute,
24 => ItemType::ProcDerive,
25 => ItemType::TraitAlias,
_ => return Err(E::missing_field("unknown number")),
})
}
}
deserializer.deserialize_any(ItemTypeVisitor)
}
}

impl<'a> From<&'a clean::Item> for ItemType {
fn from(item: &'a clean::Item) -> ItemType {
let kind = match &item.kind {
Expand Down Expand Up @@ -197,6 +243,10 @@ impl ItemType {
pub(crate) fn is_adt(&self) -> bool {
matches!(self, ItemType::Struct | ItemType::Union | ItemType::Enum)
}
/// Keep this the same as isFnLikeTy in search.js
pub(crate) fn is_fn_like(&self) -> bool {
matches!(self, ItemType::Function | ItemType::Method | ItemType::TyMethod)
}
}

impl fmt::Display for ItemType {
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) struct Layout {

pub(crate) struct Page<'a> {
pub(crate) title: &'a str,
pub(crate) short_title: &'a str,
pub(crate) css_class: &'a str,
pub(crate) root_path: &'a str,
pub(crate) static_root_path: Option<&'a str>,
Expand Down
14 changes: 14 additions & 0 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ impl<'tcx> Context<'tcx> {
if !is_module {
title.push_str(it.name.unwrap().as_str());
}
let short_title;
let short_title = if is_module {
let module_name = self.current.last().unwrap();
short_title = if it.is_crate() {
format!("Crate {module_name}")
} else {
format!("Module {module_name}")
};
&short_title[..]
} else {
it.name.as_ref().unwrap().as_str()
};
if !it.is_primitive() && !it.is_keyword() {
if !is_module {
title.push_str(" in ");
Expand Down Expand Up @@ -240,6 +252,7 @@ impl<'tcx> Context<'tcx> {
root_path: &self.root_path(),
static_root_path: self.shared.static_root_path.as_deref(),
title: &title,
short_title,
description: &desc,
resource_suffix: &self.shared.resource_suffix,
rust_logo: has_doc_flag(self.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
Expand Down Expand Up @@ -617,6 +630,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
let shared = &self.shared;
let mut page = layout::Page {
title: "List of all items in this crate",
short_title: "All",
css_class: "mod sys",
root_path: "../",
static_root_path: shared.static_root_path.as_deref(),
Expand Down
Loading
Loading