Skip to content

Commit 5adf003

Browse files
Use deterministic FnvHash{Map,Set} in rustdoc
1 parent 144e576 commit 5adf003

File tree

6 files changed

+53
-52
lines changed

6 files changed

+53
-52
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
//! Support for inlining external documentation into the current AST.
1212
13-
use std::collections::HashSet;
1413
use std::iter::once;
1514

1615
use syntax::ast;
@@ -21,6 +20,7 @@ use rustc::hir::def::Def;
2120
use rustc::hir::def_id::DefId;
2221
use rustc::hir::print as pprust;
2322
use rustc::ty::{self, TyCtxt};
23+
use rustc::util::nodemap::FnvHashSet;
2424

2525
use rustc_const_eval::lookup_const_by_id;
2626

@@ -425,7 +425,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
425425
.into_iter()
426426
.map(|meth| meth.name.to_string())
427427
.collect()
428-
}).unwrap_or(HashSet::new());
428+
}).unwrap_or(FnvHashSet());
429429

430430
ret.push(clean::Item {
431431
inner: clean::ImplItem(clean::Impl {
@@ -461,7 +461,7 @@ fn build_module<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
461461
// If we're reexporting a reexport it may actually reexport something in
462462
// two namespaces, so the target may be listed twice. Make sure we only
463463
// visit each node at most once.
464-
let mut visited = HashSet::new();
464+
let mut visited = FnvHashSet();
465465
for item in tcx.sess.cstore.item_children(did) {
466466
match item.def {
467467
cstore::DlDef(Def::ForeignMod(did)) => {

src/librustdoc/clean/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ use rustc::hir::print as pprust;
4343
use rustc::ty::subst::Substs;
4444
use rustc::ty;
4545
use rustc::middle::stability;
46+
use rustc::util::nodemap::{FnvHashMap, FnvHashSet};
4647

4748
use rustc::hir;
4849

49-
use std::collections::{HashMap, HashSet};
5050
use std::path::PathBuf;
5151
use std::rc::Rc;
5252
use std::sync::Arc;
@@ -121,7 +121,7 @@ pub struct Crate {
121121
pub access_levels: Arc<AccessLevels<DefId>>,
122122
// These are later on moved into `CACHEKEY`, leaving the map empty.
123123
// Only here so that they can be filtered through the rustdoc passes.
124-
pub external_traits: HashMap<DefId, Trait>,
124+
pub external_traits: FnvHashMap<DefId, Trait>,
125125
}
126126

127127
struct CrateNum(ast::CrateNum);
@@ -1010,7 +1010,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics<'tcx>,
10101010
// Note that associated types also have a sized bound by default, but we
10111011
// don't actually know the set of associated types right here so that's
10121012
// handled in cleaning associated types
1013-
let mut sized_params = HashSet::new();
1013+
let mut sized_params = FnvHashSet();
10141014
where_predicates.retain(|pred| {
10151015
match *pred {
10161016
WP::BoundPredicate { ty: Generic(ref g), ref bounds } => {
@@ -1656,9 +1656,9 @@ impl From<ast::FloatTy> for PrimitiveType {
16561656
struct SubstAlias<'a, 'tcx: 'a> {
16571657
tcx: &'a ty::TyCtxt<'a, 'tcx, 'tcx>,
16581658
// Table type parameter definition -> substituted type
1659-
ty_substs: HashMap<Def, hir::Ty>,
1659+
ty_substs: FnvHashMap<Def, hir::Ty>,
16601660
// Table node id of lifetime parameter definition -> substituted lifetime
1661-
lt_substs: HashMap<ast::NodeId, hir::Lifetime>,
1661+
lt_substs: FnvHashMap<ast::NodeId, hir::Lifetime>,
16621662
}
16631663

16641664
impl<'a, 'tcx: 'a, 'b: 'tcx> Folder for SubstAlias<'a, 'tcx> {
@@ -1727,8 +1727,8 @@ impl Clean<Type> for hir::Ty {
17271727
let item = tcx.map.expect_item(node_id);
17281728
if let hir::ItemTy(ref ty, ref generics) = item.node {
17291729
let provided_params = &path.segments.last().unwrap().parameters;
1730-
let mut ty_substs = HashMap::new();
1731-
let mut lt_substs = HashMap::new();
1730+
let mut ty_substs = FnvHashMap();
1731+
let mut lt_substs = FnvHashMap();
17321732
for (i, ty_param) in generics.ty_params.iter().enumerate() {
17331733
let ty_param_def = tcx.expect_def(ty_param.id);
17341734
if let Some(ty) = provided_params.types().get(i).cloned()
@@ -2384,7 +2384,7 @@ impl Clean<ImplPolarity> for hir::ImplPolarity {
23842384
pub struct Impl {
23852385
pub unsafety: hir::Unsafety,
23862386
pub generics: Generics,
2387-
pub provided_trait_methods: HashSet<String>,
2387+
pub provided_trait_methods: FnvHashSet<String>,
23882388
pub trait_: Option<Type>,
23892389
pub for_: Type,
23902390
pub items: Vec<Item>,
@@ -2410,7 +2410,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
24102410
.map(|meth| meth.name.to_string())
24112411
.collect()
24122412
})
2413-
}).unwrap_or(HashSet::new());
2413+
}).unwrap_or(FnvHashSet());
24142414

24152415
ret.push(Item {
24162416
name: None,

src/librustdoc/core.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc::middle::privacy::AccessLevels;
1818
use rustc::ty::{self, TyCtxt};
1919
use rustc::hir::map as hir_map;
2020
use rustc::lint;
21+
use rustc::util::nodemap::{FnvHashMap, FnvHashSet};
2122
use rustc_trans::back::link;
2223
use rustc_resolve as resolve;
2324
use rustc_metadata::cstore::CStore;
@@ -28,7 +29,6 @@ use errors;
2829
use errors::emitter::ColorConfig;
2930

3031
use std::cell::{RefCell, Cell};
31-
use std::collections::{HashMap, HashSet};
3232
use std::rc::Rc;
3333

3434
use visit_ast::RustdocVisitor;
@@ -45,13 +45,13 @@ pub enum MaybeTyped<'a, 'tcx: 'a> {
4545
NotTyped(&'a session::Session)
4646
}
4747

48-
pub type ExternalPaths = HashMap<DefId, (Vec<String>, clean::TypeKind)>;
48+
pub type ExternalPaths = FnvHashMap<DefId, (Vec<String>, clean::TypeKind)>;
4949

5050
pub struct DocContext<'a, 'tcx: 'a> {
5151
pub map: &'a hir_map::Map<'tcx>,
5252
pub maybe_typed: MaybeTyped<'a, 'tcx>,
5353
pub input: Input,
54-
pub populated_crate_impls: RefCell<HashSet<ast::CrateNum>>,
54+
pub populated_crate_impls: RefCell<FnvHashSet<ast::CrateNum>>,
5555
pub deref_trait_did: Cell<Option<DefId>>,
5656
// Note that external items for which `doc(hidden)` applies to are shown as
5757
// non-reachable while local items aren't. This is because we're reusing
@@ -61,7 +61,7 @@ pub struct DocContext<'a, 'tcx: 'a> {
6161
/// Later on moved into `html::render::CACHE_KEY`
6262
pub renderinfo: RefCell<RenderInfo>,
6363
/// Later on moved through `clean::Crate` into `html::render::CACHE_KEY`
64-
pub external_traits: RefCell<HashMap<DefId, clean::Trait>>,
64+
pub external_traits: RefCell<FnvHashMap<DefId, clean::Trait>>,
6565
}
6666

6767
impl<'b, 'tcx> DocContext<'b, 'tcx> {
@@ -178,10 +178,10 @@ pub fn run_core(search_paths: SearchPaths,
178178
map: &tcx.map,
179179
maybe_typed: Typed(tcx),
180180
input: input,
181-
populated_crate_impls: RefCell::new(HashSet::new()),
181+
populated_crate_impls: RefCell::new(FnvHashSet()),
182182
deref_trait_did: Cell::new(None),
183183
access_levels: RefCell::new(access_levels),
184-
external_traits: RefCell::new(HashMap::new()),
184+
external_traits: RefCell::new(FnvHashMap()),
185185
renderinfo: RefCell::new(Default::default()),
186186
};
187187
debug!("crate: {:?}", ctxt.map.krate());

src/librustdoc/html/render.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use self::ExternalLocation::*;
3737
use std::ascii::AsciiExt;
3838
use std::cell::RefCell;
3939
use std::cmp::Ordering;
40-
use std::collections::{BTreeMap, HashMap, HashSet};
40+
use std::collections::BTreeMap;
4141
use std::default::Default;
4242
use std::error;
4343
use std::fmt::{self, Display, Formatter};
@@ -61,6 +61,7 @@ use rustc::middle::privacy::AccessLevels;
6161
use rustc::middle::stability;
6262
use rustc::session::config::get_unstable_features_setting;
6363
use rustc::hir;
64+
use rustc::util::nodemap::{FnvHashMap, FnvHashSet};
6465

6566
use clean::{self, Attributes, GetDefId};
6667
use doctree;
@@ -114,9 +115,9 @@ pub struct SharedContext {
114115
/// `true`.
115116
pub include_sources: bool,
116117
/// The local file sources we've emitted and their respective url-paths.
117-
pub local_sources: HashMap<PathBuf, String>,
118+
pub local_sources: FnvHashMap<PathBuf, String>,
118119
/// All the passes that were run on this crate.
119-
pub passes: HashSet<String>,
120+
pub passes: FnvHashSet<String>,
120121
/// The base-URL of the issue tracker for when an item has been tagged with
121122
/// an issue number.
122123
pub issue_tracker_base_url: Option<String>,
@@ -211,43 +212,43 @@ pub struct Cache {
211212
/// Mapping of typaram ids to the name of the type parameter. This is used
212213
/// when pretty-printing a type (so pretty printing doesn't have to
213214
/// painfully maintain a context like this)
214-
pub typarams: HashMap<DefId, String>,
215+
pub typarams: FnvHashMap<DefId, String>,
215216

216217
/// Maps a type id to all known implementations for that type. This is only
217218
/// recognized for intra-crate `ResolvedPath` types, and is used to print
218219
/// out extra documentation on the page of an enum/struct.
219220
///
220221
/// The values of the map are a list of implementations and documentation
221222
/// found on that implementation.
222-
pub impls: HashMap<DefId, Vec<Impl>>,
223+
pub impls: FnvHashMap<DefId, Vec<Impl>>,
223224

224225
/// Maintains a mapping of local crate node ids to the fully qualified name
225226
/// and "short type description" of that node. This is used when generating
226227
/// URLs when a type is being linked to. External paths are not located in
227228
/// this map because the `External` type itself has all the information
228229
/// necessary.
229-
pub paths: HashMap<DefId, (Vec<String>, ItemType)>,
230+
pub paths: FnvHashMap<DefId, (Vec<String>, ItemType)>,
230231

231232
/// Similar to `paths`, but only holds external paths. This is only used for
232233
/// generating explicit hyperlinks to other crates.
233-
pub external_paths: HashMap<DefId, (Vec<String>, ItemType)>,
234+
pub external_paths: FnvHashMap<DefId, (Vec<String>, ItemType)>,
234235

235236
/// This map contains information about all known traits of this crate.
236237
/// Implementations of a crate should inherit the documentation of the
237238
/// parent trait if no extra documentation is specified, and default methods
238239
/// should show up in documentation about trait implementations.
239-
pub traits: HashMap<DefId, clean::Trait>,
240+
pub traits: FnvHashMap<DefId, clean::Trait>,
240241

241242
/// When rendering traits, it's often useful to be able to list all
242243
/// implementors of the trait, and this mapping is exactly, that: a mapping
243244
/// of trait ids to the list of known implementors of the trait
244-
pub implementors: HashMap<DefId, Vec<Implementor>>,
245+
pub implementors: FnvHashMap<DefId, Vec<Implementor>>,
245246

246247
/// Cache of where external crate documentation can be found.
247-
pub extern_locations: HashMap<ast::CrateNum, (String, ExternalLocation)>,
248+
pub extern_locations: FnvHashMap<ast::CrateNum, (String, ExternalLocation)>,
248249

249250
/// Cache of where documentation for primitives can be found.
250-
pub primitive_locations: HashMap<clean::PrimitiveType, ast::CrateNum>,
251+
pub primitive_locations: FnvHashMap<clean::PrimitiveType, ast::CrateNum>,
251252

252253
// Note that external items for which `doc(hidden)` applies to are shown as
253254
// non-reachable while local items aren't. This is because we're reusing
@@ -260,7 +261,7 @@ pub struct Cache {
260261
parent_stack: Vec<DefId>,
261262
parent_is_trait_impl: bool,
262263
search_index: Vec<IndexItem>,
263-
seen_modules: HashSet<DefId>,
264+
seen_modules: FnvHashSet<DefId>,
264265
seen_mod: bool,
265266
stripped_mod: bool,
266267
deref_trait_did: Option<DefId>,
@@ -277,9 +278,9 @@ pub struct Cache {
277278
/// Later on moved into `CACHE_KEY`.
278279
#[derive(Default)]
279280
pub struct RenderInfo {
280-
pub inlined: HashSet<DefId>,
281+
pub inlined: FnvHashSet<DefId>,
281282
pub external_paths: ::core::ExternalPaths,
282-
pub external_typarams: HashMap<DefId, String>,
283+
pub external_typarams: FnvHashMap<DefId, String>,
283284
pub deref_trait_did: Option<DefId>,
284285
}
285286

@@ -377,10 +378,10 @@ impl ToJson for IndexItemFunctionType {
377378
thread_local!(static CACHE_KEY: RefCell<Arc<Cache>> = Default::default());
378379
thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> =
379380
RefCell::new(Vec::new()));
380-
thread_local!(static USED_ID_MAP: RefCell<HashMap<String, usize>> =
381+
thread_local!(static USED_ID_MAP: RefCell<FnvHashMap<String, usize>> =
381382
RefCell::new(init_ids()));
382383

383-
fn init_ids() -> HashMap<String, usize> {
384+
fn init_ids() -> FnvHashMap<String, usize> {
384385
[
385386
"main",
386387
"search",
@@ -407,7 +408,7 @@ pub fn reset_ids(embedded: bool) {
407408
*s.borrow_mut() = if embedded {
408409
init_ids()
409410
} else {
410-
HashMap::new()
411+
FnvHashMap()
411412
};
412413
});
413414
}
@@ -432,7 +433,7 @@ pub fn derive_id(candidate: String) -> String {
432433
pub fn run(mut krate: clean::Crate,
433434
external_html: &ExternalHtml,
434435
dst: PathBuf,
435-
passes: HashSet<String>,
436+
passes: FnvHashSet<String>,
436437
css_file_extension: Option<PathBuf>,
437438
renderinfo: RenderInfo) -> Result<(), Error> {
438439
let src_root = match krate.src.parent() {
@@ -443,7 +444,7 @@ pub fn run(mut krate: clean::Crate,
443444
src_root: src_root,
444445
passes: passes,
445446
include_sources: true,
446-
local_sources: HashMap::new(),
447+
local_sources: FnvHashMap(),
447448
issue_tracker_base_url: None,
448449
layout: layout::Layout {
449450
logo: "".to_string(),
@@ -513,22 +514,22 @@ pub fn run(mut krate: clean::Crate,
513514
.collect();
514515

515516
let mut cache = Cache {
516-
impls: HashMap::new(),
517+
impls: FnvHashMap(),
517518
external_paths: external_paths,
518-
paths: HashMap::new(),
519-
implementors: HashMap::new(),
519+
paths: FnvHashMap(),
520+
implementors: FnvHashMap(),
520521
stack: Vec::new(),
521522
parent_stack: Vec::new(),
522523
search_index: Vec::new(),
523524
parent_is_trait_impl: false,
524-
extern_locations: HashMap::new(),
525-
primitive_locations: HashMap::new(),
526-
seen_modules: HashSet::new(),
525+
extern_locations: FnvHashMap(),
526+
primitive_locations: FnvHashMap(),
527+
seen_modules: FnvHashSet(),
527528
seen_mod: false,
528529
stripped_mod: false,
529530
access_levels: krate.access_levels.clone(),
530531
orphan_methods: Vec::new(),
531-
traits: mem::replace(&mut krate.external_traits, HashMap::new()),
532+
traits: mem::replace(&mut krate.external_traits, FnvHashMap()),
532533
deref_trait_did: deref_trait_did,
533534
typarams: external_typarams,
534535
};
@@ -574,7 +575,7 @@ pub fn run(mut krate: clean::Crate,
574575

575576
/// Build the search index from the collected metadata
576577
fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
577-
let mut nodeid_to_pathid = HashMap::new();
578+
let mut nodeid_to_pathid = FnvHashMap();
578579
let mut crate_items = Vec::with_capacity(cache.search_index.len());
579580
let mut crate_paths = Vec::<Json>::new();
580581

@@ -2515,7 +2516,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
25152516
#[derive(Copy, Clone)]
25162517
enum AssocItemLink<'a> {
25172518
Anchor(Option<&'a str>),
2518-
GotoSource(DefId, &'a HashSet<String>),
2519+
GotoSource(DefId, &'a FnvHashSet<String>),
25192520
}
25202521

25212522
impl<'a> AssocItemLink<'a> {

src/librustdoc/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::cell::{RefCell, Cell};
12-
use std::collections::{HashMap, HashSet};
1312
use std::env;
1413
use std::ffi::OsString;
1514
use std::io::prelude::*;
@@ -29,6 +28,7 @@ use rustc::session::{self, config};
2928
use rustc::session::config::{get_unstable_features_setting, OutputType,
3029
OutputTypes, Externs};
3130
use rustc::session::search_paths::{SearchPaths, PathKind};
31+
use rustc::util::nodemap::{FnvHashMap, FnvHashSet};
3232
use rustc_back::dynamic_lib::DynamicLibrary;
3333
use rustc_back::tempdir::TempDir;
3434
use rustc_driver::{driver, Compilation};
@@ -107,8 +107,8 @@ pub fn run(input: &str,
107107
map: &map,
108108
maybe_typed: core::NotTyped(&sess),
109109
input: input,
110-
external_traits: RefCell::new(HashMap::new()),
111-
populated_crate_impls: RefCell::new(HashSet::new()),
110+
external_traits: RefCell::new(FnvHashMap()),
111+
populated_crate_impls: RefCell::new(FnvHashSet()),
112112
deref_trait_did: Cell::new(None),
113113
access_levels: Default::default(),
114114
renderinfo: Default::default(),

0 commit comments

Comments
 (0)