about summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-12-25 13:38:57 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2019-12-25 14:10:46 -0500
commitb98633b94c5354fbcb02bd0111f2aba5155c3190 (patch)
treeebfb6e277e20318795617fbd27f514aa708bc84e /src/librustc_errors
parented33453a37d602f34cc40c205f9b9b8a8aff88b5 (diff)
Store callbacks in global statics
The callbacks have precisely two states: the default, and the one
present throughout almost all of the rustc run (the filled in value
which has access to TyCtxt).

We used to store this as a thread local, and reset it on each thread to
the non-default value. But this is somewhat wasteful, since there is no
reason to set it globally -- while the callbacks themselves access TLS,
they do not do so in a manner that fails in when we do not have TLS to
work with.
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/lib.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 8f1437ee49c..b41eff408ed 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -17,11 +17,11 @@ use registry::Registry;
 use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
 use rustc_data_structures::stable_hasher::StableHasher;
 use rustc_data_structures::sync::{self, Lock, Lrc};
+use rustc_data_structures::AtomicRef;
 use syntax_pos::source_map::SourceMap;
 use syntax_pos::{Loc, MultiSpan, Span};
 
 use std::borrow::Cow;
-use std::cell::Cell;
 use std::panic;
 use std::path::Path;
 use std::{error, fmt};
@@ -313,8 +313,8 @@ pub enum StashKey {
 
 fn default_track_diagnostic(_: &Diagnostic) {}
 
-thread_local!(pub static TRACK_DIAGNOSTICS: Cell<fn(&Diagnostic)> =
-                Cell::new(default_track_diagnostic));
+pub static TRACK_DIAGNOSTICS: AtomicRef<fn(&Diagnostic)> =
+    AtomicRef::new(&(default_track_diagnostic as fn(&_)));
 
 #[derive(Copy, Clone, Default)]
 pub struct HandlerFlags {
@@ -734,9 +734,7 @@ impl HandlerInner {
             return;
         }
 
-        TRACK_DIAGNOSTICS.with(|track_diagnostics| {
-            track_diagnostics.get()(diagnostic);
-        });
+        (*TRACK_DIAGNOSTICS)(diagnostic);
 
         if let Some(ref code) = diagnostic.code {
             self.emitted_diagnostic_codes.insert(code.clone());