Skip to content

Commit

Permalink
Remove IGNORED_ATTR_NAMES and make PROFQ_CHAN a scoped thread local.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Nov 29, 2017
1 parent 65b83db commit 9e078bd
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 11 deletions.
33 changes: 32 additions & 1 deletion src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fmt_macros = { path = "../libfmt_macros" }
graphviz = { path = "../libgraphviz" }
jobserver = "0.1"
log = "0.3"
scoped-tls = { git = "https://github.com/Zoxc/scoped-tls.git", features=["nightly"] }
owning_ref = { git = "https://github.com/Zoxc/owning-ref-rs.git" }
rustc_back = { path = "../librustc_back" }
rustc_const_math = { path = "../librustc_const_math" }
Expand Down
8 changes: 3 additions & 5 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHashingContextProvi
use rustc_data_structures::accumulate_vec::AccumulateVec;
use rustc_data_structures::fx::FxHashSet;

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

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

#[inline]
pub fn is_ignored_attr(&self, name: Symbol) -> bool {
rustc_access_global!(IGNORED_ATTR_NAMES, |ignored_attrs| {
ignored_attrs.contains(&name)
})
self.sess.ignored_attr_names.contains(&name)
}

pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
pub use self::fingerprint::Fingerprint;
pub use self::caching_codemap_view::CachingCodemapView;
pub use self::hcx::{StableHashingContext, NodeIdHashingMode,
hash_stable_trait_impls};
hash_stable_trait_impls, compute_ignored_attr_names};
mod fingerprint;
mod caching_codemap_view;
mod hcx;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern crate rustc_errors as errors;
#[macro_use] extern crate syntax;
extern crate syntax_pos;
extern crate jobserver;

#[macro_use] extern crate scoped_tls;
extern crate serialize as rustc_serialize; // used by deriving

// Note that librustc doesn't actually depend on these crates, see the note in
Expand Down
12 changes: 12 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
use hir::def_id::{CrateNum, DefIndex};
use ich::Fingerprint;

use ich;
use lint;
use middle::allocator::AllocatorKind;
use middle::dependency_format;
Expand All @@ -22,6 +23,7 @@ use session::config::DebugInfoLevel;
use ty::tls;
use util::nodemap::{FxHashMap, FxHashSet};
use util::common::{duration_to_secs_str, ErrorReported};
use util::common::ProfileQueriesMsg;

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

Expand All @@ -30,6 +32,7 @@ use errors::{self, DiagnosticBuilder, DiagnosticId};
use errors::emitter::{EmitterDyn, EmitterWriter};
use syntax::json::JsonEmitter;
use syntax::feature_gate;
use syntax::symbol::Symbol;
use syntax::parse;
use syntax::parse::ParseSess;
use syntax::{ast, codemap};
Expand All @@ -48,6 +51,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::{Once, ONCE_INIT};
use std::time::Duration;
use std::sync::mpsc;

mod code_stats;
pub mod config;
Expand Down Expand Up @@ -112,6 +116,12 @@ pub struct Session {

incr_comp_session: RwLock<IncrCompSession>,

/// A cache of attributes ignored by StableHashingContext
pub ignored_attr_names: FxHashSet<Symbol>,

/// Used by -Z profile-queries in util::common
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>,

/// Some measurements that are being gathered during compilation.
pub perf_stats: PerfStats,

Expand Down Expand Up @@ -832,6 +842,8 @@ pub fn build_session_(sopts: config::Options,
injected_panic_runtime: LockCell::new(None),
imported_macro_spans: Lock::new(HashMap::new()),
incr_comp_session: RwLock::new(IncrCompSession::NotInitialized),
ignored_attr_names: ich::compute_ignored_attr_names(),
profile_channel: Lock::new(None),
perf_stats: PerfStats {
svh_time: LockCell::new(Duration::from_secs(0)),
incr_comp_hashes_time: LockCell::new(Duration::from_secs(0)),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct ErrorReported;
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));

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

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

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

/// Set channel for profile queries channel
pub fn profq_set_chan(s: Sender<ProfileQueriesMsg>) -> bool {
rustc_access_global!(PROFQ_CHAN, |chan| {
PROFQ_CHAN.with(|chan| {
if chan.borrow().is_none() {
*chan.borrow_mut() = Some(s);
true
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use std::io::{self, Write};
use std::iter;
use std::path::{Path, PathBuf};
use rustc_data_structures::sync::Lrc;
use rustc::util::common::PROFQ_CHAN;
use std::sync::mpsc;
use syntax::{ast, diagnostics, visit};
use syntax::attr;
Expand All @@ -74,6 +75,18 @@ pub fn compile_input(sess: &Session,
output: &Option<PathBuf>,
addl_plugins: Option<Vec<String>>,
control: &CompileController) -> CompileResult {
PROFQ_CHAN.set(&sess.profile_channel, || {
compile_input_impl(sess, cstore, input, outdir, output, addl_plugins, control)
})
}

fn compile_input_impl(sess: &Session,
cstore: &CStore,
input: &Input,
outdir: &Option<PathBuf>,
output: &Option<PathBuf>,
addl_plugins: Option<Vec<String>>,
control: &CompileController) -> CompileResult {
use rustc::session::config::CrateType;

macro_rules! controller_entry_point {
Expand Down

0 comments on commit 9e078bd

Please sign in to comment.