about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_data_structures/Cargo.toml1
-rw-r--r--compiler/rustc_data_structures/src/jobserver.rs52
-rw-r--r--compiler/rustc_driver/Cargo.toml1
-rw-r--r--compiler/rustc_driver/src/lib.rs12
-rw-r--r--compiler/rustc_feature/Cargo.toml1
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs10
-rw-r--r--compiler/rustc_feature/src/lib.rs2
-rw-r--r--compiler/rustc_hir/Cargo.toml1
-rw-r--r--compiler/rustc_hir/src/lang_items.rs16
-rw-r--r--compiler/rustc_hir/src/lib.rs1
-rw-r--r--compiler/rustc_hir/src/weak_lang_items.rs14
-rw-r--r--compiler/rustc_interface/Cargo.toml1
-rw-r--r--compiler/rustc_interface/src/passes.rs6
-rw-r--r--compiler/rustc_interface/src/util.rs4
14 files changed, 56 insertions, 66 deletions
diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml
index 464f8c984dd..fcae9b936ed 100644
--- a/compiler/rustc_data_structures/Cargo.toml
+++ b/compiler/rustc_data_structures/Cargo.toml
@@ -12,7 +12,6 @@ ena = "0.14"
 indexmap = "1.5.1"
 tracing = "0.1"
 jobserver_crate = { version = "0.1.13", package = "jobserver" }
-lazy_static = "1"
 rustc_serialize = { path = "../rustc_serialize" }
 rustc_macros = { path = "../rustc_macros" }
 rustc_graphviz = { path = "../rustc_graphviz" }
diff --git a/compiler/rustc_data_structures/src/jobserver.rs b/compiler/rustc_data_structures/src/jobserver.rs
index a811c88839d..41605afb44e 100644
--- a/compiler/rustc_data_structures/src/jobserver.rs
+++ b/compiler/rustc_data_structures/src/jobserver.rs
@@ -1,33 +1,31 @@
 pub use jobserver_crate::Client;
-use lazy_static::lazy_static;
+use std::lazy::SyncLazy;
 
-lazy_static! {
-    // We can only call `from_env` once per process
+// We can only call `from_env` once per process
 
-    // Note that this is unsafe because it may misinterpret file descriptors
-    // on Unix as jobserver file descriptors. We hopefully execute this near
-    // the beginning of the process though to ensure we don't get false
-    // positives, or in other words we try to execute this before we open
-    // any file descriptors ourselves.
-    //
-    // Pick a "reasonable maximum" if we don't otherwise have
-    // a jobserver in our environment, capping out at 32 so we
-    // don't take everything down by hogging the process run queue.
-    // The fixed number is used to have deterministic compilation
-    // across machines.
-    //
-    // Also note that we stick this in a global because there could be
-    // multiple rustc instances in this process, and the jobserver is
-    // per-process.
-    static ref GLOBAL_CLIENT: Client = unsafe {
-        Client::from_env().unwrap_or_else(|| {
-            let client = Client::new(32).expect("failed to create jobserver");
-            // Acquire a token for the main thread which we can release later
-            client.acquire_raw().ok();
-            client
-        })
-    };
-}
+// Note that this is unsafe because it may misinterpret file descriptors
+// on Unix as jobserver file descriptors. We hopefully execute this near
+// the beginning of the process though to ensure we don't get false
+// positives, or in other words we try to execute this before we open
+// any file descriptors ourselves.
+//
+// Pick a "reasonable maximum" if we don't otherwise have
+// a jobserver in our environment, capping out at 32 so we
+// don't take everything down by hogging the process run queue.
+// The fixed number is used to have deterministic compilation
+// across machines.
+//
+// Also note that we stick this in a global because there could be
+// multiple rustc instances in this process, and the jobserver is
+// per-process.
+static GLOBAL_CLIENT: SyncLazy<Client> = SyncLazy::new(|| unsafe {
+    Client::from_env().unwrap_or_else(|| {
+        let client = Client::new(32).expect("failed to create jobserver");
+        // Acquire a token for the main thread which we can release later
+        client.acquire_raw().ok();
+        client
+    })
+});
 
 pub fn client() -> Client {
     GLOBAL_CLIENT.clone()
diff --git a/compiler/rustc_driver/Cargo.toml b/compiler/rustc_driver/Cargo.toml
index 76e8592254c..0d9dcb262b2 100644
--- a/compiler/rustc_driver/Cargo.toml
+++ b/compiler/rustc_driver/Cargo.toml
@@ -8,7 +8,6 @@ edition = "2018"
 crate-type = ["dylib"]
 
 [dependencies]
-lazy_static = "1.0"
 libc = "0.2"
 tracing = { version = "0.1.18", features = ["release_max_level_info"]  }
 tracing-subscriber = { version = "0.2.10", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs
index 0d8332a20ae..c277e314d0e 100644
--- a/compiler/rustc_driver/src/lib.rs
+++ b/compiler/rustc_driver/src/lib.rs
@@ -11,8 +11,6 @@
 
 #[macro_use]
 extern crate tracing;
-#[macro_use]
-extern crate lazy_static;
 
 pub extern crate rustc_plugin_impl as plugin;
 
@@ -49,6 +47,7 @@ use std::env;
 use std::ffi::OsString;
 use std::fs;
 use std::io::{self, Read, Write};
+use std::lazy::SyncLazy;
 use std::mem;
 use std::panic::{self, catch_unwind};
 use std::path::PathBuf;
@@ -1142,13 +1141,12 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
     }
 }
 
-lazy_static! {
-    static ref DEFAULT_HOOK: Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static> = {
+static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
+    SyncLazy::new(|| {
         let hook = panic::take_hook();
         panic::set_hook(Box::new(|info| report_ice(info, BUG_REPORT_URL)));
         hook
-    };
-}
+    });
 
 /// Prints the ICE message, including backtrace and query stack.
 ///
@@ -1223,7 +1221,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
 ///
 /// A custom rustc driver can skip calling this to set up a custom ICE hook.
 pub fn install_ice_hook() {
-    lazy_static::initialize(&DEFAULT_HOOK);
+    SyncLazy::force(&DEFAULT_HOOK);
 }
 
 /// This allows tools to enable rust logging without having to magically match rustc's
diff --git a/compiler/rustc_feature/Cargo.toml b/compiler/rustc_feature/Cargo.toml
index 3f8047e931e..7a06bce13c8 100644
--- a/compiler/rustc_feature/Cargo.toml
+++ b/compiler/rustc_feature/Cargo.toml
@@ -9,5 +9,4 @@ doctest = false
 
 [dependencies]
 rustc_data_structures = { path = "../rustc_data_structures" }
-lazy_static = "1.0.0"
 rustc_span = { path = "../rustc_span" }
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index 879f06f89a7..fc122db8ac1 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -5,10 +5,11 @@ use AttributeType::*;
 
 use crate::{Features, Stability};
 
-use lazy_static::lazy_static;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_span::symbol::{sym, Symbol};
 
+use std::lazy::SyncLazy;
+
 type GateFn = fn(&Features) -> bool;
 
 macro_rules! cfg_fn {
@@ -589,8 +590,8 @@ pub fn is_builtin_attr_name(name: Symbol) -> bool {
     BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
 }
 
-lazy_static! {
-    pub static ref BUILTIN_ATTRIBUTE_MAP: FxHashMap<Symbol, &'static BuiltinAttribute> = {
+pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &'static BuiltinAttribute>> =
+    SyncLazy::new(|| {
         let mut map = FxHashMap::default();
         for attr in BUILTIN_ATTRIBUTES.iter() {
             if map.insert(attr.0, attr).is_some() {
@@ -598,5 +599,4 @@ lazy_static! {
             }
         }
         map
-    };
-}
+    });
diff --git a/compiler/rustc_feature/src/lib.rs b/compiler/rustc_feature/src/lib.rs
index f8bf0315d0c..4393368cd45 100644
--- a/compiler/rustc_feature/src/lib.rs
+++ b/compiler/rustc_feature/src/lib.rs
@@ -11,6 +11,8 @@
 //! even if it is stabilized or removed, *do not remove it*. Instead, move the
 //! symbol to the `accepted` or `removed` modules respectively.
 
+#![feature(once_cell)]
+
 mod accepted;
 mod active;
 mod builtin_attrs;
diff --git a/compiler/rustc_hir/Cargo.toml b/compiler/rustc_hir/Cargo.toml
index ed295ff0058..b24c208c76a 100644
--- a/compiler/rustc_hir/Cargo.toml
+++ b/compiler/rustc_hir/Cargo.toml
@@ -15,6 +15,5 @@ rustc_index = { path = "../rustc_index" }
 rustc_span = { path = "../rustc_span" }
 rustc_serialize = { path = "../rustc_serialize" }
 rustc_ast = { path = "../rustc_ast" }
-lazy_static = "1"
 tracing = "0.1"
 smallvec = { version = "1.0", features = ["union", "may_dangle"] }
diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs
index acf6847c014..5e4c03bec83 100644
--- a/compiler/rustc_hir/src/lang_items.rs
+++ b/compiler/rustc_hir/src/lang_items.rs
@@ -17,7 +17,7 @@ use rustc_macros::HashStable_Generic;
 use rustc_span::symbol::{kw, sym, Symbol};
 use rustc_span::Span;
 
-use lazy_static::lazy_static;
+use std::lazy::SyncLazy;
 
 pub enum LangItemGroup {
     Op,
@@ -117,14 +117,12 @@ macro_rules! language_item_table {
             )*
         }
 
-        lazy_static! {
-            /// A mapping from the name of the lang item to its order and the form it must be of.
-            pub static ref ITEM_REFS: FxHashMap<Symbol, (usize, Target)> = {
-                let mut item_refs = FxHashMap::default();
-                $( item_refs.insert($name, (LangItem::$variant as usize, $target)); )*
-                item_refs
-            };
-        }
+        /// A mapping from the name of the lang item to its order and the form it must be of.
+        pub static ITEM_REFS: SyncLazy<FxHashMap<Symbol, (usize, Target)>> = SyncLazy::new(|| {
+            let mut item_refs = FxHashMap::default();
+            $( item_refs.insert($name, (LangItem::$variant as usize, $target)); )*
+            item_refs
+        });
 
 // End of the macro
     }
diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs
index 19ea1de5683..c69a9b063ae 100644
--- a/compiler/rustc_hir/src/lib.rs
+++ b/compiler/rustc_hir/src/lib.rs
@@ -6,6 +6,7 @@
 #![feature(const_fn)] // For the unsizing cast on `&[]`
 #![feature(const_panic)]
 #![feature(in_band_lifetimes)]
+#![feature(once_cell)]
 #![feature(or_patterns)]
 #![recursion_limit = "256"]
 
diff --git a/compiler/rustc_hir/src/weak_lang_items.rs b/compiler/rustc_hir/src/weak_lang_items.rs
index 129eec7d29e..52f28bf8f4c 100644
--- a/compiler/rustc_hir/src/weak_lang_items.rs
+++ b/compiler/rustc_hir/src/weak_lang_items.rs
@@ -7,18 +7,16 @@ use rustc_ast as ast;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_span::symbol::{sym, Symbol};
 
-use lazy_static::lazy_static;
+use std::lazy::SyncLazy;
 
 macro_rules! weak_lang_items {
     ($($name:ident, $item:ident, $sym:ident;)*) => (
 
-lazy_static! {
-    pub static ref WEAK_ITEMS_REFS: FxHashMap<Symbol, LangItem> = {
-        let mut map = FxHashMap::default();
-        $(map.insert(sym::$name, LangItem::$item);)*
-        map
-    };
-}
+pub static WEAK_ITEMS_REFS: SyncLazy<FxHashMap<Symbol, LangItem>> = SyncLazy::new(|| {
+    let mut map = FxHashMap::default();
+    $(map.insert(sym::$name, LangItem::$item);)*
+    map
+});
 
 /// The `check_name` argument avoids the need for `librustc_hir` to depend on
 /// `librustc_session`.
diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml
index 9affe4ec6d8..e214493a567 100644
--- a/compiler/rustc_interface/Cargo.toml
+++ b/compiler/rustc_interface/Cargo.toml
@@ -43,7 +43,6 @@ rustc_resolve = { path = "../rustc_resolve" }
 rustc_trait_selection = { path = "../rustc_trait_selection" }
 rustc_ty = { path = "../rustc_ty" }
 tempfile = "3.0.5"
-once_cell = "1"
 
 [target.'cfg(windows)'.dependencies]
 winapi = { version = "0.3", features = ["libloaderapi"] }
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs
index f33dcec8ba7..66d3765d347 100644
--- a/compiler/rustc_interface/src/passes.rs
+++ b/compiler/rustc_interface/src/passes.rs
@@ -2,7 +2,6 @@ use crate::interface::{Compiler, Result};
 use crate::proc_macro_decls;
 use crate::util;
 
-use once_cell::sync::Lazy;
 use rustc_ast::mut_visit::MutVisitor;
 use rustc_ast::{self as ast, visit};
 use rustc_codegen_ssa::back::link::emit_metadata;
@@ -46,6 +45,7 @@ use std::any::Any;
 use std::cell::RefCell;
 use std::ffi::OsString;
 use std::io::{self, BufWriter, Write};
+use std::lazy::SyncLazy;
 use std::path::PathBuf;
 use std::rc::Rc;
 use std::{env, fs, iter, mem};
@@ -681,7 +681,7 @@ pub fn prepare_outputs(
     Ok(outputs)
 }
 
-pub static DEFAULT_QUERY_PROVIDERS: Lazy<Providers> = Lazy::new(|| {
+pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
     let providers = &mut Providers::default();
     providers.analysis = analysis;
     proc_macro_decls::provide(providers);
@@ -704,7 +704,7 @@ pub static DEFAULT_QUERY_PROVIDERS: Lazy<Providers> = Lazy::new(|| {
     *providers
 });
 
-pub static DEFAULT_EXTERN_QUERY_PROVIDERS: Lazy<Providers> = Lazy::new(|| {
+pub static DEFAULT_EXTERN_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
     let mut extern_providers = *DEFAULT_QUERY_PROVIDERS;
     rustc_metadata::provide_extern(&mut extern_providers);
     rustc_codegen_ssa::provide_extern(&mut extern_providers);
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs
index 8816ba198cf..b1b39fd1ad2 100644
--- a/compiler/rustc_interface/src/util.rs
+++ b/compiler/rustc_interface/src/util.rs
@@ -25,6 +25,7 @@ use rustc_span::symbol::{sym, Symbol};
 use smallvec::SmallVec;
 use std::env;
 use std::io::{self, Write};
+use std::lazy::SyncOnceCell;
 use std::mem;
 use std::ops::DerefMut;
 use std::path::{Path, PathBuf};
@@ -243,8 +244,7 @@ pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
 // loading, so we leave the code here. It is potentially useful for other tools
 // that want to invoke the rustc binary while linking to rustc as well.
 pub fn rustc_path<'a>() -> Option<&'a Path> {
-    static RUSTC_PATH: once_cell::sync::OnceCell<Option<PathBuf>> =
-        once_cell::sync::OnceCell::new();
+    static RUSTC_PATH: SyncOnceCell<Option<PathBuf>> = SyncOnceCell::new();
 
     const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR");