about summary refs log tree commit diff
path: root/src/librustc_interface
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2020-07-06 10:53:14 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2020-07-09 14:11:44 +1000
commit81c5bb6a3fb02d1c1c3a4698e9e0e031ef2f4e4e (patch)
tree1415d42d29241899a5a7ebeef59a556256ab2bb5 /src/librustc_interface
parent2753fab7ce3647033146b07c8b6c9f4856a910b0 (diff)
Eliminate confusing "globals" terminology.
There are some structures that are called "globals", but are they global
to a compilation session, and not truly global. I have always found this
highly confusing, so this commit renames them as "session globals" and
adds a comment explaining things.

Also, the commit fixes an unnecessary nesting of `set()` calls
`src/librustc_errors/json/tests.rs`
Diffstat (limited to 'src/librustc_interface')
-rw-r--r--src/librustc_interface/interface.rs2
-rw-r--r--src/librustc_interface/tests.rs10
-rw-r--r--src/librustc_interface/util.rs21
3 files changed, 17 insertions, 16 deletions
diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs
index 920cc6021e6..4059022e7a5 100644
--- a/src/librustc_interface/interface.rs
+++ b/src/librustc_interface/interface.rs
@@ -74,7 +74,7 @@ impl Compiler {
 
 /// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
 pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
-    rustc_ast::with_default_globals(move || {
+    rustc_ast::with_default_session_globals(move || {
         let cfg = cfgspecs
             .into_iter()
             .map(|s| {
diff --git a/src/librustc_interface/tests.rs b/src/librustc_interface/tests.rs
index e35dbbc0c2f..651a77912c6 100644
--- a/src/librustc_interface/tests.rs
+++ b/src/librustc_interface/tests.rs
@@ -73,7 +73,7 @@ fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
 // When the user supplies --test we should implicitly supply --cfg test
 #[test]
 fn test_switch_implies_cfg_test() {
-    rustc_ast::with_default_globals(|| {
+    rustc_ast::with_default_session_globals(|| {
         let matches = optgroups().parse(&["--test".to_string()]).unwrap();
         let (sess, cfg) = mk_session(matches);
         let cfg = build_configuration(&sess, to_crate_config(cfg));
@@ -84,7 +84,7 @@ fn test_switch_implies_cfg_test() {
 // When the user supplies --test and --cfg test, don't implicitly add another --cfg test
 #[test]
 fn test_switch_implies_cfg_test_unless_cfg_test() {
-    rustc_ast::with_default_globals(|| {
+    rustc_ast::with_default_session_globals(|| {
         let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
         let (sess, cfg) = mk_session(matches);
         let cfg = build_configuration(&sess, to_crate_config(cfg));
@@ -96,20 +96,20 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
 
 #[test]
 fn test_can_print_warnings() {
-    rustc_ast::with_default_globals(|| {
+    rustc_ast::with_default_session_globals(|| {
         let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
         let (sess, _) = mk_session(matches);
         assert!(!sess.diagnostic().can_emit_warnings());
     });
 
-    rustc_ast::with_default_globals(|| {
+    rustc_ast::with_default_session_globals(|| {
         let matches =
             optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
         let (sess, _) = mk_session(matches);
         assert!(sess.diagnostic().can_emit_warnings());
     });
 
-    rustc_ast::with_default_globals(|| {
+    rustc_ast::with_default_session_globals(|| {
         let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
         let (sess, _) = mk_session(matches);
         assert!(sess.diagnostic().can_emit_warnings());
diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs
index 924908e5724..fe091e92062 100644
--- a/src/librustc_interface/util.rs
+++ b/src/librustc_interface/util.rs
@@ -141,7 +141,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
     crate::callbacks::setup_callbacks();
 
     scoped_thread(cfg, || {
-        rustc_ast::with_globals(edition, || {
+        rustc_ast::with_session_globals(edition, || {
             ty::tls::GCX_PTR.set(&Lock::new(0), || {
                 if let Some(stderr) = stderr {
                     io::set_panic(Some(box Sink(stderr.clone())));
@@ -177,16 +177,17 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
 
     let with_pool = move |pool: &ThreadPool| pool.install(move || f());
 
-    rustc_ast::with_globals(edition, || {
-        rustc_ast::GLOBALS.with(|syntax_globals| {
-            rustc_span::GLOBALS.with(|rustc_span_globals| {
-                // The main handler runs for each Rayon worker thread and sets up
-                // the thread local rustc uses. syntax_globals and rustc_span_globals are
-                // captured and set on the new threads. ty::tls::with_thread_locals sets up
-                // thread local callbacks from librustc_ast
+    rustc_ast::with_session_globals(edition, || {
+        rustc_ast::SESSION_GLOBALS.with(|ast_session_globals| {
+            rustc_span::SESSION_GLOBALS.with(|span_session_globals| {
+                // The main handler runs for each Rayon worker thread and sets
+                // up the thread local rustc uses. ast_session_globals and
+                // span_session_globals are captured and set on the new
+                // threads. ty::tls::with_thread_locals sets up thread local
+                // callbacks from librustc_ast.
                 let main_handler = move |thread: ThreadBuilder| {
-                    rustc_ast::GLOBALS.set(syntax_globals, || {
-                        rustc_span::GLOBALS.set(rustc_span_globals, || {
+                    rustc_ast::SESSION_GLOBALS.set(ast_session_globals, || {
+                        rustc_span::SESSION_GLOBALS.set(span_session_globals, || {
                             if let Some(stderr) = stderr {
                                 io::set_panic(Some(box Sink(stderr.clone())));
                             }