Skip to content

Commit f6ba272

Browse files
committed
Remove syntax and syntax_pos thread locals
1 parent b42ff9b commit f6ba272

File tree

29 files changed

+1291
-1132
lines changed

29 files changed

+1291
-1132
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

+35-30
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,7 @@ mod tests {
20882088
use super::{OutputType, OutputTypes, Externs};
20892089
use rustc_back::{PanicStrategy, RelroLevel};
20902090
use syntax::symbol::Symbol;
2091+
use syntax;
20912092

20922093
fn optgroups() -> getopts::Options {
20932094
let mut opts = getopts::Options::new();
@@ -2108,51 +2109,55 @@ mod tests {
21082109
// When the user supplies --test we should implicitly supply --cfg test
21092110
#[test]
21102111
fn test_switch_implies_cfg_test() {
2111-
let matches =
2112-
&match optgroups().parse(&["--test".to_string()]) {
2113-
Ok(m) => m,
2114-
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
2115-
};
2116-
let registry = errors::registry::Registry::new(&[]);
2117-
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2118-
let sess = build_session(sessopts, None, registry);
2119-
let cfg = build_configuration(&sess, cfg);
2120-
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2112+
syntax::with_globals(&syntax::Globals::new(), || {
2113+
let matches =
2114+
&match optgroups().parse(&["--test".to_string()]) {
2115+
Ok(m) => m,
2116+
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
2117+
};
2118+
let registry = errors::registry::Registry::new(&[]);
2119+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2120+
let sess = build_session(sessopts, None, registry);
2121+
let cfg = build_configuration(&sess, cfg);
2122+
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2123+
});
21212124
}
21222125

21232126
// When the user supplies --test and --cfg test, don't implicitly add
21242127
// another --cfg test
21252128
#[test]
21262129
fn test_switch_implies_cfg_test_unless_cfg_test() {
2127-
let matches =
2128-
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
2129-
Ok(m) => m,
2130-
Err(f) => {
2131-
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
2132-
}
2133-
};
2134-
let registry = errors::registry::Registry::new(&[]);
2135-
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2136-
let sess = build_session(sessopts, None, registry);
2137-
let cfg = build_configuration(&sess, cfg);
2138-
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2139-
assert!(test_items.next().is_some());
2140-
assert!(test_items.next().is_none());
2130+
syntax::with_globals(&syntax::Globals::new(), || {
2131+
let matches =
2132+
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
2133+
Ok(m) => m,
2134+
Err(f) => {
2135+
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
2136+
}
2137+
};
2138+
let registry = errors::registry::Registry::new(&[]);
2139+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2140+
let sess = build_session(sessopts, None, registry);
2141+
let cfg = build_configuration(&sess, cfg);
2142+
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2143+
assert!(test_items.next().is_some());
2144+
assert!(test_items.next().is_none());
2145+
});
21412146
}
21422147

21432148
#[test]
21442149
fn test_can_print_warnings() {
2145-
{
2150+
syntax::with_globals(&syntax::Globals::new(), || {
21462151
let matches = optgroups().parse(&[
21472152
"-Awarnings".to_string()
21482153
]).unwrap();
21492154
let registry = errors::registry::Registry::new(&[]);
21502155
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21512156
let sess = build_session(sessopts, None, registry);
21522157
assert!(!sess.diagnostic().flags.can_emit_warnings);
2153-
}
2158+
});
21542159

2155-
{
2160+
syntax::with_globals(&syntax::Globals::new(), || {
21562161
let matches = optgroups().parse(&[
21572162
"-Awarnings".to_string(),
21582163
"-Dwarnings".to_string()
@@ -2161,17 +2166,17 @@ mod tests {
21612166
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21622167
let sess = build_session(sessopts, None, registry);
21632168
assert!(sess.diagnostic().flags.can_emit_warnings);
2164-
}
2169+
});
21652170

2166-
{
2171+
syntax::with_globals(&syntax::Globals::new(), || {
21672172
let matches = optgroups().parse(&[
21682173
"-Adead_code".to_string()
21692174
]).unwrap();
21702175
let registry = errors::registry::Registry::new(&[]);
21712176
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21722177
let sess = build_session(sessopts, None, registry);
21732178
assert!(sess.diagnostic().flags.can_emit_warnings);
2174-
}
2179+
});
21752180
}
21762181

21772182
#[test]

src/librustc_data_structures/sync.rs

-30
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
//!
2727
//! `MTLock` is a mutex which disappears if cfg!(parallel_queries) is false.
2828
//!
29-
//! `rustc_global!` gives us a way to declare variables which are intended to be
30-
//! global for the current rustc session. This currently maps to thread-locals,
31-
//! since rustdoc uses the rustc libraries in multiple threads.
32-
//! These globals should eventually be moved into the `Session` structure.
33-
//!
3429
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
3530
//! depending on the value of cfg!(parallel_queries).
3631
@@ -266,31 +261,6 @@ cfg_if! {
266261
}
267262
}
268263

269-
#[macro_export]
270-
#[allow_internal_unstable]
271-
macro_rules! rustc_global {
272-
// empty (base case for the recursion)
273-
() => {};
274-
275-
// process multiple declarations
276-
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => (
277-
thread_local!($(#[$attr])* $vis static $name: $t = $init);
278-
rustc_global!($($rest)*);
279-
);
280-
281-
// handle a single declaration
282-
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => (
283-
thread_local!($(#[$attr])* $vis static $name: $t = $init);
284-
);
285-
}
286-
287-
#[macro_export]
288-
macro_rules! rustc_access_global {
289-
($name:path, $callback:expr) => {
290-
$name.with($callback)
291-
}
292-
}
293-
294264
impl<T: Copy + Debug> Debug for LockCell<T> {
295265
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
296266
f.debug_struct("LockCell")

src/librustc_driver/lib.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ pub fn run_compiler<'a>(args: &[String],
192192
file_loader: Option<Box<FileLoader + Send + Sync + 'static>>,
193193
emitter_dest: Option<Box<Write + Send>>)
194194
-> (CompileResult, Option<Session>)
195+
{
196+
syntax::with_globals(&syntax::Globals::new(), || {
197+
run_compiler_impl(args, callbacks, file_loader, emitter_dest)
198+
})
199+
}
200+
201+
fn run_compiler_impl<'a>(args: &[String],
202+
callbacks: &mut CompilerCalls<'a>,
203+
file_loader: Option<Box<FileLoader + Send + Sync + 'static>>,
204+
emitter_dest: Option<Box<Write + Send>>)
205+
-> (CompileResult, Option<Session>)
195206
{
196207
macro_rules! do_or_return {($expr: expr, $sess: expr) => {
197208
match $expr {
@@ -1189,7 +1200,9 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
11891200
cfg = cfg.stack_size(STACK_SIZE);
11901201
}
11911202

1192-
let thread = cfg.spawn(f);
1203+
let thread = cfg.spawn(|| {
1204+
syntax::with_globals(&syntax::Globals::new(), || f())
1205+
});
11931206
thread.unwrap().join()
11941207
}
11951208

src/librustc_driver/test.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use rustc::session::config::{OutputFilenames, OutputTypes};
3333
use rustc_trans_utils::trans_crate::TransCrate;
3434
use std::rc::Rc;
3535
use rustc_data_structures::sync::Lrc;
36+
use syntax;
3637
use syntax::ast;
3738
use syntax::abi::Abi;
3839
use syntax::codemap::{CodeMap, FilePathMapping};
@@ -97,9 +98,19 @@ fn errors(msgs: &[&str]) -> (Box<Emitter + Send>, usize) {
9798
}
9899

99100
fn test_env<F>(source_string: &str,
100-
(emitter, expected_err_count): (Box<Emitter + Send>, usize),
101+
args: (Box<Emitter + Send>, usize),
101102
body: F)
102103
where F: FnOnce(Env)
104+
{
105+
syntax::with_globals(&syntax::Globals::new(), || {
106+
test_env_impl(source_string, args, body)
107+
});
108+
}
109+
110+
fn test_env_impl<F>(source_string: &str,
111+
(emitter, expected_err_count): (Box<Emitter + Send>, usize),
112+
body: F)
113+
where F: FnOnce(Env)
103114
{
104115
let mut options = config::basic_options();
105116
options.debugging_opts.verbose = true;

0 commit comments

Comments
 (0)