Skip to content

Commit bea25a0

Browse files
authored
Merge pull request RustPython#5627 from youknowone/once-cell
Replace direct use of once_cell to std
2 parents c96fd3d + ad57885 commit bea25a0

File tree

22 files changed

+50
-55
lines changed

22 files changed

+50
-55
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

derive-impl/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ rustpython-compiler-core = { workspace = true }
1414
rustpython-doc = { workspace = true }
1515

1616
itertools = { workspace = true }
17-
once_cell = { workspace = true }
1817
syn = { workspace = true, features = ["full", "extra-traits"] }
1918

2019
maplit = "1.0.2"

derive-impl/src/compile_bytecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
//! ```
1515
1616
use crate::Diagnostic;
17-
use once_cell::sync::Lazy;
1817
use proc_macro2::{Span, TokenStream};
1918
use quote::quote;
2019
use rustpython_compiler_core::{Mode, bytecode::CodeObject, frozen};
20+
use std::sync::LazyLock;
2121
use std::{
2222
collections::HashMap,
2323
env, fs,
@@ -29,7 +29,7 @@ use syn::{
2929
spanned::Spanned,
3030
};
3131

32-
static CARGO_MANIFEST_DIR: Lazy<PathBuf> = Lazy::new(|| {
32+
static CARGO_MANIFEST_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
3333
PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not present"))
3434
});
3535

stdlib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ malachite-bigint = { workspace = true }
4040
num-integer = { workspace = true }
4141
num-traits = { workspace = true }
4242
num_enum = { workspace = true }
43-
once_cell = { workspace = true }
4443
parking_lot = { workspace = true }
4544
thread_local = { workspace = true }
4645

stdlib/src/contextvars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod _contextvars {
3333
};
3434
use crossbeam_utils::atomic::AtomicCell;
3535
use indexmap::IndexMap;
36-
use once_cell::sync::Lazy;
36+
use std::sync::LazyLock;
3737
use std::{
3838
cell::{Cell, RefCell, UnsafeCell},
3939
sync::atomic::Ordering,
@@ -274,7 +274,7 @@ mod _contextvars {
274274

275275
impl AsSequence for PyContext {
276276
fn as_sequence() -> &'static PySequenceMethods {
277-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
277+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
278278
contains: atomic_func!(|seq, target, vm| {
279279
let target = target.try_to_value(vm)?;
280280
PyContext::sequence_downcast(seq).contains(target)

stdlib/src/csv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ mod _csv {
1212
};
1313
use csv_core::Terminator;
1414
use itertools::{self, Itertools};
15-
use once_cell::sync::Lazy;
1615
use parking_lot::Mutex;
1716
use rustpython_vm::match_class;
17+
use std::sync::LazyLock;
1818
use std::{collections::HashMap, fmt};
1919

2020
#[pyattr]
@@ -41,11 +41,11 @@ mod _csv {
4141
)
4242
}
4343

44-
static GLOBAL_HASHMAP: Lazy<Mutex<HashMap<String, PyDialect>>> = Lazy::new(|| {
44+
static GLOBAL_HASHMAP: LazyLock<Mutex<HashMap<String, PyDialect>>> = LazyLock::new(|| {
4545
let m = HashMap::new();
4646
Mutex::new(m)
4747
});
48-
static GLOBAL_FIELD_LIMIT: Lazy<Mutex<isize>> = Lazy::new(|| Mutex::new(131072));
48+
static GLOBAL_FIELD_LIMIT: LazyLock<Mutex<isize>> = LazyLock::new(|| Mutex::new(131072));
4949

5050
fn new_csv_error(vm: &VirtualMachine, msg: String) -> PyBaseExceptionRef {
5151
vm.new_exception_msg(super::_csv::error(vm), msg)

stdlib/src/mmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ mod mmap {
457457

458458
impl AsSequence for PyMmap {
459459
fn as_sequence() -> &'static PySequenceMethods {
460-
use once_cell::sync::Lazy;
461-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
460+
use std::sync::LazyLock;
461+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
462462
length: atomic_func!(|seq, _vm| Ok(PyMmap::sequence_downcast(seq).len())),
463463
item: atomic_func!(|seq, i, vm| {
464464
let zelf = PyMmap::sequence_downcast(seq);

stdlib/src/sqlite.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,8 +1953,8 @@ mod _sqlite {
19531953

19541954
impl AsMapping for Row {
19551955
fn as_mapping() -> &'static PyMappingMethods {
1956-
static AS_MAPPING: once_cell::sync::Lazy<PyMappingMethods> =
1957-
once_cell::sync::Lazy::new(|| PyMappingMethods {
1956+
static AS_MAPPING: std::sync::LazyLock<PyMappingMethods> =
1957+
std::sync::LazyLock::new(|| PyMappingMethods {
19581958
length: atomic_func!(|mapping, _vm| Ok(Row::mapping_downcast(mapping)
19591959
.data
19601960
.len())),
@@ -1969,8 +1969,8 @@ mod _sqlite {
19691969

19701970
impl AsSequence for Row {
19711971
fn as_sequence() -> &'static PySequenceMethods {
1972-
static AS_SEQUENCE: once_cell::sync::Lazy<PySequenceMethods> =
1973-
once_cell::sync::Lazy::new(|| PySequenceMethods {
1972+
static AS_SEQUENCE: std::sync::LazyLock<PySequenceMethods> =
1973+
std::sync::LazyLock::new(|| PySequenceMethods {
19741974
length: atomic_func!(|seq, _vm| Ok(Row::sequence_downcast(seq).data.len())),
19751975
item: atomic_func!(|seq, i, vm| Row::sequence_downcast(seq)
19761976
.data

stdlib/src/uuid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub(crate) use _uuid::make_module;
44
mod _uuid {
55
use crate::{builtins::PyNone, vm::VirtualMachine};
66
use mac_address::get_mac_address;
7-
use once_cell::sync::OnceCell;
7+
use std::sync::OnceLock;
88
use uuid::{Context, Uuid, timestamp::Timestamp};
99

1010
fn get_node_id() -> [u8; 6] {
@@ -19,7 +19,7 @@ mod _uuid {
1919
static CONTEXT: Context = Context::new(0);
2020
let ts = Timestamp::now(&CONTEXT);
2121

22-
static NODE_ID: OnceCell<[u8; 6]> = OnceCell::new();
22+
static NODE_ID: OnceLock<[u8; 6]> = OnceLock::new();
2323
let unique_node_id = NODE_ID.get_or_init(get_node_id);
2424

2525
(Uuid::new_v1(ts, unique_node_id).as_bytes().to_vec(), PyNone)

vm/src/builtins/bytes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
},
2828
};
2929
use bstr::ByteSlice;
30-
use once_cell::sync::Lazy;
30+
use std::sync::LazyLock;
3131
use std::{mem::size_of, ops::Deref};
3232

3333
#[pyclass(module = false, name = "bytes")]
@@ -568,7 +568,7 @@ impl AsBuffer for PyBytes {
568568

569569
impl AsMapping for PyBytes {
570570
fn as_mapping() -> &'static PyMappingMethods {
571-
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
571+
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
572572
length: atomic_func!(|mapping, _vm| Ok(PyBytes::mapping_downcast(mapping).len())),
573573
subscript: atomic_func!(
574574
|mapping, needle, vm| PyBytes::mapping_downcast(mapping)._getitem(needle, vm)
@@ -581,7 +581,7 @@ impl AsMapping for PyBytes {
581581

582582
impl AsSequence for PyBytes {
583583
fn as_sequence() -> &'static PySequenceMethods {
584-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
584+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
585585
length: atomic_func!(|seq, _vm| Ok(PyBytes::sequence_downcast(seq).len())),
586586
concat: atomic_func!(|seq, other, vm| {
587587
PyBytes::sequence_downcast(seq)

0 commit comments

Comments
 (0)