Merge pull request #5627 from youknowone/once-cell

Replace direct use of once_cell to std
This commit is contained in:
Noa authored and GitHub committed 2025-03-26 23:36:31 -05:00
commit bea25a0285
22 files changed
+50 -55

No files matched your search

Generated
-2
View File
@@ -2413,7 +2413,6 @@ version = "0.4.0"
dependencies = [
"itertools 0.14.0",
"maplit",
"once_cell",
"proc-macro2",
"quote",
"rustpython-compiler-core",
@@ -2516,7 +2515,6 @@ dependencies = [
"num-integer",
"num-traits",
"num_enum",
"once_cell",
"openssl",
"openssl-probe",
"openssl-sys",
-1
View File
@@ -14,7 +14,6 @@ rustpython-compiler-core = { workspace = true }
rustpython-doc = { workspace = true }
itertools = { workspace = true }
once_cell = { workspace = true }
syn = { workspace = true, features = ["full", "extra-traits"] }
maplit = "1.0.2"
+2 -2
View File
@@ -14,10 +14,10 @@
//! ```
use crate::Diagnostic;
use once_cell::sync::Lazy;
use proc_macro2::{Span, TokenStream};
use quote::quote;
use rustpython_compiler_core::{Mode, bytecode::CodeObject, frozen};
use std::sync::LazyLock;
use std::{
collections::HashMap,
env, fs,
@@ -29,7 +29,7 @@ use syn::{
spanned::Spanned,
};
static CARGO_MANIFEST_DIR: Lazy<PathBuf> = Lazy::new(|| {
static CARGO_MANIFEST_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not present"))
});
-1
View File
@@ -40,7 +40,6 @@ malachite-bigint = { workspace = true }
num-integer = { workspace = true }
num-traits = { workspace = true }
num_enum = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
thread_local = { workspace = true }
+2 -2
View File
@@ -33,7 +33,7 @@ mod _contextvars {
};
use crossbeam_utils::atomic::AtomicCell;
use indexmap::IndexMap;
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use std::{
cell::{Cell, RefCell, UnsafeCell},
sync::atomic::Ordering,
@@ -274,7 +274,7 @@ mod _contextvars {
impl AsSequence for PyContext {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
contains: atomic_func!(|seq, target, vm| {
let target = target.try_to_value(vm)?;
PyContext::sequence_downcast(seq).contains(target)
+3 -3
View File
@@ -12,9 +12,9 @@ mod _csv {
};
use csv_core::Terminator;
use itertools::{self, Itertools};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use rustpython_vm::match_class;
use std::sync::LazyLock;
use std::{collections::HashMap, fmt};
#[pyattr]
@@ -41,11 +41,11 @@ mod _csv {
)
}
static GLOBAL_HASHMAP: Lazy<Mutex<HashMap<String, PyDialect>>> = Lazy::new(|| {
static GLOBAL_HASHMAP: LazyLock<Mutex<HashMap<String, PyDialect>>> = LazyLock::new(|| {
let m = HashMap::new();
Mutex::new(m)
});
static GLOBAL_FIELD_LIMIT: Lazy<Mutex<isize>> = Lazy::new(|| Mutex::new(131072));
static GLOBAL_FIELD_LIMIT: LazyLock<Mutex<isize>> = LazyLock::new(|| Mutex::new(131072));
fn new_csv_error(vm: &VirtualMachine, msg: String) -> PyBaseExceptionRef {
vm.new_exception_msg(super::_csv::error(vm), msg)
+2 -2
View File
@@ -457,8 +457,8 @@ mod mmap {
impl AsSequence for PyMmap {
fn as_sequence() -> &'static PySequenceMethods {
use once_cell::sync::Lazy;
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
use std::sync::LazyLock;
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyMmap::sequence_downcast(seq).len())),
item: atomic_func!(|seq, i, vm| {
let zelf = PyMmap::sequence_downcast(seq);
+4 -4
View File
@@ -1953,8 +1953,8 @@ mod _sqlite {
impl AsMapping for Row {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: once_cell::sync::Lazy<PyMappingMethods> =
once_cell::sync::Lazy::new(|| PyMappingMethods {
static AS_MAPPING: std::sync::LazyLock<PyMappingMethods> =
std::sync::LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, _vm| Ok(Row::mapping_downcast(mapping)
.data
.len())),
@@ -1969,8 +1969,8 @@ mod _sqlite {
impl AsSequence for Row {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: once_cell::sync::Lazy<PySequenceMethods> =
once_cell::sync::Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: std::sync::LazyLock<PySequenceMethods> =
std::sync::LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(Row::sequence_downcast(seq).data.len())),
item: atomic_func!(|seq, i, vm| Row::sequence_downcast(seq)
.data
+2 -2
View File
@@ -4,7 +4,7 @@ pub(crate) use _uuid::make_module;
mod _uuid {
use crate::{builtins::PyNone, vm::VirtualMachine};
use mac_address::get_mac_address;
use once_cell::sync::OnceCell;
use std::sync::OnceLock;
use uuid::{Context, Uuid, timestamp::Timestamp};
fn get_node_id() -> [u8; 6] {
@@ -19,7 +19,7 @@ mod _uuid {
static CONTEXT: Context = Context::new(0);
let ts = Timestamp::now(&CONTEXT);
static NODE_ID: OnceCell<[u8; 6]> = OnceCell::new();
static NODE_ID: OnceLock<[u8; 6]> = OnceLock::new();
let unique_node_id = NODE_ID.get_or_init(get_node_id);
(Uuid::new_v1(ts, unique_node_id).as_bytes().to_vec(), PyNone)
+3 -3
View File
@@ -27,7 +27,7 @@ use crate::{
},
};
use bstr::ByteSlice;
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use std::{mem::size_of, ops::Deref};
#[pyclass(module = false, name = "bytes")]
@@ -568,7 +568,7 @@ impl AsBuffer for PyBytes {
impl AsMapping for PyBytes {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, _vm| Ok(PyBytes::mapping_downcast(mapping).len())),
subscript: atomic_func!(
|mapping, needle, vm| PyBytes::mapping_downcast(mapping)._getitem(needle, vm)
@@ -581,7 +581,7 @@ impl AsMapping for PyBytes {
impl AsSequence for PyBytes {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyBytes::sequence_downcast(seq).len())),
concat: atomic_func!(|seq, other, vm| {
PyBytes::sequence_downcast(seq)
+5 -5
View File
@@ -23,9 +23,9 @@ use crate::{
},
vm::VirtualMachine,
};
use once_cell::sync::Lazy;
use rustpython_common::lock::PyMutex;
use std::fmt;
use std::sync::LazyLock;
pub type DictContentType = dictdatatype::Dict;
@@ -443,7 +443,7 @@ impl AsMapping for PyDict {
impl AsSequence for PyDict {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
contains: atomic_func!(|seq, target, vm| PyDict::sequence_downcast(seq)
.entries
.contains(vm, target)),
@@ -1133,7 +1133,7 @@ impl Comparable for PyDictKeys {
impl AsSequence for PyDictKeys {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyDictKeys::sequence_downcast(seq).len())),
contains: atomic_func!(|seq, target, vm| {
PyDictKeys::sequence_downcast(seq)
@@ -1196,7 +1196,7 @@ impl Comparable for PyDictItems {
impl AsSequence for PyDictItems {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyDictItems::sequence_downcast(seq).len())),
contains: atomic_func!(|seq, target, vm| {
let needle: &Py<PyTuple> = match target.downcast_ref() {
@@ -1246,7 +1246,7 @@ impl Unconstructible for PyDictValues {}
impl AsSequence for PyDictValues {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyDictValues::sequence_downcast(seq).len())),
..PySequenceMethods::NOT_IMPLEMENTED
});
+2 -2
View File
@@ -1,4 +1,4 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use super::type_;
use crate::{
@@ -325,7 +325,7 @@ pub fn subs_parameters<F: Fn(&VirtualMachine) -> PyResult<String>>(
impl AsMapping for PyGenericAlias {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
subscript: atomic_func!(|mapping, needle, vm| {
PyGenericAlias::mapping_downcast(mapping).getitem(needle.to_owned(), vm)
}),
+3 -3
View File
@@ -12,7 +12,7 @@ use crate::{
Representable,
},
};
use once_cell::sync::Lazy;
use std::sync::LazyLock;
#[pyclass(module = false, name = "mappingproxy", traverse)]
#[derive(Debug)]
@@ -221,7 +221,7 @@ impl Comparable for PyMappingProxy {
impl AsMapping for PyMappingProxy {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, vm| PyMappingProxy::mapping_downcast(mapping).len(vm)),
subscript: atomic_func!(|mapping, needle, vm| {
PyMappingProxy::mapping_downcast(mapping).getitem(needle.to_owned(), vm)
@@ -234,7 +234,7 @@ impl AsMapping for PyMappingProxy {
impl AsSequence for PyMappingProxy {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
contains: atomic_func!(
|seq, target, vm| PyMappingProxy::sequence_downcast(seq)._contains(target, vm)
),
+2 -2
View File
@@ -28,8 +28,8 @@ use crate::{
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
use once_cell::sync::Lazy;
use rustpython_common::lock::PyMutex;
use std::sync::LazyLock;
use std::{cmp::Ordering, fmt::Debug, mem::ManuallyDrop, ops::Range};
#[derive(FromArgs)]
@@ -993,7 +993,7 @@ impl AsMapping for PyMemoryView {
impl AsSequence for PyMemoryView {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, vm| {
let zelf = PyMemoryView::sequence_downcast(seq);
zelf.try_not_released(vm)?;
+3 -3
View File
@@ -17,8 +17,8 @@ use crossbeam_utils::atomic::AtomicCell;
use malachite_bigint::{BigInt, Sign};
use num_integer::Integer;
use num_traits::{One, Signed, ToPrimitive, Zero};
use once_cell::sync::Lazy;
use std::cmp::max;
use std::sync::LazyLock;
// Search flag passed to iter_search
enum SearchType {
@@ -385,7 +385,7 @@ impl PyRange {
impl AsMapping for PyRange {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(
|mapping, vm| PyRange::mapping_downcast(mapping).protocol_length(vm)
),
@@ -400,7 +400,7 @@ impl AsMapping for PyRange {
impl AsSequence for PyRange {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, vm| PyRange::sequence_downcast(seq).protocol_length(vm)),
item: atomic_func!(|seq, i, vm| {
PyRange::sequence_downcast(seq)
+3 -3
View File
@@ -23,11 +23,11 @@ use crate::{
utils::collection_repr,
vm::VirtualMachine,
};
use once_cell::sync::Lazy;
use rustpython_common::{
atomic::{Ordering, PyAtomic, Radium},
hash,
};
use std::sync::LazyLock;
use std::{fmt, ops::Deref};
pub type SetContentType = dictdatatype::Dict<()>;
@@ -794,7 +794,7 @@ impl Initializer for PySet {
impl AsSequence for PySet {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PySet::sequence_downcast(seq).len())),
contains: atomic_func!(|seq, needle, vm| PySet::sequence_downcast(seq)
.inner
@@ -1112,7 +1112,7 @@ impl PyFrozenSet {
impl AsSequence for PyFrozenSet {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyFrozenSet::sequence_downcast(seq).len())),
contains: atomic_func!(|seq, needle, vm| PyFrozenSet::sequence_downcast(seq)
.inner
+3 -3
View File
@@ -28,7 +28,6 @@ use ascii::{AsciiChar, AsciiStr, AsciiString};
use bstr::ByteSlice;
use itertools::Itertools;
use num_traits::ToPrimitive;
use once_cell::sync::Lazy;
use rustpython_common::{
ascii,
atomic::{self, PyAtomic, Radium},
@@ -38,6 +37,7 @@ use rustpython_common::{
str::DeduceStrKind,
wtf8::{CodePoint, Wtf8, Wtf8Buf, Wtf8Chunk},
};
use std::sync::LazyLock;
use std::{borrow::Cow, char, fmt, ops::Range};
use unic_ucd_bidi::BidiClass;
use unic_ucd_category::GeneralCategory;
@@ -1495,7 +1495,7 @@ impl Iterable for PyStr {
impl AsMapping for PyStr {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, _vm| Ok(PyStr::mapping_downcast(mapping).len())),
subscript: atomic_func!(
|mapping, needle, vm| PyStr::mapping_downcast(mapping)._getitem(needle, vm)
@@ -1524,7 +1524,7 @@ impl AsNumber for PyStr {
impl AsSequence for PyStr {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyStr::sequence_downcast(seq).len())),
concat: atomic_func!(|seq, other, vm| {
let zelf = PyStr::sequence_downcast(seq);
+3 -4
View File
@@ -19,8 +19,7 @@ use crate::{
utils::collection_repr,
vm::VirtualMachine,
};
use once_cell::sync::Lazy;
use std::{fmt, marker::PhantomData};
use std::{fmt, marker::PhantomData, sync::LazyLock};
#[pyclass(module = false, name = "tuple", traverse)]
pub struct PyTuple {
@@ -351,7 +350,7 @@ impl PyTuple {
impl AsMapping for PyTuple {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, _vm| Ok(PyTuple::mapping_downcast(mapping).len())),
subscript: atomic_func!(
|mapping, needle, vm| PyTuple::mapping_downcast(mapping)._getitem(needle, vm)
@@ -364,7 +363,7 @@ impl AsMapping for PyTuple {
impl AsSequence for PyTuple {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyTuple::sequence_downcast(seq).len())),
concat: atomic_func!(|seq, other, vm| {
let zelf = PyTuple::sequence_downcast(seq);
+2 -2
View File
@@ -10,8 +10,8 @@ use crate::{
protocol::{PyMappingMethods, PyNumberMethods},
types::{AsMapping, AsNumber, Comparable, GetAttr, Hashable, PyComparisonOp, Representable},
};
use once_cell::sync::Lazy;
use std::fmt;
use std::sync::LazyLock;
const CLS_ATTRS: &[&str] = &["__module__"];
@@ -219,7 +219,7 @@ impl PyUnion {
impl AsMapping for PyUnion {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
subscript: atomic_func!(|mapping, needle, vm| {
PyUnion::mapping_downcast(mapping).getitem(needle.to_owned(), vm)
}),
+2 -2
View File
@@ -11,7 +11,7 @@ use crate::{
PyComparisonOp, Representable, SetAttr,
},
};
use once_cell::sync::Lazy;
use std::sync::LazyLock;
#[pyclass(module = false, name = "weakproxy", unhashable = true, traverse)]
#[derive(Debug)]
@@ -186,7 +186,7 @@ impl Comparable for PyWeakProxy {
impl AsSequence for PyWeakProxy {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, vm| PyWeakProxy::sequence_downcast(seq).len(vm)),
contains: atomic_func!(|seq, needle, vm| {
PyWeakProxy::sequence_downcast(seq).contains(needle.to_owned(), vm)
+2 -2
View File
@@ -814,8 +814,8 @@ mod _sre {
impl AsMapping for Match {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: once_cell::sync::Lazy<PyMappingMethods> =
once_cell::sync::Lazy::new(|| PyMappingMethods {
static AS_MAPPING: std::sync::LazyLock<PyMappingMethods> =
std::sync::LazyLock::new(|| PyMappingMethods {
subscript: atomic_func!(|mapping, needle, vm| {
Match::mapping_downcast(mapping)
.getitem(needle.to_owned(), vm)
+2 -2
View File
@@ -107,8 +107,8 @@ pub struct PyGlobalState {
}
pub fn process_hash_secret_seed() -> u32 {
use once_cell::sync::OnceCell;
static SEED: OnceCell<u32> = OnceCell::new();
use std::sync::OnceLock;
static SEED: OnceLock<u32> = OnceLock::new();
*SEED.get_or_init(rand::random)
}