Skip to content

Commit f7d9040

Browse files
committed
Remove syntax and syntax_pos thread locals
1 parent 9e078bd commit f7d9040

File tree

29 files changed

+1292
-1133
lines changed

29 files changed

+1292
-1133
lines changed

src/Cargo.lock

+3-1
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
@@ -2090,6 +2090,7 @@ mod tests {
20902090
use super::{OutputType, OutputTypes, Externs};
20912091
use rustc_back::{PanicStrategy, RelroLevel};
20922092
use syntax::symbol::Symbol;
2093+
use syntax;
20932094

20942095
fn optgroups() -> getopts::Options {
20952096
let mut opts = getopts::Options::new();
@@ -2110,51 +2111,55 @@ mod tests {
21102111
// When the user supplies --test we should implicitly supply --cfg test
21112112
#[test]
21122113
fn test_switch_implies_cfg_test() {
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)));
2114+
syntax::with_globals(&syntax::Globals::new(), || {
2115+
let matches =
2116+
&match optgroups().parse(&["--test".to_string()]) {
2117+
Ok(m) => m,
2118+
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
2119+
};
2120+
let registry = errors::registry::Registry::new(&[]);
2121+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2122+
let sess = build_session(sessopts, None, registry);
2123+
let cfg = build_configuration(&sess, cfg);
2124+
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2125+
});
21232126
}
21242127

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

21452150
#[test]
21462151
fn test_can_print_warnings() {
2147-
{
2152+
syntax::with_globals(&syntax::Globals::new(), || {
21482153
let matches = optgroups().parse(&[
21492154
"-Awarnings".to_string()
21502155
]).unwrap();
21512156
let registry = errors::registry::Registry::new(&[]);
21522157
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21532158
let sess = build_session(sessopts, None, registry);
21542159
assert!(!sess.diagnostic().flags.can_emit_warnings);
2155-
}
2160+
});
21562161

2157-
{
2162+
syntax::with_globals(&syntax::Globals::new(), || {
21582163
let matches = optgroups().parse(&[
21592164
"-Awarnings".to_string(),
21602165
"-Dwarnings".to_string()
@@ -2163,17 +2168,17 @@ mod tests {
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
"-Adead_code".to_string()
21712176
]).unwrap();
21722177
let registry = errors::registry::Registry::new(&[]);
21732178
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21742179
let sess = build_session(sessopts, None, registry);
21752180
assert!(sess.diagnostic().flags.can_emit_warnings);
2176-
}
2181+
});
21772182
}
21782183

21792184
#[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)