Skip to content

Commit c1a2db3

Browse files
committed
Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock
1 parent 7c360dc commit c1a2db3

File tree

32 files changed

+847
-819
lines changed

32 files changed

+847
-819
lines changed

compiler/rustc_codegen_cranelift/src/driver/jit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::Symbol;
1313

1414
use cranelift_jit::{JITBuilder, JITModule};
1515

16-
// FIXME use std::lazy::SyncOnceCell once it stabilizes
16+
// FIXME use std::sync::OnceLock once it stabilizes
1717
use once_cell::sync::OnceCell;
1818

1919
use crate::{prelude::*, BackendConfig};

compiler/rustc_data_structures/src/jobserver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub use jobserver_crate::Client;
2-
use std::lazy::SyncLazy;
2+
use std::sync::LazyLock;
33

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

@@ -18,7 +18,7 @@ use std::lazy::SyncLazy;
1818
// Also note that we stick this in a global because there could be
1919
// multiple rustc instances in this process, and the jobserver is
2020
// per-process.
21-
static GLOBAL_CLIENT: SyncLazy<Client> = SyncLazy::new(|| unsafe {
21+
static GLOBAL_CLIENT: LazyLock<Client> = LazyLock::new(|| unsafe {
2222
Client::from_env().unwrap_or_else(|| {
2323
let client = Client::new(32).expect("failed to create jobserver");
2424
// Acquire a token for the main thread which we can release later

compiler/rustc_data_structures/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ cfg_if! {
258258
pub use parking_lot::MutexGuard as LockGuard;
259259
pub use parking_lot::MappedMutexGuard as MappedLockGuard;
260260

261-
pub use std::lazy::SyncOnceCell as OnceCell;
261+
pub use std::sync::OnceLock as OnceCell;
262262

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

compiler/rustc_driver/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ use std::env;
4747
use std::ffi::OsString;
4848
use std::fs;
4949
use std::io::{self, Read, Write};
50-
use std::lazy::SyncLazy;
5150
use std::panic::{self, catch_unwind};
5251
use std::path::PathBuf;
5352
use std::process::{self, Command, Stdio};
5453
use std::str;
54+
use std::sync::LazyLock;
5555
use std::time::Instant;
5656

5757
pub mod args;
@@ -1141,8 +1141,8 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
11411141
}
11421142
}
11431143

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

12431243
/// This allows tools to enable rust logging without having to magically match rustc's

compiler/rustc_error_messages/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tracing::{instrument, trace};
2020
#[cfg(not(parallel_compiler))]
2121
use std::cell::LazyCell as Lazy;
2222
#[cfg(parallel_compiler)]
23-
use std::lazy::SyncLazy as Lazy;
23+
use std::sync::LazyLock as Lazy;
2424

2525
#[cfg(parallel_compiler)]
2626
use intl_memoizer::concurrent::IntlLangMemoizer;

compiler/rustc_feature/src/builtin_attrs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{Features, Stability};
99
use rustc_data_structures::fx::FxHashMap;
1010
use rustc_span::symbol::{sym, Symbol};
1111

12-
use std::lazy::SyncLazy;
12+
use std::sync::LazyLock;
1313

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

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

812-
pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &BuiltinAttribute>> =
813-
SyncLazy::new(|| {
812+
pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>> =
813+
LazyLock::new(|| {
814814
let mut map = FxHashMap::default();
815815
for attr in BUILTIN_ATTRIBUTES.iter() {
816816
if map.insert(attr.name, attr).is_some() {

compiler/rustc_hir/src/lang_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_macros::HashStable_Generic;
1717
use rustc_span::symbol::{kw, sym, Symbol};
1818
use rustc_span::Span;
1919

20-
use std::lazy::SyncLazy;
20+
use std::sync::LazyLock;
2121

2222
pub enum LangItemGroup {
2323
Op,
@@ -134,7 +134,7 @@ macro_rules! language_item_table {
134134
}
135135

136136
/// A mapping from the name of the lang item to its order and the form it must be of.
137-
pub static ITEM_REFS: SyncLazy<FxHashMap<Symbol, (usize, Target)>> = SyncLazy::new(|| {
137+
pub static ITEM_REFS: LazyLock<FxHashMap<Symbol, (usize, Target)>> = LazyLock::new(|| {
138138
let mut item_refs = FxHashMap::default();
139139
$( item_refs.insert($module::$name, (LangItem::$variant as usize, $target)); )*
140140
item_refs

compiler/rustc_hir/src/weak_lang_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use rustc_ast as ast;
77
use rustc_data_structures::stable_map::StableMap;
88
use rustc_span::symbol::{sym, Symbol};
99

10-
use std::lazy::SyncLazy;
10+
use std::sync::LazyLock;
1111

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

15-
pub static WEAK_ITEMS_REFS: SyncLazy<StableMap<Symbol, LangItem>> = SyncLazy::new(|| {
15+
pub static WEAK_ITEMS_REFS: LazyLock<StableMap<Symbol, LangItem>> = LazyLock::new(|| {
1616
let mut map = StableMap::default();
1717
$(map.insert(sym::$name, LangItem::$item);)*
1818
map

compiler/rustc_interface/src/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ use std::any::Any;
4343
use std::cell::RefCell;
4444
use std::ffi::OsString;
4545
use std::io::{self, BufWriter, Write};
46-
use std::lazy::SyncLazy;
4746
use std::marker::PhantomPinned;
4847
use std::path::{Path, PathBuf};
4948
use std::pin::Pin;
5049
use std::rc::Rc;
50+
use std::sync::LazyLock;
5151
use std::{env, fs, iter};
5252

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

762-
pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
762+
pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
763763
let providers = &mut Providers::default();
764764
providers.analysis = analysis;
765765
proc_macro_decls::provide(providers);
@@ -784,7 +784,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
784784
*providers
785785
});
786786

787-
pub static DEFAULT_EXTERN_QUERY_PROVIDERS: SyncLazy<ExternProviders> = SyncLazy::new(|| {
787+
pub static DEFAULT_EXTERN_QUERY_PROVIDERS: LazyLock<ExternProviders> = LazyLock::new(|| {
788788
let mut extern_providers = ExternProviders::default();
789789
rustc_metadata::provide_extern(&mut extern_providers);
790790
rustc_codegen_ssa::provide_extern(&mut extern_providers);

compiler/rustc_interface/src/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ use rustc_span::source_map::FileLoader;
2424
use rustc_span::symbol::{sym, Symbol};
2525
use std::env;
2626
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
27-
use std::lazy::SyncOnceCell;
2827
use std::mem;
2928
#[cfg(not(parallel_compiler))]
3029
use std::panic;
3130
use std::path::{Path, PathBuf};
3231
use std::sync::atomic::{AtomicBool, Ordering};
32+
use std::sync::OnceLock;
3333
use std::thread;
3434
use tracing::info;
3535

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

247247
let load = LOAD.get_or_init(|| {
248248
let default_codegen_backend = option_env!("CFG_DEFAULT_CODEGEN_BACKEND").unwrap_or("llvm");
@@ -265,7 +265,7 @@ pub fn get_codegen_backend(
265265
// loading, so we leave the code here. It is potentially useful for other tools
266266
// that want to invoke the rustc binary while linking to rustc as well.
267267
pub fn rustc_path<'a>() -> Option<&'a Path> {
268-
static RUSTC_PATH: SyncOnceCell<Option<PathBuf>> = SyncOnceCell::new();
268+
static RUSTC_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();
269269

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

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A helpful diagram for debugging dataflow problems.
22
33
use std::borrow::Cow;
4-
use std::lazy::SyncOnceCell;
4+
use std::sync::OnceLock;
55
use std::{io, ops, str};
66

77
use regex::Regex;
@@ -590,7 +590,7 @@ where
590590

591591
macro_rules! regex {
592592
($re:literal $(,)?) => {{
593-
static RE: SyncOnceCell<regex::Regex> = SyncOnceCell::new();
593+
static RE: OnceLock<regex::Regex> = OnceLock::new();
594594
RE.get_or_init(|| Regex::new($re).unwrap())
595595
}};
596596
}

compiler/rustc_mir_transform/src/coverage/debug.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ use rustc_middle::ty::TyCtxt;
123123
use rustc_span::Span;
124124

125125
use std::iter;
126-
use std::lazy::SyncOnceCell;
127126
use std::ops::Deref;
127+
use std::sync::OnceLock;
128128

129129
pub const NESTED_INDENT: &str = " ";
130130

131131
const RUSTC_COVERAGE_DEBUG_OPTIONS: &str = "RUSTC_COVERAGE_DEBUG_OPTIONS";
132132

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

136136
&DEBUG_OPTIONS.get_or_init(DebugOptions::from_env)
137137
}

library/std/src/io/stdio.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use crate::io::prelude::*;
88
use crate::cell::{Cell, RefCell};
99
use crate::fmt;
1010
use crate::io::{self, BufReader, IoSlice, IoSliceMut, LineWriter, Lines};
11-
use crate::lazy::SyncOnceCell;
1211
use crate::pin::Pin;
1312
use crate::sync::atomic::{AtomicBool, Ordering};
14-
use crate::sync::{Arc, Mutex, MutexGuard};
13+
use crate::sync::{Arc, Mutex, MutexGuard, OnceLock};
1514
use crate::sys::stdio;
1615
use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
1716

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

555-
static STDOUT: SyncOnceCell<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = SyncOnceCell::new();
554+
static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLock::new();
556555

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

842841
Stderr {
843842
inner: Pin::static_ref(&INSTANCE).get_or_init_pin(

0 commit comments

Comments
 (0)