1
Fork 0

Use deterministic FnvHash{Map,Set} in rustdoc

This commit is contained in:
Jonas Schievink 2016-08-24 10:55:03 +02:00
parent 144e576c87
commit 5adf003b99
6 changed files with 53 additions and 52 deletions

View file

@ -37,7 +37,7 @@ pub use self::ExternalLocation::*;
use std::ascii::AsciiExt;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::collections::BTreeMap;
use std::default::Default;
use std::error;
use std::fmt::{self, Display, Formatter};
@ -61,6 +61,7 @@ use rustc::middle::privacy::AccessLevels;
use rustc::middle::stability;
use rustc::session::config::get_unstable_features_setting;
use rustc::hir;
use rustc::util::nodemap::{FnvHashMap, FnvHashSet};
use clean::{self, Attributes, GetDefId};
use doctree;
@ -114,9 +115,9 @@ pub struct SharedContext {
/// `true`.
pub include_sources: bool,
/// The local file sources we've emitted and their respective url-paths.
pub local_sources: HashMap<PathBuf, String>,
pub local_sources: FnvHashMap<PathBuf, String>,
/// All the passes that were run on this crate.
pub passes: HashSet<String>,
pub passes: FnvHashSet<String>,
/// The base-URL of the issue tracker for when an item has been tagged with
/// an issue number.
pub issue_tracker_base_url: Option<String>,
@ -211,7 +212,7 @@ pub struct Cache {
/// Mapping of typaram ids to the name of the type parameter. This is used
/// when pretty-printing a type (so pretty printing doesn't have to
/// painfully maintain a context like this)
pub typarams: HashMap<DefId, String>,
pub typarams: FnvHashMap<DefId, String>,
/// Maps a type id to all known implementations for that type. This is only
/// recognized for intra-crate `ResolvedPath` types, and is used to print
@ -219,35 +220,35 @@ pub struct Cache {
///
/// The values of the map are a list of implementations and documentation
/// found on that implementation.
pub impls: HashMap<DefId, Vec<Impl>>,
pub impls: FnvHashMap<DefId, Vec<Impl>>,
/// Maintains a mapping of local crate node ids to the fully qualified name
/// and "short type description" of that node. This is used when generating
/// URLs when a type is being linked to. External paths are not located in
/// this map because the `External` type itself has all the information
/// necessary.
pub paths: HashMap<DefId, (Vec<String>, ItemType)>,
pub paths: FnvHashMap<DefId, (Vec<String>, ItemType)>,
/// Similar to `paths`, but only holds external paths. This is only used for
/// generating explicit hyperlinks to other crates.
pub external_paths: HashMap<DefId, (Vec<String>, ItemType)>,
pub external_paths: FnvHashMap<DefId, (Vec<String>, ItemType)>,
/// This map contains information about all known traits of this crate.
/// Implementations of a crate should inherit the documentation of the
/// parent trait if no extra documentation is specified, and default methods
/// should show up in documentation about trait implementations.
pub traits: HashMap<DefId, clean::Trait>,
pub traits: FnvHashMap<DefId, clean::Trait>,
/// When rendering traits, it's often useful to be able to list all
/// implementors of the trait, and this mapping is exactly, that: a mapping
/// of trait ids to the list of known implementors of the trait
pub implementors: HashMap<DefId, Vec<Implementor>>,
pub implementors: FnvHashMap<DefId, Vec<Implementor>>,
/// Cache of where external crate documentation can be found.
pub extern_locations: HashMap<ast::CrateNum, (String, ExternalLocation)>,
pub extern_locations: FnvHashMap<ast::CrateNum, (String, ExternalLocation)>,
/// Cache of where documentation for primitives can be found.
pub primitive_locations: HashMap<clean::PrimitiveType, ast::CrateNum>,
pub primitive_locations: FnvHashMap<clean::PrimitiveType, ast::CrateNum>,
// Note that external items for which `doc(hidden)` applies to are shown as
// non-reachable while local items aren't. This is because we're reusing
@ -260,7 +261,7 @@ pub struct Cache {
parent_stack: Vec<DefId>,
parent_is_trait_impl: bool,
search_index: Vec<IndexItem>,
seen_modules: HashSet<DefId>,
seen_modules: FnvHashSet<DefId>,
seen_mod: bool,
stripped_mod: bool,
deref_trait_did: Option<DefId>,
@ -277,9 +278,9 @@ pub struct Cache {
/// Later on moved into `CACHE_KEY`.
#[derive(Default)]
pub struct RenderInfo {
pub inlined: HashSet<DefId>,
pub inlined: FnvHashSet<DefId>,
pub external_paths: ::core::ExternalPaths,
pub external_typarams: HashMap<DefId, String>,
pub external_typarams: FnvHashMap<DefId, String>,
pub deref_trait_did: Option<DefId>,
}
@ -377,10 +378,10 @@ impl ToJson for IndexItemFunctionType {
thread_local!(static CACHE_KEY: RefCell<Arc<Cache>> = Default::default());
thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> =
RefCell::new(Vec::new()));
thread_local!(static USED_ID_MAP: RefCell<HashMap<String, usize>> =
thread_local!(static USED_ID_MAP: RefCell<FnvHashMap<String, usize>> =
RefCell::new(init_ids()));
fn init_ids() -> HashMap<String, usize> {
fn init_ids() -> FnvHashMap<String, usize> {
[
"main",
"search",
@ -407,7 +408,7 @@ pub fn reset_ids(embedded: bool) {
*s.borrow_mut() = if embedded {
init_ids()
} else {
HashMap::new()
FnvHashMap()
};
});
}
@ -432,7 +433,7 @@ pub fn derive_id(candidate: String) -> String {
pub fn run(mut krate: clean::Crate,
external_html: &ExternalHtml,
dst: PathBuf,
passes: HashSet<String>,
passes: FnvHashSet<String>,
css_file_extension: Option<PathBuf>,
renderinfo: RenderInfo) -> Result<(), Error> {
let src_root = match krate.src.parent() {
@ -443,7 +444,7 @@ pub fn run(mut krate: clean::Crate,
src_root: src_root,
passes: passes,
include_sources: true,
local_sources: HashMap::new(),
local_sources: FnvHashMap(),
issue_tracker_base_url: None,
layout: layout::Layout {
logo: "".to_string(),
@ -513,22 +514,22 @@ pub fn run(mut krate: clean::Crate,
.collect();
let mut cache = Cache {
impls: HashMap::new(),
impls: FnvHashMap(),
external_paths: external_paths,
paths: HashMap::new(),
implementors: HashMap::new(),
paths: FnvHashMap(),
implementors: FnvHashMap(),
stack: Vec::new(),
parent_stack: Vec::new(),
search_index: Vec::new(),
parent_is_trait_impl: false,
extern_locations: HashMap::new(),
primitive_locations: HashMap::new(),
seen_modules: HashSet::new(),
extern_locations: FnvHashMap(),
primitive_locations: FnvHashMap(),
seen_modules: FnvHashSet(),
seen_mod: false,
stripped_mod: false,
access_levels: krate.access_levels.clone(),
orphan_methods: Vec::new(),
traits: mem::replace(&mut krate.external_traits, HashMap::new()),
traits: mem::replace(&mut krate.external_traits, FnvHashMap()),
deref_trait_did: deref_trait_did,
typarams: external_typarams,
};
@ -574,7 +575,7 @@ pub fn run(mut krate: clean::Crate,
/// Build the search index from the collected metadata
fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
let mut nodeid_to_pathid = HashMap::new();
let mut nodeid_to_pathid = FnvHashMap();
let mut crate_items = Vec::with_capacity(cache.search_index.len());
let mut crate_paths = Vec::<Json>::new();
@ -2515,7 +2516,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
#[derive(Copy, Clone)]
enum AssocItemLink<'a> {
Anchor(Option<&'a str>),
GotoSource(DefId, &'a HashSet<String>),
GotoSource(DefId, &'a FnvHashSet<String>),
}
impl<'a> AssocItemLink<'a> {