Skip to content

Commit c05e8eb

Browse files
committed
Remove PySliceRef
1 parent 997f85f commit c05e8eb

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

vm/src/builtins/list.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{PositionIterInternal, PyGenericAlias, PySliceRef, PyTupleRef, PyTypeRef};
1+
use super::{PositionIterInternal, PyGenericAlias, PySlice, PyTupleRef, PyTypeRef};
22
use crate::common::lock::{
33
PyMappedRwLockReadGuard, PyMutex, PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard,
44
};
@@ -210,7 +210,12 @@ impl PyList {
210210
}
211211
}
212212

213-
fn setslice(&self, slice: PySliceRef, sec: ArgIterable, vm: &VirtualMachine) -> PyResult<()> {
213+
fn setslice(
214+
&self,
215+
slice: PyRef<PySlice>,
216+
sec: ArgIterable,
217+
vm: &VirtualMachine,
218+
) -> PyResult<()> {
214219
let items: Result<Vec<PyObjectRef>, _> = sec.iter(vm)?.collect();
215220
let items = items?;
216221
let slice = slice.to_saturated(vm)?;
@@ -492,7 +497,7 @@ impl PyList {
492497
removed.map(drop)
493498
}
494499

495-
fn delslice(&self, slice: PySliceRef, vm: &VirtualMachine) -> PyResult<()> {
500+
fn delslice(&self, slice: PyRef<PySlice>, vm: &VirtualMachine) -> PyResult<()> {
496501
let slice = slice.to_saturated(vm)?;
497502
self.borrow_vec_mut().delete_slice(vm, slice)
498503
}

vm/src/builtins/memory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{PyBytes, PyBytesRef, PyList, PyListRef, PySliceRef, PyStr, PyStrRef, PyTypeRef};
1+
use super::{PyBytes, PyBytesRef, PyList, PyListRef, PySlice, PyStr, PyStrRef, PyTypeRef};
22
use crate::common::{
33
borrow::{BorrowedValue, BorrowedValueMut},
44
hash::PyHash,
@@ -250,7 +250,7 @@ impl PyMemoryView {
250250
})
251251
}
252252

253-
fn getitem_by_slice(zelf: PyRef<Self>, slice: PySliceRef, vm: &VirtualMachine) -> PyResult {
253+
fn getitem_by_slice(zelf: PyRef<Self>, slice: PyRef<PySlice>, vm: &VirtualMachine) -> PyResult {
254254
// slicing a memoryview return a new memoryview
255255
let len = zelf.buffer.options.len;
256256
let (range, step, is_negative_step) =
@@ -368,7 +368,7 @@ impl PyMemoryView {
368368

369369
fn setitem_by_slice(
370370
zelf: PyRef<Self>,
371-
slice: PySliceRef,
371+
slice: PyRef<PySlice>,
372372
items: PyObjectRef,
373373
vm: &VirtualMachine,
374374
) -> PyResult<()> {

vm/src/builtins/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! This package contains the python basic/builtin types
2+
//! 7 common PyRef type aliases are exposed - PyBytesRef, PyDictRef, PyIntRef, PyListRef, PyStrRef, PyTypeRef, PyTupleRef
3+
//! Do not add more PyRef type aliases. They will be rare enough to use directly PyRef<T>.
24
35
pub(crate) mod asyncgenerator;
46
pub use asyncgenerator::PyAsyncGen;
@@ -67,7 +69,7 @@ pub use set::{PyFrozenSet, PySet};
6769
pub(crate) mod singletons;
6870
pub use singletons::{PyNone, PyNotImplemented};
6971
pub(crate) mod slice;
70-
pub use slice::{PyEllipsis, PySlice, PySliceRef};
72+
pub use slice::{PyEllipsis, PySlice};
7173
pub(crate) mod staticmethod;
7274
pub use staticmethod::PyStaticMethod;
7375
pub(crate) mod traceback;

vm/src/builtins/range.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{PyInt, PyIntRef, PySlice, PySliceRef, PyTupleRef, PyTypeRef};
1+
use super::{PyInt, PyIntRef, PySlice, PyTupleRef, PyTypeRef};
22
use crate::builtins::builtins_iter;
33
use crate::common::hash::PyHash;
44
use crate::{
@@ -664,7 +664,7 @@ fn range_state(length: &BigInt, state: PyObjectRef, vm: &VirtualMachine) -> PyRe
664664

665665
pub enum RangeIndex {
666666
Int(PyIntRef),
667-
Slice(PySliceRef),
667+
Slice(PyRef<PySlice>),
668668
}
669669

670670
impl TryFromObject for RangeIndex {

vm/src/builtins/slice.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ impl PyValue for PySlice {
2424
}
2525
}
2626

27-
pub type PySliceRef = PyRef<PySlice>;
28-
2927
#[pyimpl(with(Hashable, Comparable))]
3028
impl PySlice {
3129
#[pyproperty]

vm/src/sliceable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::ops::Range;
33

44
use crate::builtins::int::PyInt;
55
// export through slicable module, not slice.
6+
use crate::builtins::slice::PySlice;
67
pub use crate::builtins::slice::{saturate_index, SaturatedSlice};
7-
use crate::builtins::slice::{PySlice, PySliceRef};
88
use crate::utils::Either;
99
use crate::VirtualMachine;
10-
use crate::{PyObjectRef, PyResult, TypeProtocol};
10+
use crate::{PyObjectRef, PyRef, PyResult, TypeProtocol};
1111

1212
pub trait PySliceableSequenceMut {
1313
type Item: Clone;
@@ -332,7 +332,7 @@ impl<T: Clone> PySliceableSequence for [T] {
332332

333333
pub enum SequenceIndex {
334334
Int(isize),
335-
Slice(PySliceRef),
335+
Slice(PyRef<PySlice>),
336336
}
337337

338338
impl SequenceIndex {

0 commit comments

Comments
 (0)