Skip to content

Commit a46f81e

Browse files
committed
Remove syntax and syntax_pos thread locals
1 parent 844c812 commit a46f81e

File tree

29 files changed

+1296
-1134
lines changed

29 files changed

+1296
-1134
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
@@ -2101,6 +2101,7 @@ mod tests {
21012101
use super::{OutputType, OutputTypes, Externs};
21022102
use rustc_back::{PanicStrategy, RelroLevel};
21032103
use syntax::symbol::Symbol;
2104+
use syntax;
21042105

21052106
fn optgroups() -> getopts::Options {
21062107
let mut opts = getopts::Options::new();
@@ -2121,51 +2122,55 @@ mod tests {
21212122
// When the user supplies --test we should implicitly supply --cfg test
21222123
#[test]
21232124
fn test_switch_implies_cfg_test() {
2124-
let matches =
2125-
&match optgroups().parse(&["--test".to_string()]) {
2126-
Ok(m) => m,
2127-
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
2128-
};
2129-
let registry = errors::registry::Registry::new(&[]);
2130-
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2131-
let sess = build_session(sessopts, None, registry);
2132-
let cfg = build_configuration(&sess, cfg);
2133-
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2125+
syntax::with_globals(&syntax::Globals::new(), || {
2126+
let matches =
2127+
&match optgroups().parse(&["--test".to_string()]) {
2128+
Ok(m) => m,
2129+
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
2130+
};
2131+
let registry = errors::registry::Registry::new(&[]);
2132+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2133+
let sess = build_session(sessopts, None, registry);
2134+
let cfg = build_configuration(&sess, cfg);
2135+
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2136+
});
21342137
}
21352138

21362139
// When the user supplies --test and --cfg test, don't implicitly add
21372140
// another --cfg test
21382141
#[test]
21392142
fn test_switch_implies_cfg_test_unless_cfg_test() {
2140-
let matches =
2141-
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
2142-
Ok(m) => m,
2143-
Err(f) => {
2144-
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
2145-
}
2146-
};
2147-
let registry = errors::registry::Registry::new(&[]);
2148-
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2149-
let sess = build_session(sessopts, None, registry);
2150-
let cfg = build_configuration(&sess, cfg);
2151-
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2152-
assert!(test_items.next().is_some());
2153-
assert!(test_items.next().is_none());
2143+
syntax::with_globals(&syntax::Globals::new(), || {
2144+
let matches =
2145+
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
2146+
Ok(m) => m,
2147+
Err(f) => {
2148+
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
2149+
}
2150+
};
2151+
let registry = errors::registry::Registry::new(&[]);
2152+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2153+
let sess = build_session(sessopts, None, registry);
2154+
let cfg = build_configuration(&sess, cfg);
2155+
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2156+
assert!(test_items.next().is_some());
2157+
assert!(test_items.next().is_none());
2158+
});
21542159
}
21552160

21562161
#[test]
21572162
fn test_can_print_warnings() {
2158-
{
2163+
syntax::with_globals(&syntax::Globals::new(), || {
21592164
let matches = optgroups().parse(&[
21602165
"-Awarnings".to_string()
21612166
]).unwrap();
21622167
let registry = errors::registry::Registry::new(&[]);
21632168
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21642169
let sess = build_session(sessopts, None, registry);
21652170
assert!(!sess.diagnostic().flags.can_emit_warnings);
2166-
}
2171+
});
21672172

2168-
{
2173+
syntax::with_globals(&syntax::Globals::new(), || {
21692174
let matches = optgroups().parse(&[
21702175
"-Awarnings".to_string(),
21712176
"-Dwarnings".to_string()
@@ -2174,17 +2179,17 @@ mod tests {
21742179
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21752180
let sess = build_session(sessopts, None, registry);
21762181
assert!(sess.diagnostic().flags.can_emit_warnings);
2177-
}
2182+
});
21782183

2179-
{
2184+
syntax::with_globals(&syntax::Globals::new(), || {
21802185
let matches = optgroups().parse(&[
21812186
"-Adead_code".to_string()
21822187
]).unwrap();
21832188
let registry = errors::registry::Registry::new(&[]);
21842189
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21852190
let sess = build_session(sessopts, None, registry);
21862191
assert!(sess.diagnostic().flags.can_emit_warnings);
2187-
}
2192+
});
21882193
}
21892194

21902195
#[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
@@ -264,31 +259,6 @@ cfg_if! {
264259
pub fn assert_sync<T: ?Sized + Sync>() {}
265260
pub fn assert_send_sync_val<T: ?Sized + Sync + Send>(_t: &T) {}
266261

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