Skip to content

Commit

Permalink
Rollup merge of rust-lang#80047 - jyn514:more-symbols, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Use more symbols in rustdoc

Builds on rust-lang#80044 and should not be merged before.

I want to test if this is actually faster before merging it, there was a lot of `to_string()` calls so I'm not sure it will actually help. That means I have to wait for 80044 to get merged before running perf.

r? `@ghost`
  • Loading branch information
GuillaumeGomez authored Dec 17, 2020
2 parents 1f5d8de + 7ee8e18 commit 5873fe8
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl Clean<ExternalCrate> for CrateNum {
};

ExternalCrate {
name: cx.tcx.crate_name(*self).to_string(),
name: cx.tcx.crate_name(*self),
src: krate_src,
attrs: cx.tcx.get_attrs(root).clean(cx),
primitives,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ thread_local!(crate static MAX_DEF_ID: RefCell<FxHashMap<CrateNum, DefId>> = Def

#[derive(Clone, Debug)]
crate struct Crate {
crate name: String,
crate name: Symbol,
crate version: Option<String>,
crate src: FileName,
crate module: Option<Item>,
Expand All @@ -66,7 +66,7 @@ crate struct Crate {

#[derive(Clone, Debug)]
crate struct ExternalCrate {
crate name: String,
crate name: Symbol,
crate src: FileName,
crate attrs: Attributes,
crate primitives: Vec<(DefId, PrimitiveType)>,
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
use rustc_middle::middle::privacy::AccessLevels;
use rustc_span::source_map::FileName;
use rustc_span::Symbol;

use crate::clean::{self, GetDefId};
use crate::config::RenderInfo;
Expand Down Expand Up @@ -74,7 +75,7 @@ crate struct Cache {
crate implementors: FxHashMap<DefId, Vec<Impl>>,

/// Cache of where external crate documentation can be found.
crate extern_locations: FxHashMap<CrateNum, (String, PathBuf, ExternalLocation)>,
crate extern_locations: FxHashMap<CrateNum, (Symbol, PathBuf, ExternalLocation)>,

/// Cache of where documentation for primitives can be found.
crate primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,
Expand Down Expand Up @@ -173,10 +174,10 @@ impl Cache {
},
_ => PathBuf::new(),
};
let extern_url = extern_html_root_urls.get(&e.name).map(|u| &**u);
let extern_url = extern_html_root_urls.get(&*e.name.as_str()).map(|u| &**u);
cache
.extern_locations
.insert(n, (e.name.clone(), src_root, extern_location(e, extern_url, &dst)));
.insert(n, (e.name, src_root, extern_location(e, extern_url, &dst)));

let did = DefId { krate: n, index: CRATE_DEF_INDEX };
cache.external_paths.insert(did, (vec![e.name.to_string()], ItemType::Module));
Expand All @@ -195,7 +196,7 @@ impl Cache {
cache.primitive_locations.insert(prim, def_id);
}

cache.stack.push(krate.name.clone());
cache.stack.push(krate.name.to_string());
krate = cache.fold_crate(krate);

for (trait_did, dids, impl_) in cache.orphan_trait_impls.drain(..) {
Expand Down Expand Up @@ -340,7 +341,7 @@ impl DocFolder for Cache {

// Keep track of the fully qualified path for this item.
let pushed = match item.name {
Some(ref n) if !n.is_empty() => {
Some(n) if !n.is_empty() => {
self.stack.push(n.to_string());
true
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::sync::Arc;
use rustc_data_structures::sync::Lrc;
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::Symbol;

use crate::clean;
use crate::config::{RenderInfo, RenderOptions};
Expand Down Expand Up @@ -76,7 +75,7 @@ crate fn run_format<T: FormatRenderer>(
None => return Ok(()),
};

item.name = Some(Symbol::intern(&krate.name));
item.name = Some(krate.name);

// Render the crate documentation
let mut work = vec![(format_renderer.clone(), item)];
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ crate fn extern_location(
) -> ExternalLocation {
use ExternalLocation::*;
// See if there's documentation generated into the local directory
let local_location = dst.join(&e.name);
let local_location = dst.join(&*e.name.as_str());
if local_location.is_dir() {
return Local;
}
Expand Down
28 changes: 16 additions & 12 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,15 @@ impl FormatRenderer for Context {
// If user passed in `--playground-url` arg, we fill in crate name here
let mut playground = None;
if let Some(url) = playground_url {
playground = Some(markdown::Playground { crate_name: Some(krate.name.clone()), url });
playground =
Some(markdown::Playground { crate_name: Some(krate.name.to_string()), url });
}
let mut layout = layout::Layout {
logo: String::new(),
favicon: String::new(),
external_html,
default_settings,
krate: krate.name.clone(),
krate: krate.name.to_string(),
css_file_extension: extension_css,
generate_search_filter,
};
Expand All @@ -445,7 +446,7 @@ impl FormatRenderer for Context {
}
(sym::html_playground_url, Some(s)) => {
playground = Some(markdown::Playground {
crate_name: Some(krate.name.clone()),
crate_name: Some(krate.name.to_string()),
url: s.to_string(),
});
}
Expand Down Expand Up @@ -530,7 +531,7 @@ impl FormatRenderer for Context {
}

fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
let final_file = self.dst.join(&krate.name).join("all.html");
let final_file = self.dst.join(&*krate.name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");
let crate_name = krate.name.clone();

Expand Down Expand Up @@ -1019,7 +1020,8 @@ themePicker.onblur = handleThemeButtonsBlur;
}

let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
let (mut all_sources, _krates) = try_err!(collect(&dst, &krate.name, "sourcesIndex"), &dst);
let (mut all_sources, _krates) =
try_err!(collect(&dst, &krate.name.as_str(), "sourcesIndex"), &dst);
all_sources.push(format!(
"sourcesIndex[\"{}\"] = {};",
&krate.name,
Expand All @@ -1035,7 +1037,7 @@ themePicker.onblur = handleThemeButtonsBlur;

// Update the search index
let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix));
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name), &dst);
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name.as_str()), &dst);
all_indexes.push(search_index);

// Sort the indexes by crate so the file will be generated identically even
Expand Down Expand Up @@ -1070,7 +1072,7 @@ themePicker.onblur = handleThemeButtonsBlur;
extra_scripts: &[],
static_extra_scripts: &[],
};
krates.push(krate.name.clone());
krates.push(krate.name.to_string());
krates.sort();
krates.dedup();

Expand Down Expand Up @@ -1162,7 +1164,7 @@ themePicker.onblur = handleThemeButtonsBlur;
mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1]));

let (mut all_implementors, _) =
try_err!(collect(&mydst, &krate.name, "implementors"), &mydst);
try_err!(collect(&mydst, &krate.name.as_str(), "implementors"), &mydst);
all_implementors.push(implementors);
// Sort the implementors by crate so the file will be generated
// identically even with rustdoc running in parallel.
Expand Down Expand Up @@ -1648,16 +1650,17 @@ impl Context {
};
let file = &file;

let symbol;
let (krate, path) = if cnum == LOCAL_CRATE {
if let Some(path) = self.shared.local_sources.get(file) {
(&self.shared.layout.krate, path)
(self.shared.layout.krate.as_str(), path)
} else {
return None;
}
} else {
let (krate, src_root) = match *cache.extern_locations.get(&cnum)? {
(ref name, ref src, ExternalLocation::Local) => (name, src),
(ref name, ref src, ExternalLocation::Remote(ref s)) => {
(name, ref src, ExternalLocation::Local) => (name, src),
(name, ref src, ExternalLocation::Remote(ref s)) => {
root = s.to_string();
(name, src)
}
Expand All @@ -1671,7 +1674,8 @@ impl Context {
let mut fname = file.file_name().expect("source has no filename").to_os_string();
fname.push(".html");
path.push_str(&fname.to_string_lossy());
(krate, &path)
symbol = krate.as_str();
(&*symbol, &path)
};

let loline = item.source.lo(self.sess()).line;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ crate fn render(
krate: clean::Crate,
) -> Result<clean::Crate, Error> {
info!("emitting source files");
let dst = dst.join("src").join(&krate.name);
let dst = dst.join("src").join(&*krate.name.as_str());
scx.ensure_dir(&dst)?;
let mut folder = SourceCollector { dst, scx };
Ok(folder.fold_crate(krate))
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl FormatRenderer for JsonRenderer {
(
k.as_u32(),
types::ExternalCrate {
name: v.0.clone(),
name: v.0.to_string(),
html_root_url: match &v.2 {
ExternalLocation::Remote(s) => Some(s.clone()),
_ => None,
Expand Down
5 changes: 0 additions & 5 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,12 @@ fn main_options(options: config::Options) -> MainResult {
// compiler all the way through the analysis passes. The rustdoc output is
// then generated from the cleaned AST of the crate. This runs all the
// plug/cleaning passes.
let crate_name = options.crate_name.clone();
let crate_version = options.crate_version.clone();
let output_format = options.output_format;
let (mut krate, renderinfo, renderopts, sess) = core::run_core(options);

info!("finished with rustc");

if let Some(name) = crate_name {
krate.name = name
}

krate.version = crate_version;

if show_coverage {
Expand Down

0 comments on commit 5873fe8

Please sign in to comment.