10000 Merge pull request #5627 from youknowone/once-cell · RustPython/RustPython@bea25a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit bea25a0

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

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)

vm/src/builtins/dict.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use crate::{
2323
},
2424
vm::VirtualMachine,
2525
};
26-
use once_cell::sync::Lazy;
2726
use rustpython_common::lock::PyMutex;
2827
use std::fmt;
28+
use std::sync::LazyLock;
2929

3030
pub type DictContentType = dictdatatype::Dict;
3131

@@ -443,7 +443,7 @@ impl AsMapping for PyDict {
443443

444444
impl AsSequence for PyDict {
445445
fn as_sequence() -> &'static PySequenceMethods {
446-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
446+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
447447
contains: atomic_func!(|seq, target, vm| PyDict::sequence_downcast(seq)
448448
.entries
449449
.contains(vm, target)),
@@ -1133,7 +1133,7 @@ impl Comparable for PyDictKeys {
11331133

11341134
impl AsSequence for PyDictKeys {
11351135
fn as_sequence() -> &'static PySequenceMethods {
1136-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
1136+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
11371137
length: atomic_func!(|seq, _vm| Ok(PyDictKeys::sequence_downcast(seq).len())),
11381138
contains: atomic_func!(|seq, target, vm| {
11391139
PyDictKeys::sequence_downcast(seq)
@@ -1196,7 +1196,7 @@ impl Comparable for PyDictItems {
11961196

11971197
impl AsSequence for PyDictItems {
11981198
fn as_sequence() -> &'static PySequenceMethods {
1199-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
1199+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
12001200
length: atomic_func!(|seq, _vm| Ok(PyDictItems::sequence_downcast(seq).len())),
12011201
contains: atomic_func!(|seq, target, vm| {
12021202
let needle: &Py<PyTuple> = match target.downcast_ref() {
@@ -1246,7 +1246,7 @@ impl Unconstructible for PyDictValues {}
12461246

12471247
impl AsSequence for PyDictValues {
12481248
fn as_sequence() -> &'static PySequenceMethods {
1249-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
1249+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
12501250
length: atomic_func!(|seq, _vm| Ok(PyDictValues::sequence_downcast(seq).len())),
12511251
..PySequenceMethods::NOT_IMPLEMENTED
12521252
});

vm/src/builtins/genericalias.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22

33
use super::type_;
44
use crate::{
@@ -325,7 +325,7 @@ pub fn subs_parameters<F: Fn(&VirtualMachine) -> PyResult<String>>(
325325

326326
impl AsMapping for PyGenericAlias {
327327
fn as_mapping() -> &'static PyMappingMethods {
328-
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
328+
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
329329
subscript: atomic_func!(|mapping, needle, vm| {
330330
PyGenericAlias::mapping_downcast(mapping).getitem(needle.to_owned(), vm)
331331
}),

vm/src/builtins/mappingproxy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
Representable,
1313
},
1414
};
15-
use once_cell::sync::Lazy;
15+
use std::sync::LazyLock;
1616

1717
#[pyclass(module = false, name = "mappingproxy", traverse)]
1818
#[derive(Debug)]
@@ -221,7 +221,7 @@ impl Comparable for PyMappingProxy {
221221

222222
impl AsMapping for PyMappingProxy {
223223
fn as_mapping() -> &'static PyMappingMethods {
224-
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
224+
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
225225
length: atomic_func!(|mapping, vm| PyMappingProxy::mapping_downcast(mapping).len(vm)),
226226
subscript: atomic_func!(|mapping, needle, vm| {
227227
PyMappingProxy::mapping_downcast(mapping).getitem(needle.to_owned(), vm)
@@ -234,7 +234,7 @@ impl AsMapping for PyMappingProxy {
234234

235235
impl AsSequence for PyMappingProxy {
236236
fn as_sequence() -> &'static PySequenceMethods {
237-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
237+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
238238
contains: atomic_func!(
239239
|seq, target, vm| PyMappingProxy::sequence_downcast(seq)._contains(target, vm)
240240
),

vm/src/builtins/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use crate::{
2828
};
2929
use crossbeam_utils::atomic::AtomicCell;
3030
use itertools::Itertools;
31-
use once_cell::sync::Lazy;
3231
use rustpython_common::lock::PyMutex;
32+
use std::sync::LazyLock;
3333
use std::{cmp::Ordering, fmt::Debug, mem::ManuallyDrop, ops::Range};
3434

3535
#[derive(FromArgs)]
@@ -993,7 +993,7 @@ impl AsMapping for PyMemoryView {
993993

994994
impl AsSequence for PyMemoryView {
995995
fn as_sequence() -> &'static PySequenceMethods {
996-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
996+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
997997
length: atomic_func!(|seq, vm| {
998998
let zelf = PyMemoryView::sequence_downcast(seq);
999999
zelf.try_not_released(vm)?;

vm/src/builtins/range.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crossbeam_utils::atomic::AtomicCell;
1717
use malachite_bigint::{BigInt, Sign};
1818
use num_integer::Integer;
1919
use num_traits::{One, Signed, ToPrimitive, Zero};
20-
use once_cell::sync::Lazy;
2120
use std::cmp::max;
21+
use std::sync::LazyLock;
2222

2323
// Search flag passed to iter_search
2424
enum SearchType {
@@ -385,7 +385,7 @@ impl PyRange {
385385

386386
impl AsMapping for PyRange {
387387
fn as_mapping() -> &'static PyMappingMethods {
388-
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
388+
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
389389
length: atomic_func!(
390390
|mapping, vm| PyRange::mapping_downcast(mapping).protocol_length(vm)
391391
),
@@ -400,7 +400,7 @@ impl AsMapping for PyRange {
400400

401401
impl AsSequence for PyRange {
402402
fn as_sequence() -> &'static PySequenceMethods {
403-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
403+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
404404
length: atomic_func!(|seq, vm| PyRange::sequence_downcast(seq).protocol_length(vm)),
405405
item: atomic_func!(|seq, i, vm| {
406406
PyRange::sequence_downcast(seq)

vm/src/builtins/set.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ use crate::{
2323
utils::collection_repr,
2424
vm::VirtualMachine,
2525
};
26-
use once_cell::sync::Lazy;
2726
use rustpython_common::{
2827
atomic::{Ordering, PyAtomic, Radium},
2928
hash,
3029
};
30+
use std::sync::LazyLock;
3131
use std::{fmt, ops::Deref};
3232

3333
pub type SetContentType = dictdatatype::Dict<()>;
@@ -794,7 +794,7 @@ impl Initializer for PySet {
794794

795795
impl AsSequence for PySet {
796796
fn as_sequence() -> &'static PySequenceMethods {
797-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
797+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
798798
length: atomic_func!(|seq, _vm| Ok(PySet::sequence_downcast(seq).len())),
799799
contains: atomic_func!(|seq, needle, vm| PySet::sequence_downcast(seq)
800800
.inner
@@ -1112,7 +1112,7 @@ impl PyFrozenSet {
11121112

11131113
impl AsSequence for PyFrozenSet {
11141114
fn as_sequence() -> &'static PySequenceMethods {
1115-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
1115+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
11161116
length: atomic_func!(|seq, _vm| Ok(PyFrozenSet::sequence_downcast(seq).len())),
11171117
contains: atomic_func!(|seq, needle, vm| PyFrozenSet::sequence_downcast(seq)
11181118
.inner

vm/src/builtins/str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use ascii::{AsciiChar, AsciiStr, AsciiString};
2828
use bstr::ByteSlice;
2929
use itertools::Itertools;
3030
use num_traits::ToPrimitive;
31-
use once_cell::sync::Lazy;
3231
use rustpython_common::{
3332
ascii,
3433
atomic::{self, PyAtomic, Radium},
@@ -38,6 +37,7 @@ use rustpython_common::{
3837
str::DeduceStrKind,
3938
wtf8::{CodePoint, Wtf8, Wtf8Buf, Wtf8Chunk},
4039
};
40+
use std::sync::LazyLock;
4141
use std::{borrow::Cow, char, fmt, ops::Range};
4242
use unic_ucd_bidi::BidiClass;
4343
use unic_ucd_category::GeneralCategory;
@@ -1495,7 +1495,7 @@ impl Iterable for PyStr {
14951495

14961496
impl AsMapping for PyStr {
14971497
fn as_mapping() -> &'static PyMappingMethods {
1498-
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
1498+
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
14991499
length: atomic_func!(|mapping, _vm| Ok(PyStr::mapping_downcast(mapping).len())),
15001500
subscript: atomic_func!(
15011501
|mapping, needle, vm| PyStr::mapping_downcast(mapping)._getitem(needle, vm)
@@ -1524,7 +1524,7 @@ impl AsNumber for PyStr {
15241524

15251525
impl AsSequence for PyStr {
15261526
fn as_sequence() -> &'static PySequenceMethods {
1527-
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
1527+
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
15281528
length: atomic_func!(|seq, _vm| Ok(PyStr::sequence_downcast(seq).len())),
15291529
concat: atomic_func!(|seq, other, vm| {
15301530
let zelf = PyStr::sequence_downcast(seq);

0 commit comments

Comments
 (0)
0