Skip to content

Commit 73ad0f4

Browse files
committed
No AtomicCell
1 parent 765133c commit 73ad0f4

File tree

5 files changed

+102
-81
lines changed

5 files changed

+102
-81
lines changed

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

crates/vm/src/types/slot.rs

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<T: Any + 'static> std::ops::DerefMut for TypeDataRefMut<'_, T> {
113113
#[macro_export]
114114
macro_rules! atomic_func {
115115
($x:expr) => {
116-
crossbeam_utils::atomic::AtomicCell::new(Some($x))
116+
Some($x)
117117
};
118118
}
119119

@@ -385,6 +385,59 @@ fn setitem_wrapper<K: ToPyObject>(
385385
.map(drop)
386386
}
387387

388+
#[inline(never)]
389+
fn mapping_setitem_wrapper(
390+
mapping: PyMapping<'_>,
391+
key: &PyObject,
392+
value: Option<PyObjectRef>,
393+
vm: &VirtualMachine,
394+
) -> PyResult<()> {
395+
setitem_wrapper(mapping.obj, key, value, vm)
396+
}
397+
398+
#[inline(never)]
399+
fn mapping_getitem_wrapper(
400+
mapping: PyMapping<'_>,
401+
key: &PyObject,
402+
vm: &VirtualMachine,
403+
) -> PyResult {
404+
getitem_wrapper(mapping.obj, key, vm)
405+
}
406+
407+
#[inline(never)]
408+
fn mapping_len_wrapper(mapping: PyMapping<'_>, vm: &VirtualMachine) -> PyResult<usize> {
409+
len_wrapper(mapping.obj, vm)
410+
}
411+
412+
#[inline(never)]
413+
fn sequence_len_wrapper(seq: PySequence<'_>, vm: &VirtualMachine) -> PyResult<usize> {
414+
len_wrapper(seq.obj, vm)
415+
}
416+
417+
#[inline(never)]
418+
fn sequence_getitem_wrapper(seq: PySequence<'_>, i: isize, vm: &VirtualMachine) -> PyResult {
419+
getitem_wrapper(seq.obj, i, vm)
420+
}
421+
422+
#[inline(never)]
423+
fn sequence_setitem_wrapper(
424+
seq: PySequence<'_>,
425+
i: isize,
426+
value: Option<PyObjectRef>,
427+
vm: &VirtualMachine,
428+
) -> PyResult<()> {
429+
setitem_wrapper(seq.obj, i, value, vm)
430+
}
431+
432+
#[inline(never)]
433+
fn sequence_contains_wrapper(
434+
seq: PySequence<'_>,
435+
needle: &PyObject,
436+
vm: &VirtualMachine,
437+
) -> PyResult<bool> {
438+
contains_wrapper(seq.obj, needle, vm)
439+
}
440+
388441
fn repr_wrapper(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>> {
389442
let ret = vm.call_special_method(zelf, identifier!(vm, __repr__), ())?;
390443
ret.downcast::<PyStr>().map_err(|obj| {
@@ -1139,12 +1192,7 @@ impl PyType {
11391192

11401193
// === Sequence slots ===
11411194
SlotAccessor::SqLength => {
1142-
update_sub_slot!(
1143-
as_sequence,
1144-
length,
1145-
|seq, vm| len_wrapper(seq.obj, vm),
1146-
SeqLength
1147-
)
1195+
update_sub_slot!(as_sequence, length, sequence_len_wrapper, SeqLength)
11481196
}
11491197
SlotAccessor::SqConcat | SlotAccessor::SqInplaceConcat => {
11501198
// Sequence concat uses sq_concat slot - no generic wrapper needed
@@ -1161,52 +1209,32 @@ impl PyType {
11611209
}
11621210
}
11631211
SlotAccessor::SqItem => {
1164-
update_sub_slot!(
1165-
as_sequence,
1166-
item,
1167-
|seq, i, vm| getitem_wrapper(seq.obj, i, vm),
1168-
SeqItem
1169-
)
1212+
update_sub_slot!(as_sequence, item, sequence_getitem_wrapper, SeqItem)
11701213
}
11711214
SlotAccessor::SqAssItem => {
1172-
update_sub_slot!(
1173-
as_sequence,
1174-
ass_item,
1175-
|seq, i, value, vm| setitem_wrapper(seq.obj, i, value, vm),
1176-
SeqAssItem
1177-
)
1215+
update_sub_slot!(as_sequence, ass_item, sequence_setitem_wrapper, SeqAssItem)
11781216
}
11791217
SlotAccessor::SqContains => {
11801218
update_sub_slot!(
11811219
as_sequence,
11821220
contains,
1183-
|seq, needle, vm| contains_wrapper(seq.obj, needle, vm),
1221+
sequence_contains_wrapper,
11841222
SeqContains
11851223
)
11861224
}
11871225

11881226
// === Mapping slots ===
11891227
SlotAccessor::MpLength => {
1190-
update_sub_slot!(
1191-
as_mapping,
1192-
length,
1193-
|mapping, vm| len_wrapper(mapping.obj, vm),
1194-
MapLength
1195-
)
1228+
update_sub_slot!(as_mapping, length, mapping_len_wrapper, MapLength)
11961229
}
11971230
SlotAccessor::MpSubscript => {
1198-
update_sub_slot!(
1199-
as_mapping,
1200-
subscript,
1201-
|mapping, key, vm| getitem_wrapper(mapping.obj, key, vm),
1202-
MapSubscript
1203-
)
1231+
update_sub_slot!(as_mapping, subscript, mapping_getitem_wrapper, MapSubscript)
12041232
}
12051233
SlotAccessor::MpAssSubscript => {
12061234
update_sub_slot!(
12071235
as_mapping,
12081236
ass_subscript,
1209-
|mapping, key, value, vm| setitem_wrapper(mapping.obj, key, value, vm),
1237+
mapping_setitem_wrapper,
12101238
MapAssSubscript
12111239
)
12121240
}

0 commit comments

Comments
 (0)