Skip to content

Commit e567afb

Browse files
incr.comp.: Initialize IGNORED_ATTRS in StableHashingContext lazily.
1 parent dd50173 commit e567afb

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/librustc/ich/hcx.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use ty::{self, TyCtxt, fast_reject};
1717

1818
use std::cmp::Ord;
1919
use std::hash as std_hash;
20+
use std::cell::RefCell;
2021
use std::collections::HashMap;
2122

2223
use syntax::ast;
@@ -30,6 +31,10 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHashingContextProvi
3031
StableHasher, StableHasherResult,
3132
ToStableHashKey};
3233
use rustc_data_structures::accumulate_vec::AccumulateVec;
34+
use rustc_data_structures::fx::FxHashSet;
35+
36+
thread_local!(static IGNORED_ATTR_NAMES: RefCell<FxHashSet<Symbol>> =
37+
RefCell::new(FxHashSet()));
3338

3439
/// This is the context state available during incr. comp. hashing. It contains
3540
/// enough information to transform DefIds and HirIds into stable DefPaths (i.e.
@@ -41,8 +46,6 @@ pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
4146
hash_bodies: bool,
4247
overflow_checks_enabled: bool,
4348
node_id_hashing_mode: NodeIdHashingMode,
44-
// A sorted array of symbol keys for fast lookup.
45-
ignored_attr_names: Vec<Symbol>,
4649

4750
// Very often, we are hashing something that does not need the
4851
// CachingCodemapView, so we initialize it lazily.
@@ -62,12 +65,14 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
6265
let hash_spans_initial = tcx.sess.opts.debuginfo != NoDebugInfo;
6366
let check_overflow_initial = tcx.sess.overflow_checks();
6467

65-
let mut ignored_attr_names: Vec<_> = ich::IGNORED_ATTRIBUTES
66-
.iter()
67-
.map(|&s| Symbol::intern(s))
68-
.collect();
69-
70-
ignored_attr_names.sort();
68+
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
69+
IGNORED_ATTR_NAMES.with(|names| {
70+
let mut names = names.borrow_mut();
71+
if names.is_empty() {
72+
names.extend(ich::IGNORED_ATTRIBUTES.iter()
73+
.map(|&s| Symbol::intern(s)));
74+
}
75+
});
7176

7277
StableHashingContext {
7378
tcx,
@@ -77,7 +82,6 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
7782
hash_bodies: true,
7883
overflow_checks_enabled: check_overflow_initial,
7984
node_id_hashing_mode: NodeIdHashingMode::HashDefPath,
80-
ignored_attr_names,
8185
}
8286
}
8387

@@ -151,7 +155,9 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
151155

152156
#[inline]
153157
pub fn is_ignored_attr(&self, name: Symbol) -> bool {
154-
self.ignored_attr_names.binary_search(&name).is_ok()
158+
IGNORED_ATTR_NAMES.with(|names| {
159+
names.borrow().contains(&name)
160+
})
155161
}
156162

157163
pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self,

src/librustc/ich/impls_syntax.rs

+5
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for [ast::
169169
fn hash_stable<W: StableHasherResult>(&self,
170170
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
171171
hasher: &mut StableHasher<W>) {
172+
if self.len() == 0 {
173+
self.len().hash_stable(hcx, hasher);
174+
return
175+
}
176+
172177
// Some attributes are always ignored during hashing.
173178
let filtered: AccumulateVec<[&ast::Attribute; 8]> = self
174179
.iter()

0 commit comments

Comments
 (0)