Skip to content

Commit 057c727

Browse files
committed
Remove syntax and syntax_pos thread locals
1 parent 2bbed5f commit 057c727

File tree

30 files changed

+1292
-1135
lines changed

30 files changed

+1292
-1135
lines changed

Diff for: src/Cargo.lock

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

Diff for: src/librustc/session/config.rs

+35-30
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,7 @@ mod tests {
20502050
use super::{OutputType, OutputTypes, Externs};
20512051
use rustc_back::{PanicStrategy, RelroLevel};
20522052
use syntax::symbol::Symbol;
2053+
use syntax;
20532054

20542055
fn optgroups() -> getopts::Options {
20552056
let mut opts = getopts::Options::new();
@@ -2070,51 +2071,55 @@ mod tests {
20702071
// When the user supplies --test we should implicitly supply --cfg test
20712072
#[test]
20722073
fn test_switch_implies_cfg_test() {
2073-
let matches =
2074-
&match optgroups().parse(&["--test".to_string()]) {
2075-
Ok(m) => m,
2076-
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
2077-
};
2078-
let registry = errors::registry::Registry::new(&[]);
2079-
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2080-
let sess = build_session(sessopts, None, registry);
2081-
let cfg = build_configuration(&sess, cfg);
2082-
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2074+
syntax::with_globals(&syntax::Globals::new(), || {
2075+
let matches =
2076+
&match optgroups().parse(&["--test".to_string()]) {
2077+
Ok(m) => m,
2078+
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
2079+
};
2080+
let registry = errors::registry::Registry::new(&[]);
2081+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2082+
let sess = build_session(sessopts, None, registry);
2083+
let cfg = build_configuration(&sess, cfg);
2084+
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2085+
});
20832086
}
20842087

20852088
// When the user supplies --test and --cfg test, don't implicitly add
20862089
// another --cfg test
20872090
#[test]
20882091
fn test_switch_implies_cfg_test_unless_cfg_test() {
2089-
let matches =
2090-
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
2091-
Ok(m) => m,
2092-
Err(f) => {
2093-
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
2094-
}
2095-
};
2096-
let registry = errors::registry::Registry::new(&[]);
2097-
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2098-
let sess = build_session(sessopts, None, registry);
2099-
let cfg = build_configuration(&sess, cfg);
2100-
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2101-
assert!(test_items.next().is_some());
2102-
assert!(test_items.next().is_none());
2092+
syntax::with_globals(&syntax::Globals::new(), || {
2093+
let matches =
2094+
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
2095+
Ok(m) => m,
2096+
Err(f) => {
2097+
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
2098+
}
2099+
};
2100+
let registry = errors::registry::Registry::new(&[]);
2101+
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2102+
let sess = build_session(sessopts, None, registry);
2103+
let cfg = build_configuration(&sess, cfg);
2104+
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2105+
assert!(test_items.next().is_some());
2106+
assert!(test_items.next().is_none());
2107+
});
21032108
}
21042109

21052110
#[test]
21062111
fn test_can_print_warnings() {
2107-
{
2112+
syntax::with_globals(&syntax::Globals::new(), || {
21082113
let matches = optgroups().parse(&[
21092114
"-Awarnings".to_string()
21102115
]).unwrap();
21112116
let registry = errors::registry::Registry::new(&[]);
21122117
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21132118
let sess = build_session(sessopts, None, registry);
21142119
assert!(!sess.diagnostic().flags.can_emit_warnings);
2115-
}
2120+
});
21162121

2117-
{
2122+
syntax::with_globals(&syntax::Globals::new(), || {
21182123
let matches = optgroups().parse(&[
21192124
"-Awarnings".to_string(),
21202125
"-Dwarnings".to_string()
@@ -2123,17 +2128,17 @@ mod tests {
21232128
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21242129
let sess = build_session(sessopts, None, registry);
21252130
assert!(sess.diagnostic().flags.can_emit_warnings);
2126-
}
2131+
});
21272132

2128-
{
2133+
syntax::with_globals(&syntax::Globals::new(), || {
21292134
let matches = optgroups().parse(&[
21302135
"-Adead_code".to_string()
21312136
]).unwrap();
21322137
let registry = errors::registry::Registry::new(&[]);
21332138
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21342139
let sess = build_session(sessopts, None, registry);
21352140
assert!(sess.diagnostic().flags.can_emit_warnings);
2136-
}
2141+
});
21372142
}
21382143

21392144
#[test]

Diff for: 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")

Diff for: 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 {
@@ -1187,7 +1198,9 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
11871198
cfg = cfg.stack_size(STACK_SIZE);
11881199
}
11891200

1190-
let thread = cfg.spawn(f);
1201+
let thread = cfg.spawn(|| {
1202+
syntax::with_globals(&syntax::Globals::new(), || f())
1203+
});
11911204
thread.unwrap().join()
11921205
}
11931206

Diff for: src/librustc_driver/pretty.rs

-2
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
974974
hir_map,
975975
analysis,
976976
resolutions,
977-
arena,
978977
arenas,
979978
output_filenames,
980979
crate_name,
@@ -1025,7 +1024,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
10251024
hir_map,
10261025
analysis,
10271026
resolutions,
1028-
arena,
10291027
arenas,
10301028
output_filenames,
10311029
crate_name,

Diff for: 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)