Skip to content

Commit d1ff2cd

Browse files
authored
RichCompare contains pymethod. No AtomicCell for slots (RustPython#6562)
* slots: add comparison pymethods to Comparable trait * No AtomicCell
1 parent 476b75d commit d1ff2cd

5 files changed

Lines changed: 156 additions & 91 deletions

File tree

crates/stdlib/src/contextvars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ mod _contextvars {
264264
Err(vm.new_key_error(needle.to_owned().into()))
265265
}
266266
}),
267-
ass_subscript: AtomicCell::new(None),
267+
ass_subscript: None,
268268
};
269269
&AS_MAPPING
270270
}

crates/stdlib/src/sqlite.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
2020

2121
#[pymodule]
2222
mod _sqlite {
23-
use crossbeam_utils::atomic::AtomicCell;
2423
use libsqlite3_sys::{
2524
SQLITE_BLOB, SQLITE_DETERMINISTIC, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL,
2625
SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE, SQLITE_OPEN_URI, SQLITE_TEXT, SQLITE_TRACE_STMT,
@@ -2549,19 +2548,19 @@ mod _sqlite {
25492548
impl AsSequence for Blob {
25502549
fn as_sequence() -> &'static PySequenceMethods {
25512550
static AS_SEQUENCE: PySequenceMethods = PySequenceMethods {
2552-
length: AtomicCell::new(None),
2553-
concat: AtomicCell::new(None),
2554-
repeat: AtomicCell::new(None),
2555-
item: AtomicCell::new(None),
2556-
ass_item: AtomicCell::new(None),
2551+
length: None,
2552+
concat: None,
2553+
repeat: None,
2554+
item: None,
2555+
ass_item: None,
25572556
contains: atomic_func!(|seq, _needle, vm| {
25582557
Err(vm.new_type_error(format!(
25592558
"argument of type '{}' is not iterable",
25602559
seq.obj.class().name(),
25612560
)))
25622561
}),
2563-
inplace_concat: AtomicCell::new(None),
2564-
inplace_repeat: AtomicCell::new(None),
2562+
inplace_concat: None,
2563+
inplace_repeat: None,
25652564
};
25662565
&AS_SEQUENCE
25672566
}

crates/vm/src/protocol/mapping.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ impl PyMappingSlots {
3535

3636
/// Copy from static PyMappingMethods
3737
pub fn copy_from(&self, methods: &PyMappingMethods) {
38-
if let Some(f) = methods.length.load() {
38+
if let Some(f) = methods.length {
3939
self.length.store(Some(f));
4040
}
41-
if let Some(f) = methods.subscript.load() {
41+
if let Some(f) = methods.subscript {
4242
self.subscript.store(Some(f));
4343
}
44-
if let Some(f) = methods.ass_subscript.load() {
44+
if let Some(f) = methods.ass_subscript {
4545
self.ass_subscript.store(Some(f));
4646
}
4747
}
@@ -50,11 +50,10 @@ impl PyMappingSlots {
5050
#[allow(clippy::type_complexity)]
5151
#[derive(Default)]
5252
pub struct PyMappingMethods {
53-
pub length: AtomicCell<Option<fn(PyMapping<'_>, &VirtualMachine) -> PyResult<usize>>>,
54-
pub subscript: AtomicCell<Option<fn(PyMapping<'_>, &PyObject, &VirtualMachine) -> PyResult>>,
55-
pub ass_subscript: AtomicCell<
53+
pub length: Option<fn(PyMapping<'_>, &VirtualMachine) -> PyResult<usize>>,
54+
pub subscript: Option<fn(PyMapping<'_>, &PyObject, &VirtualMachine) -> PyResult>,
55+
pub ass_subscript:
5656
Option<fn(PyMapping<'_>, &PyObject, Option<PyObjectRef>, &VirtualMachine) -> PyResult<()>>,
57-
>,
5857
}
5958

6059
impl std::fmt::Debug for PyMappingMethods {
@@ -64,11 +63,10 @@ impl std::fmt::Debug for PyMappingMethods {
6463
}
6564

6665
impl PyMappingMethods {
67-
#[allow(clippy::declare_interior_mutable_const)]
6866
pub const NOT_IMPLEMENTED: Self = Self {
69-
length: AtomicCell::new(None),
70-
subscript: AtomicCell::new(None),
71-
ass_subscript: AtomicCell::new(None),
67+
length: None,
68+
subscript: None,
69+
ass_subscript: None,
7270
};
7371
}
7472

crates/vm/src/protocol/sequence.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@ impl PySequenceSlots {
4242

4343
/// Copy from static PySequenceMethods
4444
pub fn copy_from(&self, methods: &PySequenceMethods) {
45-
if let Some(f) = methods.length.load() {
45+
if let Some(f) = methods.length {
4646
self.length.store(Some(f));
4747
}
48-
if let Some(f) = methods.concat.load() {
48+
if let Some(f) = methods.concat {
4949
self.concat.store(Some(f));
5050
}
51-
if let Some(f) = methods.repeat.load() {
51+
if let Some(f) = methods.repeat {
5252
self.repeat.store(Some(f));
5353
}
54-
if let Some(f) = methods.item.load() {
54+
if let Some(f) = methods.item {
5555
self.item.store(Some(f));
5656
}
57-
if let Some(f) = methods.ass_item.load() {
57+
if let Some(f) = methods.ass_item {
5858
self.ass_item.store(Some(f));
5959
}
60-
if let Some(f) = methods.contains.load() {
60+
if let Some(f) = methods.contains {
6161
self.contains.store(Some(f));
6262
}
63-
if let Some(f) = methods.inplace_concat.load() {
63+
if let Some(f) = methods.inplace_concat {
6464
self.inplace_concat.store(Some(f));
6565
}
66-
if let Some(f) = methods.inplace_repeat.load() {
66+
if let Some(f) = methods.inplace_repeat {
6767
self.inplace_repeat.store(Some(f));
6868
}
6969
}
@@ -72,18 +72,15 @@ impl PySequenceSlots {
7272
#[allow(clippy::type_complexity)]
7373
#[derive(Default)]
7474
pub struct PySequenceMethods {
75-
pub length: AtomicCell<Option<fn(PySequence<'_>, &VirtualMachine) -> PyResult<usize>>>,
76-
pub concat: AtomicCell<Option<fn(PySequence<'_>, &PyObject, &VirtualMachine) -> PyResult>>,
77-
pub repeat: AtomicCell<Option<fn(PySequence<'_>, isize, &VirtualMachine) -> PyResult>>,
78-
pub item: AtomicCell<Option<fn(PySequence<'_>, isize, &VirtualMachine) -> PyResult>>,
79-
pub ass_item: AtomicCell<
75+
pub length: Option<fn(PySequence<'_>, &VirtualMachine) -> PyResult<usize>>,
76+
pub concat: Option<fn(PySequence<'_>, &PyObject, &VirtualMachine) -> PyResult>,
77+
pub repeat: Option<fn(PySequence<'_>, isize, &VirtualMachine) -> PyResult>,
78+
pub item: Option<fn(PySequence<'_>, isize, &VirtualMachine) -> PyResult>,
79+
pub ass_item:
8080
Option<fn(PySequence<'_>, isize, Option<PyObjectRef>, &VirtualMachine) -> PyResult<()>>,
81-
>,
82-
pub contains:
83-
AtomicCell<Option<fn(PySequence<'_>, &PyObject, &VirtualMachine) -> PyResult<bool>>>,
84-
pub inplace_concat:
85-
AtomicCell<Option<fn(PySequence<'_>, &PyObject, &VirtualMachine) -> PyResult>>,
86-
pub inplace_repeat: AtomicCell<Option<fn(PySequence<'_>, isize, &VirtualMachine) -> PyResult>>,
81+
pub contains: Option<fn(PySequence<'_>, &PyObject, &VirtualMachine) -> PyResult<bool>>,
82+
pub inplace_concat: Option<fn(PySequence<'_>, &PyObject, &VirtualMachine) -> PyResult>,
83+
pub inplace_repeat: Option<fn(PySequence<'_>, isize, &VirtualMachine) -> PyResult>,
8784
}
8885

8986
impl std::fmt::Debug for PySequenceMethods {
@@ -93,16 +90,15 @@ impl std::fmt::Debug for PySequenceMethods {
9390
}
9491

9592
impl PySequenceMethods {
96-
#[allow(clippy::declare_interior_mutable_const)]
9793
pub const NOT_IMPLEMENTED: Self = Self {
98-
length: AtomicCell::new(None),
99-
concat: AtomicCell::new(None),
100-
repeat: AtomicCell::new(None),
101-
item: AtomicCell::new(None),
102-
ass_item: AtomicCell::new(None),
103-
contains: AtomicCell::new(None),
104-
inplace_concat: AtomicCell::new(None),
105-
inplace_repeat: AtomicCell::new(None),
94+
length: None,
95+
concat: None,
96+
repeat: None,
97+
item: None,
98+
ass_item: None,
99+
contains: None,
100+
inplace_concat: None,
101+
inplace_repeat: None,
106102
};
107103
}
108104

0 commit comments

Comments
 (0)