Skip to content

Commit

Permalink
Remove syntax and syntax_pos thread locals
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Nov 25, 2017
1 parent 2bbed5f commit 057c727
Show file tree
Hide file tree
Showing 30 changed files with 1,292 additions and 1,135 deletions.
4 changes: 3 additions & 1 deletion src/Cargo.lock

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

65 changes: 35 additions & 30 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,7 @@ mod tests {
use super::{OutputType, OutputTypes, Externs};
use rustc_back::{PanicStrategy, RelroLevel};
use syntax::symbol::Symbol;
use syntax;

fn optgroups() -> getopts::Options {
let mut opts = getopts::Options::new();
Expand All @@ -2070,51 +2071,55 @@ mod tests {
// When the user supplies --test we should implicitly supply --cfg test
#[test]
fn test_switch_implies_cfg_test() {
let matches =
&match optgroups().parse(&["--test".to_string()]) {
Ok(m) => m,
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
};
let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, cfg);
assert!(cfg.contains(&(Symbol::intern("test"), None)));
syntax::with_globals(&syntax::Globals::new(), || {
let matches =
&match optgroups().parse(&["--test".to_string()]) {
Ok(m) => m,
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
};
let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, cfg);
assert!(cfg.contains(&(Symbol::intern("test"), None)));
});
}

// When the user supplies --test and --cfg test, don't implicitly add
// another --cfg test
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches =
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
Ok(m) => m,
Err(f) => {
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
}
};
let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, cfg);
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
assert!(test_items.next().is_some());
assert!(test_items.next().is_none());
syntax::with_globals(&syntax::Globals::new(), || {
let matches =
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
Ok(m) => m,
Err(f) => {
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
}
};
let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, cfg);
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
assert!(test_items.next().is_some());
assert!(test_items.next().is_none());
});
}

#[test]
fn test_can_print_warnings() {
{
syntax::with_globals(&syntax::Globals::new(), || {
let matches = optgroups().parse(&[
"-Awarnings".to_string()
]).unwrap();
let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, None, registry);
assert!(!sess.diagnostic().flags.can_emit_warnings);
}
});

{
syntax::with_globals(&syntax::Globals::new(), || {
let matches = optgroups().parse(&[
"-Awarnings".to_string(),
"-Dwarnings".to_string()
Expand All @@ -2123,17 +2128,17 @@ mod tests {
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, None, registry);
assert!(sess.diagnostic().flags.can_emit_warnings);
}
});

{
syntax::with_globals(&syntax::Globals::new(), || {
let matches = optgroups().parse(&[
"-Adead_code".to_string()
]).unwrap();
let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, None, registry);
assert!(sess.diagnostic().flags.can_emit_warnings);
}
});
}

#[test]
Expand Down
30 changes: 0 additions & 30 deletions src/librustc_data_structures/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
//!
//! `MTLock` is a mutex which disappears if cfg!(parallel_queries) is false.
//!
//! `rustc_global!` gives us a way to declare variables which are intended to be
//! global for the current rustc session. This currently maps to thread-locals,
//! since rustdoc uses the rustc libraries in multiple threads.
//! These globals should eventually be moved into the `Session` structure.
//!
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
//! depending on the value of cfg!(parallel_queries).

Expand Down Expand Up @@ -266,31 +261,6 @@ cfg_if! {
}
}

#[macro_export]
#[allow_internal_unstable]
macro_rules! rustc_global {
// empty (base case for the recursion)
() => {};

// process multiple declarations
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => (
thread_local!($(#[$attr])* $vis static $name: $t = $init);
rustc_global!($($rest)*);
);

// handle a single declaration
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => (
thread_local!($(#[$attr])* $vis static $name: $t = $init);
);
}

#[macro_export]
macro_rules! rustc_access_global {
($name:path, $callback:expr) => {
$name.with($callback)
}
}

impl<T: Copy + Debug> Debug for LockCell<T> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_struct("LockCell")
Expand Down
15 changes: 14 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ pub fn run_compiler<'a>(args: &[String],
file_loader: Option<Box<FileLoader + Send + Sync + 'static>>,
emitter_dest: Option<Box<Write + Send>>)
-> (CompileResult, Option<Session>)
{
syntax::with_globals(&syntax::Globals::new(), || {
run_compiler_impl(args, callbacks, file_loader, emitter_dest)
})
}

fn run_compiler_impl<'a>(args: &[String],
callbacks: &mut CompilerCalls<'a>,
file_loader: Option<Box<FileLoader + Send + Sync + 'static>>,
emitter_dest: Option<Box<Write + Send>>)
-> (CompileResult, Option<Session>)
{
macro_rules! do_or_return {($expr: expr, $sess: expr) => {
match $expr {
Expand Down Expand Up @@ -1187,7 +1198,9 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
cfg = cfg.stack_size(STACK_SIZE);
}

let thread = cfg.spawn(f);
let thread = cfg.spawn(|| {
syntax::with_globals(&syntax::Globals::new(), || f())
});
thread.unwrap().join()
}

Expand Down
2 changes: 0 additions & 2 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
hir_map,
analysis,
resolutions,
arena,
arenas,
output_filenames,
crate_name,
Expand Down Expand Up @@ -1025,7 +1024,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
hir_map,
analysis,
resolutions,
arena,
arenas,
output_filenames,
crate_name,
Expand Down
13 changes: 12 additions & 1 deletion src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use rustc::session::config::{OutputFilenames, OutputTypes};
use rustc_trans_utils::trans_crate::TransCrate;
use std::rc::Rc;
use rustc_data_structures::sync::Lrc;
use syntax;
use syntax::ast;
use syntax::abi::Abi;
use syntax::codemap::{CodeMap, FilePathMapping};
Expand Down Expand Up @@ -97,9 +98,19 @@ fn errors(msgs: &[&str]) -> (Box<Emitter + Send>, usize) {
}

fn test_env<F>(source_string: &str,
(emitter, expected_err_count): (Box<Emitter + Send>, usize),
args: (Box<Emitter + Send>, usize),
body: F)
where F: FnOnce(Env)
{
syntax::with_globals(&syntax::Globals::new(), || {
test_env_impl(source_string, args, body)
});
}

fn test_env_impl<F>(source_string: &str,
(emitter, expected_err_count): (Box<Emitter + Send>, usize),
body: F)
where F: FnOnce(Env)
{
let mut options = config::basic_options();
options.debugging_opts.verbose = true;
Expand Down
Loading

0 comments on commit 057c727

Please sign in to comment.