Skip to content

Commit b42ff9b

Browse files
committed
Remove IGNORED_ATTR_NAMES and make PROFQ_CHAN a scoped thread local.
1 parent 88eed20 commit b42ff9b

File tree

8 files changed

+239
-146
lines changed

8 files changed

+239
-146
lines changed

src/Cargo.lock

+205-136
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fmt_macros = { path = "../libfmt_macros" }
1515
graphviz = { path = "../libgraphviz" }
1616
jobserver = "0.1"
1717
log = "0.3"
18+
scoped-tls = { git = "https://github.com/Zoxc/scoped-tls.git", features=["nightly"] }
1819
owning_ref = { git = "https://github.com/Zoxc/owning-ref-rs.git" }
1920
rustc_back = { path = "../librustc_back" }
2021
rustc_const_math = { path = "../librustc_const_math" }

src/librustc/ich/hcx.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHashingContextProvi
3535
use rustc_data_structures::accumulate_vec::AccumulateVec;
3636
use rustc_data_structures::fx::FxHashSet;
3737

38-
rustc_global!(static IGNORED_ATTR_NAMES: FxHashSet<Symbol> = {
38+
pub fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
3939
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
4040
ich::IGNORED_ATTRIBUTES.iter().map(|&s| Symbol::intern(s)).collect()
41-
});
41+
}
4242

4343
/// This is the context state available during incr. comp. hashing. It contains
4444
/// enough information to transform DefIds and HirIds into stable DefPaths (i.e.
@@ -191,9 +191,7 @@ impl<'gcx> StableHashingContext<'gcx> {
191191

192192
#[inline]
193193
pub fn is_ignored_attr(&self, name: Symbol) -> bool {
194-
rustc_access_global!(IGNORED_ATTR_NAMES, |ignored_attrs| {
195-
ignored_attrs.contains(&name)
196-
})
194+
self.sess.ignored_attr_names.contains(&name)
197195
}
198196

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

src/librustc/ich/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
pub use self::fingerprint::Fingerprint;
1414
pub use self::caching_codemap_view::CachingCodemapView;
1515
pub use self::hcx::{StableHashingContext, NodeIdHashingMode,
16-
hash_stable_trait_impls};
16+
hash_stable_trait_impls, compute_ignored_attr_names};
1717
mod fingerprint;
1818
mod caching_codemap_view;
1919
mod hcx;

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ extern crate rustc_errors as errors;
8585
#[macro_use] extern crate syntax;
8686
extern crate syntax_pos;
8787
extern crate jobserver;
88-
88+
#[macro_use] extern crate scoped_tls;
8989
extern crate serialize as rustc_serialize; // used by deriving
9090

9191
// Note that librustc doesn't actually depend on these crates, see the note in

src/librustc/session/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
1414
use hir::def_id::{CrateNum, DefIndex};
1515
use ich::Fingerprint;
1616

17+
use ich;
1718
use lint;
1819
use middle::allocator::AllocatorKind;
1920
use middle::dependency_format;
@@ -22,6 +23,7 @@ use session::config::DebugInfoLevel;
2223
use ty::tls;
2324
use util::nodemap::{FxHashMap, FxHashSet};
2425
use util::common::{duration_to_secs_str, ErrorReported};
26+
use util::common::ProfileQueriesMsg;
2527

2628
use rustc_data_structures::sync::{Lrc, RwLock, Lock, LockCell, ReadGuard};
2729

@@ -30,6 +32,7 @@ use errors::{self, DiagnosticBuilder, DiagnosticId};
3032
use errors::emitter::{EmitterDyn, EmitterWriter};
3133
use syntax::json::JsonEmitter;
3234
use syntax::feature_gate;
35+
use syntax::symbol::Symbol;
3336
use syntax::parse;
3437
use syntax::parse::ParseSess;
3538
use syntax::{ast, codemap};
@@ -48,6 +51,7 @@ use std::io::Write;
4851
use std::path::{Path, PathBuf};
4952
use std::sync::{Once, ONCE_INIT};
5053
use std::time::Duration;
54+
use std::sync::mpsc;
5155

5256
mod code_stats;
5357
pub mod config;
@@ -112,6 +116,12 @@ pub struct Session {
112116

113117
incr_comp_session: RwLock<IncrCompSession>,
114118

119+
/// A cache of attributes ignored by StableHashingContext
120+
pub ignored_attr_names: FxHashSet<Symbol>,
121+
122+
/// Used by -Z profile-queries in util::common
123+
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>,
124+
115125
/// Some measurements that are being gathered during compilation.
116126
pub perf_stats: PerfStats,
117127

@@ -832,6 +842,8 @@ pub fn build_session_(sopts: config::Options,
832842
injected_panic_runtime: LockCell::new(None),
833843
imported_macro_spans: Lock::new(HashMap::new()),
834844
incr_comp_session: RwLock::new(IncrCompSession::NotInitialized),
845+
ignored_attr_names: ich::compute_ignored_attr_names(),
846+
profile_channel: Lock::new(None),
835847
perf_stats: PerfStats {
836848
svh_time: LockCell::new(Duration::from_secs(0)),
837849
incr_comp_hashes_time: LockCell::new(Duration::from_secs(0)),

src/librustc/util/common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct ErrorReported;
3939
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
4040

4141
/// Initialized for -Z profile-queries
42-
rustc_global!(static PROFQ_CHAN: Lock<Option<Sender<ProfileQueriesMsg>>> = Lock::new(None));
42+
scoped_thread_local!(pub static PROFQ_CHAN: Lock<Option<Sender<ProfileQueriesMsg>>>);
4343

4444
/// Parameters to the `Dump` variant of type `ProfileQueriesMsg`.
4545
#[derive(Clone,Debug)]
@@ -81,7 +81,7 @@ pub enum ProfileQueriesMsg {
8181

8282
/// If enabled, send a message to the profile-queries thread
8383
pub fn profq_msg(msg: ProfileQueriesMsg) {
84-
rustc_access_global!(PROFQ_CHAN, |sender| {
84+
PROFQ_CHAN.with(|sender| {
8585
if let Some(s) = sender.borrow().as_ref() {
8686
s.send(msg).unwrap()
8787
} else {
@@ -97,7 +97,7 @@ pub fn profq_msg(msg: ProfileQueriesMsg) {
9797

9898
/// Set channel for profile queries channel
9999
pub fn profq_set_chan(s: Sender<ProfileQueriesMsg>) -> bool {
100-
rustc_access_global!(PROFQ_CHAN, |chan| {
100+
PROFQ_CHAN.with(|chan| {
101101
if chan.borrow().is_none() {
102102
*chan.borrow_mut() = Some(s);
103103
true

src/librustc_driver/driver.rs

+13
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use std::io::{self, Write};
5252
use std::iter;
5353
use std::path::{Path, PathBuf};
5454
use rustc_data_structures::sync::Lrc;
55+
use rustc::util::common::PROFQ_CHAN;
5556
use std::sync::mpsc;
5657
use syntax::{ast, diagnostics, visit};
5758
use syntax::attr;
@@ -74,6 +75,18 @@ pub fn compile_input(sess: &Session,
7475
output: &Option<PathBuf>,
7576
addl_plugins: Option<Vec<String>>,
7677
control: &CompileController) -> CompileResult {
78+
PROFQ_CHAN.set(&sess.profile_channel, || {
79+
compile_input_impl(sess, cstore, input, outdir, output, addl_plugins, control)
80+
})
81+
}
82+
83+
fn compile_input_impl(sess: &Session,
84+
cstore: &CStore,
85+
input: &Input,
86+
outdir: &Option<PathBuf>,
87+
output: &Option<PathBuf>,
88+
addl_plugins: Option<Vec<String>>,
89+
control: &CompileController) -> CompileResult {
7790
use rustc::session::config::CrateType;
7891

7992
macro_rules! controller_entry_point {

0 commit comments

Comments
 (0)