From c05e8eb48c79147f83b0179213fa05a20c3af646 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 13 Oct 2021 02:50:51 +0900 Subject: [PATCH] Remove PySliceRef --- vm/src/builtins/list.rs | 11 ++++++++--- vm/src/builtins/memory.rs | 6 +++--- vm/src/builtins/mod.rs | 4 +++- vm/src/builtins/range.rs | 4 ++-- vm/src/builtins/slice.rs | 2 -- vm/src/sliceable.rs | 6 +++--- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/vm/src/builtins/list.rs b/vm/src/builtins/list.rs index 7269f848a..027bca90b 100644 --- a/vm/src/builtins/list.rs +++ b/vm/src/builtins/list.rs @@ -1,4 +1,4 @@ -use super::{PositionIterInternal, PyGenericAlias, PySliceRef, PyTupleRef, PyTypeRef}; +use super::{PositionIterInternal, PyGenericAlias, PySlice, PyTupleRef, PyTypeRef}; use crate::common::lock::{ PyMappedRwLockReadGuard, PyMutex, PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard, }; @@ -210,7 +210,12 @@ impl PyList { } } - fn setslice(&self, slice: PySliceRef, sec: ArgIterable, vm: &VirtualMachine) -> PyResult<()> { + fn setslice( + &self, + slice: PyRef, + sec: ArgIterable, + vm: &VirtualMachine, + ) -> PyResult<()> { let items: Result, _> = sec.iter(vm)?.collect(); let items = items?; let slice = slice.to_saturated(vm)?; @@ -492,7 +497,7 @@ impl PyList { removed.map(drop) } - fn delslice(&self, slice: PySliceRef, vm: &VirtualMachine) -> PyResult<()> { + fn delslice(&self, slice: PyRef, vm: &VirtualMachine) -> PyResult<()> { let slice = slice.to_saturated(vm)?; self.borrow_vec_mut().delete_slice(vm, slice) } diff --git a/vm/src/builtins/memory.rs b/vm/src/builtins/memory.rs index 0013ed1f1..d8920d353 100644 --- a/vm/src/builtins/memory.rs +++ b/vm/src/builtins/memory.rs @@ -1,4 +1,4 @@ -use super::{PyBytes, PyBytesRef, PyList, PyListRef, PySliceRef, PyStr, PyStrRef, PyTypeRef}; +use super::{PyBytes, PyBytesRef, PyList, PyListRef, PySlice, PyStr, PyStrRef, PyTypeRef}; use crate::common::{ borrow::{BorrowedValue, BorrowedValueMut}, hash::PyHash, @@ -250,7 +250,7 @@ impl PyMemoryView { }) } - fn getitem_by_slice(zelf: PyRef, slice: PySliceRef, vm: &VirtualMachine) -> PyResult { + fn getitem_by_slice(zelf: PyRef, slice: PyRef, vm: &VirtualMachine) -> PyResult { // slicing a memoryview return a new memoryview let len = zelf.buffer.options.len; let (range, step, is_negative_step) = @@ -368,7 +368,7 @@ impl PyMemoryView { fn setitem_by_slice( zelf: PyRef, - slice: PySliceRef, + slice: PyRef, items: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()> { diff --git a/vm/src/builtins/mod.rs b/vm/src/builtins/mod.rs index 891f8087d..c891910db 100644 --- a/vm/src/builtins/mod.rs +++ b/vm/src/builtins/mod.rs @@ -1,4 +1,6 @@ //! This package contains the python basic/builtin types +//! 7 common PyRef type aliases are exposed - PyBytesRef, PyDictRef, PyIntRef, PyListRef, PyStrRef, PyTypeRef, PyTupleRef +//! Do not add more PyRef type aliases. They will be rare enough to use directly PyRef. pub(crate) mod asyncgenerator; pub use asyncgenerator::PyAsyncGen; @@ -67,7 +69,7 @@ pub use set::{PyFrozenSet, PySet}; pub(crate) mod singletons; pub use singletons::{PyNone, PyNotImplemented}; pub(crate) mod slice; -pub use slice::{PyEllipsis, PySlice, PySliceRef}; +pub use slice::{PyEllipsis, PySlice}; pub(crate) mod staticmethod; pub use staticmethod::PyStaticMethod; pub(crate) mod traceback; diff --git a/vm/src/builtins/range.rs b/vm/src/builtins/range.rs index 96e209e04..cf650f941 100644 --- a/vm/src/builtins/range.rs +++ b/vm/src/builtins/range.rs @@ -1,4 +1,4 @@ -use super::{PyInt, PyIntRef, PySlice, PySliceRef, PyTupleRef, PyTypeRef}; +use super::{PyInt, PyIntRef, PySlice, PyTupleRef, PyTypeRef}; use crate::builtins::builtins_iter; use crate::common::hash::PyHash; use crate::{ @@ -664,7 +664,7 @@ fn range_state(length: &BigInt, state: PyObjectRef, vm: &VirtualMachine) -> PyRe pub enum RangeIndex { Int(PyIntRef), - Slice(PySliceRef), + Slice(PyRef), } impl TryFromObject for RangeIndex { diff --git a/vm/src/builtins/slice.rs b/vm/src/builtins/slice.rs index 2748c5ee9..371c63701 100644 --- a/vm/src/builtins/slice.rs +++ b/vm/src/builtins/slice.rs @@ -24,8 +24,6 @@ impl PyValue for PySlice { } } -pub type PySliceRef = PyRef; - #[pyimpl(with(Hashable, Comparable))] impl PySlice { #[pyproperty] diff --git a/vm/src/sliceable.rs b/vm/src/sliceable.rs index c0e44425d..6eab0e5c6 100644 --- a/vm/src/sliceable.rs +++ b/vm/src/sliceable.rs @@ -3,11 +3,11 @@ use std::ops::Range; use crate::builtins::int::PyInt; // export through slicable module, not slice. +use crate::builtins::slice::PySlice; pub use crate::builtins::slice::{saturate_index, SaturatedSlice}; -use crate::builtins::slice::{PySlice, PySliceRef}; use crate::utils::Either; use crate::VirtualMachine; -use crate::{PyObjectRef, PyResult, TypeProtocol}; +use crate::{PyObjectRef, PyRef, PyResult, TypeProtocol}; pub trait PySliceableSequenceMut { type Item: Clone; @@ -332,7 +332,7 @@ impl PySliceableSequence for [T] { pub enum SequenceIndex { Int(isize), - Slice(PySliceRef), + Slice(PyRef), } impl SequenceIndex {