Skip to content

Commit d089fe9

Browse files
committed
Auto merge of #48811 - Zoxc:syntax-globals, r=michaelwoerister
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
2 parents 24e679c + cbdf4ec commit d089fe9

File tree

29 files changed

+1257
-1043
lines changed

29 files changed

+1257
-1043
lines changed

src/Cargo.lock

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

src/librustc/session/config.rs

+32-26
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,7 @@ mod tests {
23912391
use super::{Externs, OutputType, OutputTypes};
23922392
use rustc_back::{PanicStrategy, RelroLevel};
23932393
use syntax::symbol::Symbol;
2394+
use syntax;
23942395

23952396
fn optgroups() -> getopts::Options {
23962397
let mut opts = getopts::Options::new();
@@ -2411,61 +2412,66 @@ mod tests {
24112412
// When the user supplies --test we should implicitly supply --cfg test
24122413
#[test]
24132414
fn test_switch_implies_cfg_test() {
2414-
let matches = &match optgroups().parse(&["--test".to_string()]) {
2415-
Ok(m) => m,
2416-
Err(f) => panic!("test_switch_implies_cfg_test: {}", f),
2417-
};
2418-
let registry = errors::registry::Registry::new(&[]);
2419-
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2420-
let sess = build_session(sessopts, None, registry);
2421-
let cfg = build_configuration(&sess, cfg);
2422-
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2415+
syntax::with_globals(|| {
2416+
let matches = &match optgroups().parse(&["--test".to_string()]) {
2417+
Ok(m) => m,
2418+
Err(f) => panic!("test_switch_implies_cfg_test: {}", f),
2419+
};
2420+
let registry = errors::registry::Registry::new(&[]);
2421+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2422+
let sess = build_session(sessopts, None, registry);
2423+
let cfg = build_configuration(&sess, cfg);
2424+
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2425+
});
24232426
}
24242427

24252428
// When the user supplies --test and --cfg test, don't implicitly add
24262429
// another --cfg test
24272430
#[test]
24282431
fn test_switch_implies_cfg_test_unless_cfg_test() {
2429-
let matches = &match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
2430-
Ok(m) => m,
2431-
Err(f) => panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f),
2432-
};
2433-
let registry = errors::registry::Registry::new(&[]);
2434-
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2435-
let sess = build_session(sessopts, None, registry);
2436-
let cfg = build_configuration(&sess, cfg);
2437-
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2438-
assert!(test_items.next().is_some());
2439-
assert!(test_items.next().is_none());
2432+
syntax::with_globals(|| {
2433+
let matches = &match optgroups().parse(&["--test".to_string(),
2434+
"--cfg=test".to_string()]) {
2435+
Ok(m) => m,
2436+
Err(f) => panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f),
2437+
};
2438+
let registry = errors::registry::Registry::new(&[]);
2439+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2440+
let sess = build_session(sessopts, None, registry);
2441+
let cfg = build_configuration(&sess, cfg);
2442+
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2443+
assert!(test_items.next().is_some());
2444+
assert!(test_items.next().is_none());
2445+
});
24402446
}
24412447

24422448
#[test]
24432449
fn test_can_print_warnings() {
2444-
{
2450+
syntax::with_globals(|| {
24452451
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
24462452
let registry = errors::registry::Registry::new(&[]);
24472453
let (sessopts, _) = build_session_options_and_crate_config(&matches);
24482454
let sess = build_session(sessopts, None, registry);
24492455
assert!(!sess.diagnostic().flags.can_emit_warnings);
2450-
}
2456+
});
24512457

2452-
{
2458+
syntax::with_globals(|| {
24532459
let matches = optgroups()
24542460
.parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()])
24552461
.unwrap();
24562462
let registry = errors::registry::Registry::new(&[]);
24572463
let (sessopts, _) = build_session_options_and_crate_config(&matches);
24582464
let sess = build_session(sessopts, None, registry);
24592465
assert!(sess.diagnostic().flags.can_emit_warnings);
2460-
}
2466+
});
24612467

2462-
{
2468+
syntax::with_globals(|| {
24632469
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
24642470
let registry = errors::registry::Registry::new(&[]);
24652471
let (sessopts, _) = build_session_options_and_crate_config(&matches);
24662472
let sess = build_session(sessopts, None, registry);
24672473
assert!(sess.diagnostic().flags.can_emit_warnings);
2468-
}
2474+
});
24692475
}
24702476

24712477
#[test]

src/librustc_driver/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,17 @@ pub fn run_compiler<'a>(args: &[String],
447447
file_loader: Option<Box<FileLoader + 'static>>,
448448
emitter_dest: Option<Box<Write + Send>>)
449449
-> (CompileResult, Option<Session>)
450+
{
451+
syntax::with_globals(|| {
452+
run_compiler_impl(args, callbacks, file_loader, emitter_dest)
453+
})
454+
}
455+
456+
fn run_compiler_impl<'a>(args: &[String],
457+
callbacks: &mut CompilerCalls<'a>,
458+
file_loader: Option<Box<FileLoader + 'static>>,
459+
emitter_dest: Option<Box<Write + Send>>)
460+
-> (CompileResult, Option<Session>)
450461
{
451462
macro_rules! do_or_return {($expr: expr, $sess: expr) => {
452463
match $expr {

src/librustc_driver/test.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc::hir::map as hir_map;
2929
use rustc::session::{self, config};
3030
use rustc::session::config::{OutputFilenames, OutputTypes};
3131
use rustc_data_structures::sync::Lrc;
32+
use syntax;
3233
use syntax::ast;
3334
use syntax::abi::Abi;
3435
use syntax::codemap::{CodeMap, FilePathMapping, FileName};
@@ -93,9 +94,19 @@ fn errors(msgs: &[&str]) -> (Box<Emitter + Send>, usize) {
9394
}
9495

9596
fn test_env<F>(source_string: &str,
96-
(emitter, expected_err_count): (Box<Emitter + Send>, usize),
97+
args: (Box<Emitter + Send>, usize),
9798
body: F)
9899
where F: FnOnce(Env)
100+
{
101+
syntax::with_globals(|| {
102+
test_env_impl(source_string, args, body)
103+
});
104+
}
105+
106+
fn test_env_impl<F>(source_string: &str,
107+
(emitter, expected_err_count): (Box<Emitter + Send>, usize),
108+
body: F)
109+
where F: FnOnce(Env)
99110
{
100111
let mut options = config::basic_options();
101112
options.debugging_opts.verbose = true;

0 commit comments

Comments
 (0)