Skip to content

Commit

Permalink
Auto merge of #48811 - Zoxc:syntax-globals, r=michaelwoerister
Browse files Browse the repository at this point in the history
Remove syntax and syntax_pos thread locals

This moves `syntax` and `syntax_pos` globals into a struct which are pointed to by thread locals. Most of the changes here are indentation changes in test. It would probably be a good idea to ignore whitespace changes while reviewing. Some indentation is unchanged to avoid merge conflicts.

r? @michaelwoerister
  • Loading branch information
bors committed Mar 14, 2018
2 parents 24e679c + cbdf4ec commit d089fe9
Show file tree
Hide file tree
Showing 29 changed files with 1,257 additions and 1,043 deletions.
2 changes: 2 additions & 0 deletions src/Cargo.lock

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

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

fn optgroups() -> getopts::Options {
let mut opts = getopts::Options::new();
Expand All @@ -2411,61 +2412,66 @@ 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(|| {
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(|| {
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(|| {
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(|| {
let matches = optgroups()
.parse(&["-Awarnings".to_string(), "-Dwarnings".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(|| {
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
11 changes: 11 additions & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,17 @@ pub fn run_compiler<'a>(args: &[String],
file_loader: Option<Box<FileLoader + 'static>>,
emitter_dest: Option<Box<Write + Send>>)
-> (CompileResult, Option<Session>)
{
syntax::with_globals(|| {
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 + 'static>>,
emitter_dest: Option<Box<Write + Send>>)
-> (CompileResult, Option<Session>)
{
macro_rules! do_or_return {($expr: expr, $sess: expr) => {
match $expr {
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 @@ -29,6 +29,7 @@ use rustc::hir::map as hir_map;
use rustc::session::{self, config};
use rustc::session::config::{OutputFilenames, OutputTypes};
use rustc_data_structures::sync::Lrc;
use syntax;
use syntax::ast;
use syntax::abi::Abi;
use syntax::codemap::{CodeMap, FilePathMapping, FileName};
Expand Down Expand Up @@ -93,9 +94,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(|| {
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 d089fe9

Please sign in to comment.