Skip to content

Commit

Permalink
Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Jun 16, 2022
1 parent 7c360dc commit c1a2db3
Show file tree
Hide file tree
Showing 32 changed files with 847 additions and 819 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/driver/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_span::Symbol;

use cranelift_jit::{JITBuilder, JITModule};

// FIXME use std::lazy::SyncOnceCell once it stabilizes
// FIXME use std::sync::OnceLock once it stabilizes
use once_cell::sync::OnceCell;

use crate::{prelude::*, BackendConfig};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/jobserver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use jobserver_crate::Client;
use std::lazy::SyncLazy;
use std::sync::LazyLock;

// We can only call `from_env` once per process

Expand All @@ -18,7 +18,7 @@ use std::lazy::SyncLazy;
// 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 {
static GLOBAL_CLIENT: LazyLock<Client> = LazyLock::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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ cfg_if! {
pub use parking_lot::MutexGuard as LockGuard;
pub use parking_lot::MappedMutexGuard as MappedLockGuard;

pub use std::lazy::SyncOnceCell as OnceCell;
pub use std::sync::OnceLock as OnceCell;

pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32, AtomicU64};

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ use std::env;
use std::ffi::OsString;
use std::fs;
use std::io::{self, Read, Write};
use std::lazy::SyncLazy;
use std::panic::{self, catch_unwind};
use std::path::PathBuf;
use std::process::{self, Command, Stdio};
use std::str;
use std::sync::LazyLock;
use std::time::Instant;

pub mod args;
Expand Down Expand Up @@ -1141,8 +1141,8 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
}
}

static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
SyncLazy::new(|| {
static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
LazyLock::new(|| {
let hook = panic::take_hook();
panic::set_hook(Box::new(|info| {
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
Expand Down Expand Up @@ -1237,7 +1237,7 @@ pub fn install_ice_hook() {
if std::env::var("RUST_BACKTRACE").is_err() {
std::env::set_var("RUST_BACKTRACE", "full");
}
SyncLazy::force(&DEFAULT_HOOK);
LazyLock::force(&DEFAULT_HOOK);
}

/// This allows tools to enable rust logging without having to magically match rustc's
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tracing::{instrument, trace};
#[cfg(not(parallel_compiler))]
use std::cell::LazyCell as Lazy;
#[cfg(parallel_compiler)]
use std::lazy::SyncLazy as Lazy;
use std::sync::LazyLock as Lazy;

#[cfg(parallel_compiler)]
use intl_memoizer::concurrent::IntlLangMemoizer;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{Features, Stability};
use rustc_data_structures::fx::FxHashMap;
use rustc_span::symbol::{sym, Symbol};

use std::lazy::SyncLazy;
use std::sync::LazyLock;

type GateFn = fn(&Features) -> bool;

Expand Down Expand Up @@ -809,8 +809,8 @@ pub fn is_builtin_only_local(name: Symbol) -> bool {
BUILTIN_ATTRIBUTE_MAP.get(&name).map_or(false, |attr| attr.only_local)
}

pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &BuiltinAttribute>> =
SyncLazy::new(|| {
pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>> =
LazyLock::new(|| {
let mut map = FxHashMap::default();
for attr in BUILTIN_ATTRIBUTES.iter() {
if map.insert(attr.name, attr).is_some() {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_macros::HashStable_Generic;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;

use std::lazy::SyncLazy;
use std::sync::LazyLock;

pub enum LangItemGroup {
Op,
Expand Down Expand Up @@ -134,7 +134,7 @@ macro_rules! language_item_table {
}

/// 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(|| {
pub static ITEM_REFS: LazyLock<FxHashMap<Symbol, (usize, Target)>> = LazyLock::new(|| {
let mut item_refs = FxHashMap::default();
$( item_refs.insert($module::$name, (LangItem::$variant as usize, $target)); )*
item_refs
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use rustc_ast as ast;
use rustc_data_structures::stable_map::StableMap;
use rustc_span::symbol::{sym, Symbol};

use std::lazy::SyncLazy;
use std::sync::LazyLock;

macro_rules! weak_lang_items {
($($name:ident, $item:ident, $sym:ident;)*) => (

pub static WEAK_ITEMS_REFS: SyncLazy<StableMap<Symbol, LangItem>> = SyncLazy::new(|| {
pub static WEAK_ITEMS_REFS: LazyLock<StableMap<Symbol, LangItem>> = LazyLock::new(|| {
let mut map = StableMap::default();
$(map.insert(sym::$name, LangItem::$item);)*
map
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ use std::any::Any;
use std::cell::RefCell;
use std::ffi::OsString;
use std::io::{self, BufWriter, Write};
use std::lazy::SyncLazy;
use std::marker::PhantomPinned;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::rc::Rc;
use std::sync::LazyLock;
use std::{env, fs, iter};

pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
Expand Down Expand Up @@ -759,7 +759,7 @@ pub fn prepare_outputs(
Ok(outputs)
}

pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
let providers = &mut Providers::default();
providers.analysis = analysis;
proc_macro_decls::provide(providers);
Expand All @@ -784,7 +784,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
*providers
});

pub static DEFAULT_EXTERN_QUERY_PROVIDERS: SyncLazy<ExternProviders> = SyncLazy::new(|| {
pub static DEFAULT_EXTERN_QUERY_PROVIDERS: LazyLock<ExternProviders> = LazyLock::new(|| {
let mut extern_providers = ExternProviders::default();
rustc_metadata::provide_extern(&mut extern_providers);
rustc_codegen_ssa::provide_extern(&mut extern_providers);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use rustc_span::source_map::FileLoader;
use rustc_span::symbol::{sym, Symbol};
use std::env;
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
use std::lazy::SyncOnceCell;
use std::mem;
#[cfg(not(parallel_compiler))]
use std::panic;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::OnceLock;
use std::thread;
use tracing::info;

Expand Down Expand Up @@ -242,7 +242,7 @@ pub fn get_codegen_backend(
maybe_sysroot: &Option<PathBuf>,
backend_name: Option<&str>,
) -> Box<dyn CodegenBackend> {
static LOAD: SyncOnceCell<unsafe fn() -> Box<dyn CodegenBackend>> = SyncOnceCell::new();
static LOAD: OnceLock<unsafe fn() -> Box<dyn CodegenBackend>> = OnceLock::new();

let load = LOAD.get_or_init(|| {
let default_codegen_backend = option_env!("CFG_DEFAULT_CODEGEN_BACKEND").unwrap_or("llvm");
Expand All @@ -265,7 +265,7 @@ pub fn get_codegen_backend(
// 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: SyncOnceCell<Option<PathBuf>> = SyncOnceCell::new();
static RUSTC_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();

const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR");

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/framework/graphviz.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A helpful diagram for debugging dataflow problems.
use std::borrow::Cow;
use std::lazy::SyncOnceCell;
use std::sync::OnceLock;
use std::{io, ops, str};

use regex::Regex;
Expand Down Expand Up @@ -590,7 +590,7 @@ where

macro_rules! regex {
($re:literal $(,)?) => {{
static RE: SyncOnceCell<regex::Regex> = SyncOnceCell::new();
static RE: OnceLock<regex::Regex> = OnceLock::new();
RE.get_or_init(|| Regex::new($re).unwrap())
}};
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/coverage/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ use rustc_middle::ty::TyCtxt;
use rustc_span::Span;

use std::iter;
use std::lazy::SyncOnceCell;
use std::ops::Deref;
use std::sync::OnceLock;

pub const NESTED_INDENT: &str = " ";

const RUSTC_COVERAGE_DEBUG_OPTIONS: &str = "RUSTC_COVERAGE_DEBUG_OPTIONS";

pub(super) fn debug_options<'a>() -> &'a DebugOptions {
static DEBUG_OPTIONS: SyncOnceCell<DebugOptions> = SyncOnceCell::new();
static DEBUG_OPTIONS: OnceLock<DebugOptions> = OnceLock::new();

&DEBUG_OPTIONS.get_or_init(DebugOptions::from_env)
}
Expand Down
9 changes: 4 additions & 5 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use crate::io::prelude::*;
use crate::cell::{Cell, RefCell};
use crate::fmt;
use crate::io::{self, BufReader, IoSlice, IoSliceMut, LineWriter, Lines};
use crate::lazy::SyncOnceCell;
use crate::pin::Pin;
use crate::sync::atomic::{AtomicBool, Ordering};
use crate::sync::{Arc, Mutex, MutexGuard};
use crate::sync::{Arc, Mutex, MutexGuard, OnceLock};
use crate::sys::stdio;
use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};

Expand Down Expand Up @@ -318,7 +317,7 @@ pub struct StdinLock<'a> {
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stdin() -> Stdin {
static INSTANCE: SyncOnceCell<Mutex<BufReader<StdinRaw>>> = SyncOnceCell::new();
static INSTANCE: OnceLock<Mutex<BufReader<StdinRaw>>> = OnceLock::new();
Stdin {
inner: INSTANCE.get_or_init(|| {
Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin_raw()))
Expand Down Expand Up @@ -552,7 +551,7 @@ pub struct StdoutLock<'a> {
inner: ReentrantMutexGuard<'a, RefCell<LineWriter<StdoutRaw>>>,
}

static STDOUT: SyncOnceCell<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = SyncOnceCell::new();
static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLock::new();

/// Constructs a new handle to the standard output of the current process.
///
Expand Down Expand Up @@ -837,7 +836,7 @@ pub fn stderr() -> Stderr {
// Note that unlike `stdout()` we don't use `at_exit` here to register a
// destructor. Stderr is not buffered , so there's no need to run a
// destructor for flushing the buffer
static INSTANCE: SyncOnceCell<ReentrantMutex<RefCell<StderrRaw>>> = SyncOnceCell::new();
static INSTANCE: OnceLock<ReentrantMutex<RefCell<StderrRaw>>> = OnceLock::new();

Stderr {
inner: Pin::static_ref(&INSTANCE).get_or_init_pin(
Expand Down
Loading

0 comments on commit c1a2db3

Please sign in to comment.