diff --git a/common/src/rc.rs b/common/src/rc.rs index 8021b61122..81207e840c 100644 --- a/common/src/rc.rs +++ b/common/src/rc.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "threading"))] -use std::rc::{Rc, Weak}; +use std::rc::Rc; #[cfg(feature = "threading")] -use std::sync::{Arc, Weak}; +use std::sync::Arc; // type aliases instead of newtypes because you can't do `fn method(self: PyRc)` with a // newtype; requires the arbitrary_self_types unstable feature @@ -10,5 +10,3 @@ use std::sync::{Arc, Weak}; pub type PyRc = Arc; #[cfg(not(feature = "threading"))] pub type PyRc = Rc; - -pub type PyWeak = Weak; diff --git a/derive/src/lib.rs b/derive/src/lib.rs index c99a5874db..8cc7b7c937 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -17,8 +17,8 @@ mod doc; mod from_args; mod pyclass; mod pymodule; +mod pypayload; mod pystructseq; -mod pyvalue; use error::{extract_spans, Diagnostic}; use proc_macro2::TokenStream; @@ -120,8 +120,8 @@ pub fn py_freeze(input: proc_macro::TokenStream) -> proc_macro::TokenStream { result_to_tokens(compile_bytecode::impl_py_freeze(input.into())) } -#[proc_macro_derive(PyValue)] -pub fn pyvalue(input: proc_macro::TokenStream) -> proc_macro::TokenStream { +#[proc_macro_derive(PyPayload)] +pub fn pypayload(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input = parse_macro_input!(input as DeriveInput); - result_to_tokens(pyvalue::impl_pyvalue(input)) + result_to_tokens(pypayload::impl_pypayload(input)) } diff --git a/derive/src/pyclass.rs b/derive/src/pyclass.rs index d40ae081a0..b1aaab9855 100644 --- a/derive/src/pyclass.rs +++ b/derive/src/pyclass.rs @@ -364,7 +364,7 @@ pub(crate) fn impl_define_exception(exc_def: PyExceptionDef) -> Result &::rustpython_vm::builtins::PyTypeRef { &vm.ctx.exceptions.#ctx_name } diff --git a/derive/src/pyvalue.rs b/derive/src/pypayload.rs similarity index 74% rename from derive/src/pyvalue.rs rename to derive/src/pypayload.rs index bcc15fd79e..e382204ff6 100644 --- a/derive/src/pyvalue.rs +++ b/derive/src/pypayload.rs @@ -2,11 +2,11 @@ use proc_macro2::TokenStream; use quote::quote; use syn::{DeriveInput, Result}; -pub(crate) fn impl_pyvalue(input: DeriveInput) -> Result { +pub(crate) fn impl_pypayload(input: DeriveInput) -> Result { let ty = &input.ident; let ret = quote! { - impl ::rustpython_vm::PyValue for #ty { + impl ::rustpython_vm::PyPayload for #ty { fn class(_vm: &::rustpython_vm::VirtualMachine) -> &rustpython_vm::builtins::PyTypeRef { ::static_type() } diff --git a/stdlib/src/array.rs b/stdlib/src/array.rs index 5ff4a1c88a..cf81a85170 100644 --- a/stdlib/src/array.rs +++ b/stdlib/src/array.rs @@ -31,8 +31,7 @@ mod array { AsBuffer, AsMapping, Comparable, Constructor, IterNext, IterNextIterable, Iterable, PyComparisonOp, }, - AsObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, - VirtualMachine, + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }, }; use itertools::Itertools; @@ -583,7 +582,7 @@ mod array { #[pyattr] #[pyclass(name = "array")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub struct PyArray { array: PyRwLock, exports: AtomicUsize, @@ -1152,7 +1151,7 @@ mod array { impl Comparable for PyArray { fn cmp( - zelf: &PyObjectView, + zelf: &Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -1203,7 +1202,7 @@ mod array { } impl AsBuffer for PyArray { - fn as_buffer(zelf: &PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn as_buffer(zelf: &Py, _vm: &VirtualMachine) -> PyResult { let array = zelf.read(); let buf = PyBuffer::new( zelf.to_owned().into(), @@ -1254,7 +1253,7 @@ mod array { } impl AsMapping for PyArray { - fn as_mapping(_zelf: &PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } @@ -1280,7 +1279,7 @@ mod array { #[pyattr] #[pyclass(name = "array_iterator")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub struct PyArrayIter { position: AtomicUsize, array: PyArrayRef, @@ -1291,7 +1290,7 @@ mod array { impl IterNextIterable for PyArrayIter {} impl IterNext for PyArrayIter { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let pos = zelf.position.fetch_add(1, atomic::Ordering::SeqCst); let r = if let Some(item) = zelf.array.read().get(pos, vm) { PyIterReturn::Return(item?) diff --git a/stdlib/src/contextvars.rs b/stdlib/src/contextvars.rs index bb43caf121..24e7ab8108 100644 --- a/stdlib/src/contextvars.rs +++ b/stdlib/src/contextvars.rs @@ -4,11 +4,11 @@ pub(crate) use _contextvars::make_module; mod _contextvars { use rustpython_vm::builtins::{PyFunction, PyStrRef, PyTypeRef}; use rustpython_vm::function::{ArgCallable, FuncArgs, OptionalArg}; - use rustpython_vm::{PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine}; + use rustpython_vm::{PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine}; #[pyattr] #[pyclass(name)] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct Context {} #[pyimpl] @@ -75,7 +75,7 @@ mod _contextvars { #[pyattr] #[pyclass(name)] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct ContextVar { #[allow(dead_code)] // TODO: RUSTPYTHON name: String, @@ -147,7 +147,7 @@ mod _contextvars { #[pyattr] #[pyclass(name = "Token")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct ContextToken {} #[derive(FromArgs)] diff --git a/stdlib/src/csv.rs b/stdlib/src/csv.rs index d04a2e2124..c0efe957f3 100644 --- a/stdlib/src/csv.rs +++ b/stdlib/src/csv.rs @@ -9,7 +9,7 @@ mod _csv { match_class, protocol::{PyIter, PyIterReturn}, types::{IterNext, IterNextIterable}, - AsObject, PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use itertools::{self, Itertools}; use std::fmt; @@ -153,7 +153,7 @@ mod _csv { } #[pyclass(noattr, module = "_csv", name = "reader")] - #[derive(PyValue)] + #[derive(PyPayload)] pub(super) struct Reader { iter: PyIter, state: PyMutex, @@ -169,7 +169,7 @@ mod _csv { impl Reader {} impl IterNextIterable for Reader {} impl IterNext for Reader { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let string = match zelf.iter.next(vm)? { PyIterReturn::Return(obj) => obj, PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)), @@ -243,7 +243,7 @@ mod _csv { } #[pyclass(noattr, module = "_csv", name = "writer")] - #[derive(PyValue)] + #[derive(PyPayload)] pub(super) struct Writer { write: PyObjectRef, state: PyMutex, diff --git a/stdlib/src/hashlib.rs b/stdlib/src/hashlib.rs index 52c98abd82..d375fa1899 100644 --- a/stdlib/src/hashlib.rs +++ b/stdlib/src/hashlib.rs @@ -6,7 +6,7 @@ mod hashlib { use crate::vm::{ builtins::{PyBytes, PyBytesRef, PyStrRef, PyTypeRef}, function::{FuncArgs, OptionalArg}, - PyResult, PyValue, VirtualMachine, + PyPayload, PyResult, VirtualMachine, }; use blake2::{Blake2b512, Blake2s256}; use digest::DynDigest; @@ -46,7 +46,7 @@ mod hashlib { #[pyattr] #[pyclass(module = "hashlib", name = "hasher")] - #[derive(PyValue)] + #[derive(PyPayload)] struct PyHasher { name: String, buffer: PyRwLock, diff --git a/stdlib/src/json.rs b/stdlib/src/json.rs index 3b68d83ce4..8abfd35237 100644 --- a/stdlib/src/json.rs +++ b/stdlib/src/json.rs @@ -10,14 +10,14 @@ mod _json { function::OptionalArg, protocol::PyIterReturn, types::{Callable, Constructor}, - AsObject, PyObjectRef, PyObjectView, PyResult, PyValue, VirtualMachine, + AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use num_bigint::BigInt; use std::str::FromStr; #[pyattr(name = "make_scanner")] #[pyclass(name = "Scanner")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct JsonScanner { strict: bool, object_hook: Option, @@ -196,11 +196,7 @@ mod _json { impl Callable for JsonScanner { type Args = (PyStrRef, isize); - fn call( - zelf: &PyObjectView, - (pystr, idx): Self::Args, - vm: &VirtualMachine, - ) -> PyResult { + fn call(zelf: &Py, (pystr, idx): Self::Args, vm: &VirtualMachine) -> PyResult { if idx < 0 { return Err(vm.new_value_error("idx cannot be negative".to_owned())); } diff --git a/stdlib/src/pyexpat.rs b/stdlib/src/pyexpat.rs index 2aa7a70d58..d37d331b66 100644 --- a/stdlib/src/pyexpat.rs +++ b/stdlib/src/pyexpat.rs @@ -35,7 +35,7 @@ mod _pyexpat { builtins::{PyStr, PyStrRef, PyTypeRef}, function::ArgBytesLike, function::{IntoFuncArgs, OptionalArg}, - PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + PyContext, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use rustpython_common::lock::PyRwLock; use std::io::Cursor; @@ -44,7 +44,7 @@ mod _pyexpat { #[pyattr] #[pyclass(name = "xmlparser", module = false)] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub struct PyExpatLikeXmlParser { start_element: MutableObject, end_element: MutableObject, diff --git a/stdlib/src/pystruct.rs b/stdlib/src/pystruct.rs index 1594d9c136..e104615a22 100644 --- a/stdlib/src/pystruct.rs +++ b/stdlib/src/pystruct.rs @@ -16,7 +16,7 @@ pub(crate) mod _struct { match_class, protocol::PyIterReturn, types::{Constructor, IterNext, IterNextIterable}, - AsObject, PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; @@ -161,7 +161,7 @@ pub(crate) mod _struct { #[pyattr] #[pyclass(name = "unpack_iterator")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct UnpackIterator { format_spec: FormatSpec, buffer: ArgBytesLike, @@ -206,7 +206,7 @@ pub(crate) mod _struct { } impl IterNextIterable for UnpackIterator {} impl IterNext for UnpackIterator { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let size = zelf.format_spec.size; let offset = zelf.offset.fetch_add(size); zelf.buffer.with_ref(|buf| { @@ -238,7 +238,7 @@ pub(crate) mod _struct { #[pyattr] #[pyclass(name = "Struct")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyStruct { spec: FormatSpec, format: PyStrRef, diff --git a/stdlib/src/random.rs b/stdlib/src/random.rs index 1708ca0b49..fbd9725179 100644 --- a/stdlib/src/random.rs +++ b/stdlib/src/random.rs @@ -9,7 +9,7 @@ mod _random { builtins::{PyInt, PyTypeRef}, function::OptionalOption, types::Constructor, - PyObjectRef, PyResult, PyValue, VirtualMachine, + PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use num_bigint::{BigInt, Sign}; use num_traits::{Signed, Zero}; @@ -56,7 +56,7 @@ mod _random { #[pyattr] #[pyclass(name = "Random")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyRandom { rng: PyMutex, } diff --git a/stdlib/src/re.rs b/stdlib/src/re.rs index 9c4dbb5d69..7d5fd161a3 100644 --- a/stdlib/src/re.rs +++ b/stdlib/src/re.rs @@ -12,7 +12,7 @@ mod re { builtins::{PyInt, PyIntRef, PyStr, PyStrRef}, convert::{ToPyObject, TryFromObject}, function::{OptionalArg, PosArgs}, - match_class, PyObjectRef, PyResult, PyValue, VirtualMachine, + match_class, PyObjectRef, PyResult, PyPayload, VirtualMachine, }; use num_traits::Signed; use regex::bytes::{Captures, Regex, RegexBuilder}; @@ -21,7 +21,7 @@ mod re { #[pyattr] #[pyclass(module = "re", name = "Pattern")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyPattern { regex: Regex, pattern: String, @@ -77,7 +77,7 @@ mod re { /// Inner data for a match object. #[pyattr] #[pyclass(module = "re", name = "Match")] - #[derive(PyValue)] + #[derive(PyPayload)] struct PyMatch { haystack: PyStrRef, captures: Vec>>, diff --git a/stdlib/src/select.rs b/stdlib/src/select.rs index 058fa242d6..cb05c93f7f 100644 --- a/stdlib/src/select.rs +++ b/stdlib/src/select.rs @@ -261,14 +261,14 @@ mod decl { use super::*; use crate::vm::{ builtins::PyFloat, common::lock::PyMutex, convert::ToPyObject, function::OptionalArg, - stdlib::io::Fildes, AsObject, PyValue, + stdlib::io::Fildes, AsObject, PyPayload, }; use libc::pollfd; use num_traits::ToPrimitive; use std::time; #[pyclass(module = "select", name = "poll")] - #[derive(Default, Debug, PyValue)] + #[derive(Default, Debug, PyPayload)] pub struct PyPoll { // keep sorted fds: PyMutex>, diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index 63153aa04c..b4c82481f2 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -16,7 +16,7 @@ mod _socket { convert::{ToPyException, ToPyObject, TryFromBorrowedObject, TryFromObject}, function::{ArgBytesLike, ArgMemoryBuffer, FuncArgs, OptionalArg, OptionalOption}, utils::{Either, ToCString}, - AsObject, PyObjectRef, PyResult, PyValue, VirtualMachine, + AsObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use num_traits::ToPrimitive; @@ -231,7 +231,7 @@ mod _socket { #[pyattr(name = "socket")] #[pyattr(name = "SocketType")] #[pyclass(name = "socket")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub struct PySocket { kind: AtomicCell, family: AtomicCell, diff --git a/stdlib/src/ssl.rs b/stdlib/src/ssl.rs index bac1b8bfde..e635484639 100644 --- a/stdlib/src/ssl.rs +++ b/stdlib/src/ssl.rs @@ -30,7 +30,7 @@ mod _ssl { }, socket::{self, PySocket}, vm::{ - builtins::{PyBaseExceptionRef, PyStrRef, PyType, PyTypeRef}, + builtins::{PyBaseExceptionRef, PyStrRef, PyType, PyTypeRef, PyWeak}, convert::{ToPyException, ToPyObject}, exceptions, function::{ @@ -39,7 +39,7 @@ mod _ssl { stdlib::os::PyPathLike, types::Constructor, utils::{Either, ToCString}, - PyObjectRef, PyObjectWeak, PyRef, PyResult, PyValue, VirtualMachine, + PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }, }; use crossbeam_utils::atomic::AtomicCell; @@ -415,7 +415,7 @@ mod _ssl { #[pyattr] #[pyclass(module = "ssl", name = "_SSLContext")] - #[derive(PyValue)] + #[derive(PyPayload)] struct PySslContext { ctx: PyRwLock, check_hostname: AtomicCell, @@ -884,13 +884,13 @@ mod _ssl { #[pyattr] #[pyclass(module = "ssl", name = "_SSLSocket")] - #[derive(PyValue)] + #[derive(PyPayload)] struct PySslSocket { ctx: PyRef, stream: PyRwLock>, socket_type: SslServerOrClient, server_hostname: Option, - owner: PyRwLock>, + owner: PyRwLock>>, } impl fmt::Debug for PySslSocket { @@ -1400,7 +1400,7 @@ mod windows { vm::{ builtins::{PyFrozenSet, PyStrRef}, convert::ToPyException, - PyObjectRef, PyResult, PyValue, VirtualMachine, + PyObjectRef, PyPayload, PyResult, VirtualMachine, }, }; diff --git a/stdlib/src/syslog.rs b/stdlib/src/syslog.rs index 860d4e646e..d32ec7cfd9 100644 --- a/stdlib/src/syslog.rs +++ b/stdlib/src/syslog.rs @@ -7,7 +7,7 @@ mod syslog { builtins::{PyStr, PyStrRef}, function::{OptionalArg, OptionalOption}, utils::ToCString, - PyObjectRef, PyResult, PyValue, VirtualMachine, + PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use std::{ffi::CStr, os::raw::c_char}; diff --git a/stdlib/src/unicodedata.rs b/stdlib/src/unicodedata.rs index 8846da293b..c25ec9503a 100644 --- a/stdlib/src/unicodedata.rs +++ b/stdlib/src/unicodedata.rs @@ -1,7 +1,7 @@ /* Access to the unicode database. See also: https://docs.python.org/3/library/unicodedata.html */ -use crate::vm::{PyObjectRef, PyValue, VirtualMachine}; +use crate::vm::{PyObjectRef, PyPayload, VirtualMachine}; pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { let module = unicodedata::make_module(vm); @@ -25,7 +25,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { #[pymodule] mod unicodedata { use crate::vm::{ - builtins::PyStrRef, function::OptionalArg, PyObjectRef, PyRef, PyResult, PyValue, + builtins::PyStrRef, function::OptionalArg, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use itertools::Itertools; @@ -37,7 +37,7 @@ mod unicodedata { #[pyattr] #[pyclass(name = "UCD")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub(super) struct Ucd { unic_version: UnicodeVersion, } diff --git a/stdlib/src/zlib.rs b/stdlib/src/zlib.rs index 781120d479..aa5ee51fe7 100644 --- a/stdlib/src/zlib.rs +++ b/stdlib/src/zlib.rs @@ -6,7 +6,7 @@ mod zlib { use crate::vm::{ builtins::{PyBaseExceptionRef, PyBytes, PyBytesRef, PyIntRef, PyTypeRef}, function::{ArgBytesLike, OptionalArg, OptionalOption}, - PyResult, PyValue, VirtualMachine, + PyPayload, PyResult, VirtualMachine, }; use adler32::RollingAdler32 as Adler32; use crossbeam_utils::atomic::AtomicCell; @@ -281,7 +281,7 @@ mod zlib { } #[pyattr] #[pyclass(name = "Decompress")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyDecompress { decompress: PyMutex, eof: AtomicCell, @@ -447,7 +447,7 @@ mod zlib { #[pyattr] #[pyclass(name = "Compress")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyCompress { inner: PyMutex, } diff --git a/vm/src/builtins/asyncgenerator.rs b/vm/src/builtins/asyncgenerator.rs index 389070e6cf..841f751527 100644 --- a/vm/src/builtins/asyncgenerator.rs +++ b/vm/src/builtins/asyncgenerator.rs @@ -7,7 +7,7 @@ use crate::{ protocol::PyIterReturn, pyclass::PyClassImpl, types::{Constructor, IterNext, IterNextIterable, Unconstructible}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; @@ -20,7 +20,7 @@ pub struct PyAsyncGen { } type PyAsyncGenRef = PyRef; -impl PyValue for PyAsyncGen { +impl PyPayload for PyAsyncGen { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.async_generator } @@ -134,7 +134,7 @@ impl Unconstructible for PyAsyncGen {} #[pyclass(module = false, name = "async_generator_wrapped_value")] #[derive(Debug)] pub(crate) struct PyAsyncGenWrappedValue(pub PyObjectRef); -impl PyValue for PyAsyncGenWrappedValue { +impl PyPayload for PyAsyncGenWrappedValue { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.async_generator_wrapped_value } @@ -183,7 +183,7 @@ pub(crate) struct PyAsyncGenASend { value: PyObjectRef, } -impl PyValue for PyAsyncGenASend { +impl PyPayload for PyAsyncGenASend { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.async_generator_asend } @@ -264,7 +264,7 @@ impl PyAsyncGenASend { impl IterNextIterable for PyAsyncGenASend {} impl IterNext for PyAsyncGenASend { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { PyIterReturn::from_pyresult(zelf.send(vm.ctx.none(), vm), vm) } } @@ -278,7 +278,7 @@ pub(crate) struct PyAsyncGenAThrow { value: (PyObjectRef, PyObjectRef, PyObjectRef), } -impl PyValue for PyAsyncGenAThrow { +impl PyPayload for PyAsyncGenAThrow { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.async_generator_athrow } @@ -410,7 +410,7 @@ impl PyAsyncGenAThrow { impl IterNextIterable for PyAsyncGenAThrow {} impl IterNext for PyAsyncGenAThrow { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { PyIterReturn::from_pyresult(zelf.send(vm.ctx.none(), vm), vm) } } diff --git a/vm/src/builtins/builtinfunc.rs b/vm/src/builtins/builtinfunc.rs index d534c512f2..69dd39a09e 100644 --- a/vm/src/builtins/builtinfunc.rs +++ b/vm/src/builtins/builtinfunc.rs @@ -4,7 +4,7 @@ use crate::{ function::{FuncArgs, IntoPyNativeFunc, PyNativeFunc}, pyclass::PyClassImpl, types::{Callable, Constructor, GetDescriptor, Unconstructible}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use std::fmt; @@ -62,7 +62,7 @@ pub struct PyBuiltinFunction { module: Option, } -impl PyValue for PyBuiltinFunction { +impl PyPayload for PyBuiltinFunction { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.builtin_function_or_method_type } @@ -105,7 +105,7 @@ impl PyBuiltinFunction { impl Callable for PyBuiltinFunction { type Args = FuncArgs; #[inline] - fn call(zelf: &crate::PyObjectView, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &crate::Py, args: FuncArgs, vm: &VirtualMachine) -> PyResult { (zelf.value.func)(vm, args) } } @@ -167,7 +167,7 @@ pub struct PyBuiltinMethod { class: PyTypeRef, } -impl PyValue for PyBuiltinMethod { +impl PyPayload for PyBuiltinMethod { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.method_descriptor_type } @@ -202,7 +202,7 @@ impl GetDescriptor for PyBuiltinMethod { impl Callable for PyBuiltinMethod { type Args = FuncArgs; #[inline] - fn call(zelf: &crate::PyObjectView, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &crate::Py, args: FuncArgs, vm: &VirtualMachine) -> PyResult { (zelf.value.func)(vm, args) } } diff --git a/vm/src/builtins/bytearray.rs b/vm/src/builtins/bytearray.rs index f8d9129258..f7a56b6a33 100644 --- a/vm/src/builtins/bytearray.rs +++ b/vm/src/builtins/bytearray.rs @@ -33,7 +33,7 @@ use crate::{ IterNextIterable, Iterable, PyComparisonOp, Unconstructible, Unhashable, }, utils::Either, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use bstr::ByteSlice; @@ -81,7 +81,7 @@ impl From> for PyByteArray { } } -impl PyValue for PyByteArray { +impl PyPayload for PyByteArray { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.bytearray_type } @@ -303,7 +303,7 @@ impl PyByteArray { } } - fn irepeat(zelf: &crate::PyObjectView, n: isize, vm: &VirtualMachine) -> PyResult<()> { + fn irepeat(zelf: &crate::Py, n: isize, vm: &VirtualMachine) -> PyResult<()> { if n == 1 { return Ok(()); } @@ -714,7 +714,7 @@ impl PyByteArray { impl Comparable for PyByteArray { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -749,7 +749,7 @@ static BUFFER_METHODS: BufferMethods = BufferMethods { }; impl AsBuffer for PyByteArray { - fn as_buffer(zelf: &PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn as_buffer(zelf: &Py, _vm: &VirtualMachine) -> PyResult { Ok(PyBuffer::new( zelf.to_owned().into(), BufferDescriptor::simple(zelf.len(), false), @@ -768,16 +768,13 @@ impl<'a> BufferResizeGuard<'a> for PyByteArray { } impl AsMapping for PyByteArray { - fn as_mapping(_zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &crate::Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl AsSequence for PyByteArray { - fn as_sequence( - _zelf: &PyObjectView, - _vm: &VirtualMachine, - ) -> Cow<'static, PySequenceMethods> { + fn as_sequence(_zelf: &Py, _vm: &VirtualMachine) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) } } @@ -847,7 +844,7 @@ pub struct PyByteArrayIterator { internal: PyMutex>, } -impl PyValue for PyByteArrayIterator { +impl PyPayload for PyByteArrayIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.bytearray_iterator_type } @@ -877,7 +874,7 @@ impl Unconstructible for PyByteArrayIterator {} impl IterNextIterable for PyByteArrayIterator {} impl IterNext for PyByteArrayIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { zelf.internal.lock().next(|bytearray, pos| { let buf = bytearray.borrow_buf(); Ok(PyIterReturn::from_result( diff --git a/vm/src/builtins/bytes.rs b/vm/src/builtins/bytes.rs index 1fcc21d6cf..b33474eb67 100644 --- a/vm/src/builtins/bytes.rs +++ b/vm/src/builtins/bytes.rs @@ -20,7 +20,7 @@ use crate::{ IterNextIterable, Iterable, PyComparisonOp, Unconstructible, }, utils::Either, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use bstr::ByteSlice; @@ -73,7 +73,7 @@ impl AsRef<[u8]> for PyBytesRef { } } -impl PyValue for PyBytes { +impl PyPayload for PyBytes { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.bytes_type } @@ -565,7 +565,7 @@ static BUFFER_METHODS: BufferMethods = BufferMethods { }; impl AsBuffer for PyBytes { - fn as_buffer(zelf: &PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn as_buffer(zelf: &Py, _vm: &VirtualMachine) -> PyResult { let buf = PyBuffer::new( zelf.to_owned().into(), BufferDescriptor::simple(zelf.len(), true), @@ -576,16 +576,13 @@ impl AsBuffer for PyBytes { } impl AsMapping for PyBytes { - fn as_mapping(_zelf: &PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl AsSequence for PyBytes { - fn as_sequence( - _zelf: &PyObjectView, - _vm: &VirtualMachine, - ) -> Cow<'static, PySequenceMethods> { + fn as_sequence(_zelf: &Py, _vm: &VirtualMachine) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) } } @@ -622,14 +619,14 @@ impl PyBytes { impl Hashable for PyBytes { #[inline] - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { Ok(zelf.inner.hash(vm)) } } impl Comparable for PyBytes { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -667,7 +664,7 @@ pub struct PyBytesIterator { internal: PyMutex>, } -impl PyValue for PyBytesIterator { +impl PyPayload for PyBytesIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.bytes_iterator_type } @@ -698,7 +695,7 @@ impl Unconstructible for PyBytesIterator {} impl IterNextIterable for PyBytesIterator {} impl IterNext for PyBytesIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { zelf.internal.lock().next(|bytes, pos| { Ok(PyIterReturn::from_result( bytes diff --git a/vm/src/builtins/classmethod.rs b/vm/src/builtins/classmethod.rs index ecbb4c0d1f..adca585bd0 100644 --- a/vm/src/builtins/classmethod.rs +++ b/vm/src/builtins/classmethod.rs @@ -3,7 +3,7 @@ use crate::{ builtins::PyBoundMethod, pyclass::PyClassImpl, types::{Constructor, GetDescriptor}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; /// classmethod(function) -> method @@ -38,7 +38,7 @@ impl From for PyClassMethod { } } -impl PyValue for PyClassMethod { +impl PyPayload for PyClassMethod { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.classmethod_type } diff --git a/vm/src/builtins/code.rs b/vm/src/builtins/code.rs index a3e46f1acb..c1c254e02c 100644 --- a/vm/src/builtins/code.rs +++ b/vm/src/builtins/code.rs @@ -7,7 +7,7 @@ use crate::{ bytecode::{self, BorrowedConstant, Constant, ConstantBag}, function::FuncArgs, pyclass::{PyClassImpl, StaticType}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use num_traits::Zero; use std::{fmt, ops::Deref}; @@ -185,7 +185,7 @@ impl fmt::Debug for PyCode { } } -impl PyValue for PyCode { +impl PyPayload for PyCode { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.code_type } diff --git a/vm/src/builtins/complex.rs b/vm/src/builtins/complex.rs index 4032851baf..65bff25aef 100644 --- a/vm/src/builtins/complex.rs +++ b/vm/src/builtins/complex.rs @@ -8,7 +8,7 @@ use crate::{ }, pyclass::PyClassImpl, types::{Comparable, Constructor, Hashable, PyComparisonOp}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use num_complex::Complex64; use num_traits::Zero; @@ -23,7 +23,7 @@ pub struct PyComplex { value: Complex64, } -impl PyValue for PyComplex { +impl PyPayload for PyComplex { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.complex_type } @@ -387,7 +387,7 @@ impl PyComplex { impl Comparable for PyComplex { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -409,7 +409,7 @@ impl Comparable for PyComplex { impl Hashable for PyComplex { #[inline] - fn hash(zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult { Ok(hash::hash_complex(&zelf.value)) } } diff --git a/vm/src/builtins/coroutine.rs b/vm/src/builtins/coroutine.rs index dc46e966fa..bcb9a6dcb7 100644 --- a/vm/src/builtins/coroutine.rs +++ b/vm/src/builtins/coroutine.rs @@ -6,7 +6,7 @@ use crate::{ protocol::PyIterReturn, pyclass::PyClassImpl, types::{Constructor, IterNext, IterNextIterable, Unconstructible}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "coroutine")] @@ -16,7 +16,7 @@ pub struct PyCoroutine { inner: Coro, } -impl PyValue for PyCoroutine { +impl PyPayload for PyCoroutine { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.coroutine_type } @@ -108,7 +108,7 @@ impl Unconstructible for PyCoroutine {} impl IterNextIterable for PyCoroutine {} impl IterNext for PyCoroutine { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { Self::send(zelf.to_owned(), vm.ctx.none(), vm) } } @@ -120,7 +120,7 @@ pub struct PyCoroutineWrapper { coro: PyRef, } -impl PyValue for PyCoroutineWrapper { +impl PyPayload for PyCoroutineWrapper { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.coroutine_wrapper_type } @@ -147,7 +147,7 @@ impl PyCoroutineWrapper { impl IterNextIterable for PyCoroutineWrapper {} impl IterNext for PyCoroutineWrapper { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { Self::send(zelf.to_owned(), vm.ctx.none(), vm) } } diff --git a/vm/src/builtins/dict.rs b/vm/src/builtins/dict.rs index f8a0fa4b1d..9e245fe6df 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -21,8 +21,7 @@ use crate::{ IterNextIterable, Iterable, PyComparisonOp, Unconstructible, Unhashable, }, vm::{ReprGuard, VirtualMachine}, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, - TryFromObject, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; use rustpython_common::lock::PyMutex; use std::{borrow::Cow, fmt}; @@ -52,7 +51,7 @@ impl fmt::Debug for PyDict { } } -impl PyValue for PyDict { +impl PyPayload for PyDict { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.dict_type } @@ -180,8 +179,8 @@ impl PyDict { } fn inner_cmp( - zelf: &PyObjectView, - other: &PyObjectView, + zelf: &Py, + other: &Py, op: PyComparisonOp, item: bool, vm: &VirtualMachine, @@ -463,16 +462,13 @@ impl PyDict { } impl AsMapping for PyDict { - fn as_mapping(_zelf: &PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl AsSequence for PyDict { - fn as_sequence( - _zelf: &PyObjectView, - _vm: &VirtualMachine, - ) -> Cow<'static, PySequenceMethods> { + fn as_sequence(_zelf: &Py, _vm: &VirtualMachine) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) } } @@ -486,7 +482,7 @@ impl PyDict { impl Comparable for PyDict { fn cmp( - zelf: &PyObjectView, + zelf: &Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -506,7 +502,7 @@ impl Iterable for PyDict { } } -impl PyObjectView { +impl Py { #[inline] fn exact_dict(&self, vm: &VirtualMachine) -> bool { self.class().is(&vm.ctx.types.dict_type) @@ -636,7 +632,7 @@ impl IntoIterator for &PyDictRef { } } -impl IntoIterator for &PyObjectView { +impl IntoIterator for &Py { type Item = (PyObjectRef, PyObjectRef); type IntoIter = DictIter; @@ -672,9 +668,9 @@ impl Iterator for DictIter { } #[pyimpl] -trait DictView: PyValue + PyClassDef + Iterable +trait DictView: PyPayload + PyClassDef + Iterable where - Self::ReverseIter: PyValue, + Self::ReverseIter: PyPayload, { type ReverseIter; @@ -741,7 +737,7 @@ macro_rules! dict_view { } } - impl PyValue for $name { + impl PyPayload for $name { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.$class } @@ -754,7 +750,7 @@ macro_rules! dict_view { pub internal: PyMutex>, } - impl PyValue for $iter_name { + impl PyPayload for $iter_name { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.$iter_class } @@ -794,7 +790,7 @@ macro_rules! dict_view { impl IterNextIterable for $iter_name {} impl IterNext for $iter_name { #[allow(clippy::redundant_closure_call)] - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let mut internal = zelf.internal.lock(); let next = if let IterStatus::Active(dict) = &internal.status { if dict.entries.has_changed_size(&zelf.size) { @@ -827,7 +823,7 @@ macro_rules! dict_view { internal: PyMutex>, } - impl PyValue for $reverse_iter_name { + impl PyPayload for $reverse_iter_name { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.$reverse_iter_class } @@ -872,7 +868,7 @@ macro_rules! dict_view { impl IterNextIterable for $reverse_iter_name {} impl IterNext for $reverse_iter_name { #[allow(clippy::redundant_closure_call)] - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let mut internal = zelf.internal.lock(); let next = if let IterStatus::Active(dict) = &internal.status { if dict.entries.has_changed_size(&zelf.size) { @@ -994,7 +990,7 @@ trait ViewSetOps: DictView { } fn cmp( - zelf: &PyObjectView, + zelf: &Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -1041,7 +1037,7 @@ impl Unconstructible for PyDictKeys {} impl Comparable for PyDictKeys { fn cmp( - zelf: &PyObjectView, + zelf: &Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -1051,10 +1047,7 @@ impl Comparable for PyDictKeys { } impl AsSequence for PyDictKeys { - fn as_sequence( - _zelf: &PyObjectView, - _vm: &VirtualMachine, - ) -> Cow<'static, PySequenceMethods> { + fn as_sequence(_zelf: &Py, _vm: &VirtualMachine) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) } } @@ -1098,7 +1091,7 @@ impl Unconstructible for PyDictItems {} impl Comparable for PyDictItems { fn cmp( - zelf: &PyObjectView, + zelf: &Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -1108,10 +1101,7 @@ impl Comparable for PyDictItems { } impl AsSequence for PyDictItems { - fn as_sequence( - _zelf: &PyObjectView, - _vm: &VirtualMachine, - ) -> Cow<'static, PySequenceMethods> { + fn as_sequence(_zelf: &Py, _vm: &VirtualMachine) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) } } @@ -1133,10 +1123,7 @@ impl PyDictValues {} impl Unconstructible for PyDictValues {} impl AsSequence for PyDictValues { - fn as_sequence( - _zelf: &PyObjectView, - _vm: &VirtualMachine, - ) -> Cow<'static, PySequenceMethods> { + fn as_sequence(_zelf: &Py, _vm: &VirtualMachine) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) } } diff --git a/vm/src/builtins/enumerate.rs b/vm/src/builtins/enumerate.rs index 3c6318c512..d9a6e55c6a 100644 --- a/vm/src/builtins/enumerate.rs +++ b/vm/src/builtins/enumerate.rs @@ -6,7 +6,7 @@ use crate::{ protocol::{PyIter, PyIterReturn}, pyclass::PyClassImpl, types::{Constructor, IterNext, IterNextIterable}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use num_bigint::BigInt; use num_traits::Zero; @@ -18,7 +18,7 @@ pub struct PyEnumerate { iterator: PyIter, } -impl PyValue for PyEnumerate { +impl PyPayload for PyEnumerate { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.enumerate_type } @@ -65,7 +65,7 @@ impl PyEnumerate { impl IterNextIterable for PyEnumerate {} impl IterNext for PyEnumerate { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let next_obj = match zelf.iterator.next(vm)? { PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)), PyIterReturn::Return(obj) => obj, @@ -83,7 +83,7 @@ pub struct PyReverseSequenceIterator { internal: PyMutex>, } -impl PyValue for PyReverseSequenceIterator { +impl PyPayload for PyReverseSequenceIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.reverse_iter_type } @@ -124,7 +124,7 @@ impl PyReverseSequenceIterator { impl IterNextIterable for PyReverseSequenceIterator {} impl IterNext for PyReverseSequenceIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { zelf.internal .lock() .rev_next(|obj, pos| PyIterReturn::from_getitem_result(obj.get_item(pos, vm), vm)) diff --git a/vm/src/builtins/filter.rs b/vm/src/builtins/filter.rs index a145afe81d..d9570b3bff 100644 --- a/vm/src/builtins/filter.rs +++ b/vm/src/builtins/filter.rs @@ -3,7 +3,7 @@ use crate::{ protocol::{PyIter, PyIterReturn}, pyclass::PyClassImpl, types::{Constructor, IterNext, IterNextIterable}, - PyContext, PyObjectRef, PyResult, PyValue, VirtualMachine, + PyContext, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; /// filter(function or None, iterable) --> filter object @@ -17,7 +17,7 @@ pub struct PyFilter { iterator: PyIter, } -impl PyValue for PyFilter { +impl PyPayload for PyFilter { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.filter_type } @@ -40,7 +40,7 @@ impl PyFilter {} impl IterNextIterable for PyFilter {} impl IterNext for PyFilter { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let predicate = &zelf.predicate; loop { let next_obj = match zelf.iterator.next(vm)? { diff --git a/vm/src/builtins/float.rs b/vm/src/builtins/float.rs index c5fc2afde7..bd1ca02255 100644 --- a/vm/src/builtins/float.rs +++ b/vm/src/builtins/float.rs @@ -10,7 +10,7 @@ use crate::{ }, pyclass::PyClassImpl, types::{Comparable, Constructor, Hashable, PyComparisonOp}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use num_bigint::{BigInt, ToBigInt}; @@ -31,7 +31,7 @@ impl PyFloat { } } -impl PyValue for PyFloat { +impl PyPayload for PyFloat { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.float_type } @@ -511,7 +511,7 @@ impl PyFloat { impl Comparable for PyFloat { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -552,7 +552,7 @@ impl Comparable for PyFloat { impl Hashable for PyFloat { #[inline] - fn hash(zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult { Ok(hash::hash_float(zelf.to_f64())) } } diff --git a/vm/src/builtins/function.rs b/vm/src/builtins/function.rs index c64a515f17..06631328e2 100644 --- a/vm/src/builtins/function.rs +++ b/vm/src/builtins/function.rs @@ -14,7 +14,7 @@ use crate::{ pyclass::PyClassImpl, scope::Scope, types::{Callable, Comparable, Constructor, GetAttr, GetDescriptor, PyComparisonOp}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[cfg(feature = "jit")] use crate::{common::lock::OnceCell, convert::ToPyObject}; @@ -324,7 +324,7 @@ impl PyFunction { } } -impl PyValue for PyFunction { +impl PyPayload for PyFunction { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.function_type } @@ -422,7 +422,7 @@ impl GetDescriptor for PyFunction { impl Callable for PyFunction { type Args = FuncArgs; #[inline] - fn call(zelf: &crate::PyObjectView, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &crate::Py, args: FuncArgs, vm: &VirtualMachine) -> PyResult { zelf.invoke(args, vm) } } @@ -437,7 +437,7 @@ pub struct PyBoundMethod { impl Callable for PyBoundMethod { type Args = FuncArgs; #[inline] - fn call(zelf: &crate::PyObjectView, mut args: FuncArgs, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &crate::Py, mut args: FuncArgs, vm: &VirtualMachine) -> PyResult { args.prepend_arg(zelf.object.clone()); vm.invoke(&zelf.function, args) } @@ -445,7 +445,7 @@ impl Callable for PyBoundMethod { impl Comparable for PyBoundMethod { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, _vm: &VirtualMachine, @@ -565,7 +565,7 @@ impl PyBoundMethod { } } -impl PyValue for PyBoundMethod { +impl PyPayload for PyBoundMethod { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.bound_method_type } @@ -578,7 +578,7 @@ pub(crate) struct PyCell { } pub(crate) type PyCellRef = PyRef; -impl PyValue for PyCell { +impl PyPayload for PyCell { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.cell_type } diff --git a/vm/src/builtins/function/jitfunc.rs b/vm/src/builtins/function/jitfunc.rs index a41c0e109c..3163c280fd 100644 --- a/vm/src/builtins/function/jitfunc.rs +++ b/vm/src/builtins/function/jitfunc.rs @@ -65,7 +65,7 @@ fn get_jit_arg_type(dict: &PyDictRef, name: &str, vm: &VirtualMachine) -> PyResu } pub fn get_jit_arg_types( - func: &crate::PyObjectView, + func: &crate::Py, vm: &VirtualMachine, ) -> PyResult> { let arg_names = func.code.arg_names(); diff --git a/vm/src/builtins/generator.rs b/vm/src/builtins/generator.rs index 41f3e4ace1..70937496c6 100644 --- a/vm/src/builtins/generator.rs +++ b/vm/src/builtins/generator.rs @@ -10,7 +10,7 @@ use crate::{ protocol::PyIterReturn, pyclass::PyClassImpl, types::{Constructor, IterNext, IterNextIterable, Unconstructible}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "generator")] @@ -19,7 +19,7 @@ pub struct PyGenerator { inner: Coro, } -impl PyValue for PyGenerator { +impl PyPayload for PyGenerator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.generator_type } @@ -100,7 +100,7 @@ impl Unconstructible for PyGenerator {} impl IterNextIterable for PyGenerator {} impl IterNext for PyGenerator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { Self::send(zelf.to_owned(), vm.ctx.none(), vm) } } diff --git a/vm/src/builtins/genericalias.rs b/vm/src/builtins/genericalias.rs index 6414161a19..d27b9fae13 100644 --- a/vm/src/builtins/genericalias.rs +++ b/vm/src/builtins/genericalias.rs @@ -6,8 +6,8 @@ use crate::{ protocol::PyMappingMethods, pyclass::PyClassImpl, types::{AsMapping, Callable, Comparable, Constructor, GetAttr, Hashable, PyComparisonOp}, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, - TryFromObject, VirtualMachine, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, }; use std::fmt; @@ -35,7 +35,7 @@ impl fmt::Debug for PyGenericAlias { } } -impl PyValue for PyGenericAlias { +impl PyPayload for PyGenericAlias { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.generic_alias_type } @@ -314,14 +314,14 @@ impl PyGenericAlias { } impl AsMapping for PyGenericAlias { - fn as_mapping(_zelf: &PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl Callable for PyGenericAlias { type Args = FuncArgs; - fn call(zelf: &crate::PyObjectView, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &crate::Py, args: FuncArgs, vm: &VirtualMachine) -> PyResult { PyType::call(&zelf.origin, args, vm).map(|obj| { if let Err(exc) = obj.set_attr("__orig_class__", zelf.to_owned(), vm) { if !exc.fast_isinstance(&vm.ctx.exceptions.attribute_error) @@ -337,7 +337,7 @@ impl Callable for PyGenericAlias { impl Comparable for PyGenericAlias { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -361,7 +361,7 @@ impl Comparable for PyGenericAlias { impl Hashable for PyGenericAlias { #[inline] - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { Ok(zelf.origin.as_object().hash(vm)? ^ zelf.args.as_object().hash(vm)?) } } diff --git a/vm/src/builtins/getset.rs b/vm/src/builtins/getset.rs index 935b4198bf..ecba8cb60d 100644 --- a/vm/src/builtins/getset.rs +++ b/vm/src/builtins/getset.rs @@ -8,7 +8,7 @@ use crate::{ pyclass::PyClassImpl, pyobject::PyThreadingConstraint, types::{Constructor, GetDescriptor, Unconstructible}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; pub type PyGetterFunc = Box PyResult)>; @@ -38,7 +38,7 @@ where impl IntoPyGetterFunc<(RefParam, R, VirtualMachine)> for F where F: Fn(&S, &VirtualMachine) -> R + 'static + Send + Sync, - S: PyValue, + S: PyPayload, R: ToPyResult, { fn get(&self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { @@ -62,7 +62,7 @@ where impl IntoPyGetterFunc<(RefParam, R)> for F where F: Fn(&S) -> R + 'static + Send + Sync, - S: PyValue, + S: PyPayload, R: ToPyResult, { fn get(&self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { @@ -113,7 +113,7 @@ where impl IntoPySetterFunc<(RefParam, V, R, VirtualMachine)> for F where F: Fn(&S, V, &VirtualMachine) -> R + 'static + Send + Sync, - S: PyValue, + S: PyPayload, V: TryFromObject, R: IntoPyNoResult, { @@ -141,7 +141,7 @@ where impl IntoPySetterFunc<(RefParam, V, R)> for F where F: Fn(&S, V) -> R + 'static + Send + Sync, - S: PyValue, + S: PyPayload, V: TryFromObject, R: IntoPyNoResult, { @@ -174,7 +174,7 @@ where impl IntoPyDeleterFunc<(RefParam, R, VirtualMachine)> for F where F: Fn(&S, &VirtualMachine) -> R + 'static + Send + Sync, - S: PyValue, + S: PyPayload, R: IntoPyNoResult, { fn delete(&self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> { @@ -198,7 +198,7 @@ where impl IntoPyDeleterFunc<(RefParam, R)> for F where F: Fn(&S) -> R + 'static + Send + Sync, - S: PyValue, + S: PyPayload, R: IntoPyNoResult, { fn delete(&self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> { @@ -237,7 +237,7 @@ impl std::fmt::Debug for PyGetSet { } } -impl PyValue for PyGetSet { +impl PyPayload for PyGetSet { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.getset_type } diff --git a/vm/src/builtins/int.rs b/vm/src/builtins/int.rs index 9690e6432c..f542e75616 100644 --- a/vm/src/builtins/int.rs +++ b/vm/src/builtins/int.rs @@ -7,7 +7,7 @@ use crate::{ function::{ArgIntoBool, OptionalArg, OptionalOption, PyArithmeticValue, PyComparisonValue}, pyclass::PyClassImpl, types::{Comparable, Constructor, Hashable, PyComparisonOp}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, VirtualMachine, }; use bstr::ByteSlice; @@ -53,7 +53,7 @@ where } } -impl PyValue for PyInt { +impl PyPayload for PyInt { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.int_type } @@ -721,7 +721,7 @@ impl PyInt { impl Comparable for PyInt { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -735,7 +735,7 @@ impl Comparable for PyInt { impl Hashable for PyInt { #[inline] - fn hash(zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult { Ok(hash::hash_bigint(zelf.as_bigint())) } } diff --git a/vm/src/builtins/iter.rs b/vm/src/builtins/iter.rs index c2f529944d..e0e07a5839 100644 --- a/vm/src/builtins/iter.rs +++ b/vm/src/builtins/iter.rs @@ -10,7 +10,7 @@ use crate::{ protocol::{PyIterReturn, PySequence, PySequenceMethods}, pyclass::PyClassImpl, types::{IterNext, IterNextIterable}, - PyContext, PyObject, PyObjectRef, PyResult, PyValue, VirtualMachine, + PyContext, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use rustpython_common::{ lock::{PyMutex, PyRwLock, PyRwLockUpgradableReadGuard}, @@ -168,7 +168,7 @@ pub struct PySequenceIterator { internal: PyMutex>, } -impl PyValue for PySequenceIterator { +impl PyPayload for PySequenceIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.iter_type } @@ -211,7 +211,7 @@ impl PySequenceIterator { impl IterNextIterable for PySequenceIterator {} impl IterNext for PySequenceIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { zelf.internal.lock().next(|obj, pos| { let seq = PySequence::with_methods(obj, zelf.seq_methods.clone()); PyIterReturn::from_getitem_result(seq.get_item(pos as isize, vm), vm) @@ -226,7 +226,7 @@ pub struct PyCallableIterator { status: PyRwLock>, } -impl PyValue for PyCallableIterator { +impl PyPayload for PyCallableIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.callable_iterator } @@ -244,7 +244,7 @@ impl PyCallableIterator { impl IterNextIterable for PyCallableIterator {} impl IterNext for PyCallableIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let status = zelf.status.upgradable_read(); let next = if let IterStatus::Active(callable) = &*status { let ret = callable.invoke((), vm)?; diff --git a/vm/src/builtins/list.rs b/vm/src/builtins/list.rs index d3545d646e..dbb1c51042 100644 --- a/vm/src/builtins/list.rs +++ b/vm/src/builtins/list.rs @@ -16,7 +16,7 @@ use crate::{ }, utils::collection_repr, vm::{ReprGuard, VirtualMachine}, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, }; use std::{borrow::Cow, fmt, ops::DerefMut}; @@ -51,7 +51,7 @@ impl FromIterator for PyList { } } -impl PyValue for PyList { +impl PyPayload for PyList { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.list_type } @@ -129,11 +129,7 @@ impl PyList { self.concat(&other, vm) } - fn inplace_concat( - zelf: &PyObjectView, - other: &PyObject, - vm: &VirtualMachine, - ) -> PyObjectRef { + fn inplace_concat(zelf: &Py, other: &PyObject, vm: &VirtualMachine) -> PyObjectRef { if let Ok(mut seq) = PySequence::from(other).extract_cloned(Ok, vm) { zelf.borrow_vec_mut().append(&mut seq); zelf.to_owned().into() @@ -392,14 +388,14 @@ impl PyList { } impl AsMapping for PyList { - fn as_mapping(_zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &crate::Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl AsSequence for PyList { fn as_sequence( - _zelf: &crate::PyObjectView, + _zelf: &crate::Py, _vm: &VirtualMachine, ) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHDOS) @@ -458,7 +454,7 @@ impl Iterable for PyList { impl Comparable for PyList { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -508,7 +504,7 @@ pub struct PyListIterator { internal: PyMutex>, } -impl PyValue for PyListIterator { +impl PyPayload for PyListIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.list_iterator_type } @@ -539,7 +535,7 @@ impl Unconstructible for PyListIterator {} impl IterNextIterable for PyListIterator {} impl IterNext for PyListIterator { - fn next(zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult { zelf.internal.lock().next(|list, pos| { let vec = list.borrow_vec(); Ok(PyIterReturn::from_result(vec.get(pos).cloned().ok_or(None))) @@ -553,7 +549,7 @@ pub struct PyListReverseIterator { internal: PyMutex>, } -impl PyValue for PyListReverseIterator { +impl PyPayload for PyListReverseIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.list_reverseiterator_type } @@ -584,7 +580,7 @@ impl Unconstructible for PyListReverseIterator {} impl IterNextIterable for PyListReverseIterator {} impl IterNext for PyListReverseIterator { - fn next(zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult { zelf.internal.lock().rev_next(|list, pos| { let vec = list.borrow_vec(); Ok(PyIterReturn::from_result(vec.get(pos).cloned().ok_or(None))) diff --git a/vm/src/builtins/map.rs b/vm/src/builtins/map.rs index e74b2be5e6..9b54d2cb85 100644 --- a/vm/src/builtins/map.rs +++ b/vm/src/builtins/map.rs @@ -4,7 +4,7 @@ use crate::{ protocol::{PyIter, PyIterReturn}, pyclass::PyClassImpl, types::{Constructor, IterNext, IterNextIterable}, - PyContext, PyObjectRef, PyResult, PyValue, VirtualMachine, + PyContext, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; /// map(func, *iterables) --> map object @@ -18,7 +18,7 @@ pub struct PyMap { iterators: Vec, } -impl PyValue for PyMap { +impl PyPayload for PyMap { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.map_type } @@ -47,7 +47,7 @@ impl PyMap { impl IterNextIterable for PyMap {} impl IterNext for PyMap { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let mut next_objs = Vec::new(); for iterator in zelf.iterators.iter() { let item = match iterator.next(vm)? { diff --git a/vm/src/builtins/mappingproxy.rs b/vm/src/builtins/mappingproxy.rs index c7404c5762..447c1a986f 100644 --- a/vm/src/builtins/mappingproxy.rs +++ b/vm/src/builtins/mappingproxy.rs @@ -7,7 +7,7 @@ use crate::{ protocol::{PyMapping, PyMappingMethods, PySequence, PySequenceMethods}, pyclass::PyClassImpl, types::{AsMapping, AsSequence, Constructor, Iterable}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; @@ -23,7 +23,7 @@ enum MappingProxyInner { Dict(PyObjectRef), } -impl PyValue for PyMappingProxy { +impl PyPayload for PyMappingProxy { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.mappingproxy_type } @@ -174,14 +174,14 @@ impl PyMappingProxy { } impl AsMapping for PyMappingProxy { - fn as_mapping(_zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &crate::Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl AsSequence for PyMappingProxy { fn as_sequence( - _zelf: &crate::PyObjectView, + _zelf: &crate::Py, _vm: &VirtualMachine, ) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) diff --git a/vm/src/builtins/memory.rs b/vm/src/builtins/memory.rs index bcc116cc47..4260feb195 100644 --- a/vm/src/builtins/memory.rs +++ b/vm/src/builtins/memory.rs @@ -19,7 +19,7 @@ use crate::{ sliceable::wrap_index, types::{AsBuffer, AsMapping, AsSequence, Comparable, Constructor, Hashable, PyComparisonOp}, utils::Either, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; @@ -698,11 +698,7 @@ impl PyMemoryView { } } - fn eq( - zelf: &crate::PyObjectView, - other: &PyObject, - vm: &VirtualMachine, - ) -> PyResult { + fn eq(zelf: &crate::Py, other: &PyObject, vm: &VirtualMachine) -> PyResult { if zelf.is(other) { return Ok(true); } @@ -931,7 +927,7 @@ static BUFFER_METHODS: BufferMethods = BufferMethods { }; impl AsBuffer for PyMemoryView { - fn as_buffer(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn as_buffer(zelf: &Py, vm: &VirtualMachine) -> PyResult { if zelf.released.load() { Err(vm.new_value_error("operation forbidden on released memoryview object".to_owned())) } else { @@ -973,16 +969,13 @@ impl PyMemoryView { } impl AsMapping for PyMemoryView { - fn as_mapping(_zelf: &PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl AsSequence for PyMemoryView { - fn as_sequence( - _zelf: &PyObjectView, - _vm: &VirtualMachine, - ) -> Cow<'static, PySequenceMethods> { + fn as_sequence(_zelf: &Py, _vm: &VirtualMachine) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) } } @@ -1005,7 +998,7 @@ impl PyMemoryView { impl Comparable for PyMemoryView { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -1026,7 +1019,7 @@ impl Comparable for PyMemoryView { } impl Hashable for PyMemoryView { - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { zelf.hash .get_or_try_init(|| { zelf.try_not_released(vm)?; @@ -1041,7 +1034,7 @@ impl Hashable for PyMemoryView { } } -impl PyValue for PyMemoryView { +impl PyPayload for PyMemoryView { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.memoryview_type } diff --git a/vm/src/builtins/module.rs b/vm/src/builtins/module.rs index 15396d7d61..05e9cb5f73 100644 --- a/vm/src/builtins/module.rs +++ b/vm/src/builtins/module.rs @@ -1,15 +1,15 @@ use super::pystr::IntoPyStrRef; use super::{PyDictRef, PyStr, PyStrRef, PyTypeRef}; use crate::{ - convert::ToPyObject, function::FuncArgs, pyclass::PyClassImpl, types::GetAttr, AsObject, - PyContext, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, VirtualMachine, + convert::ToPyObject, function::FuncArgs, pyclass::PyClassImpl, types::GetAttr, AsObject, Py, + PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "module")] #[derive(Debug)] pub struct PyModule {} -impl PyValue for PyModule { +impl PyPayload for PyModule { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.module_type } @@ -48,7 +48,7 @@ impl PyModule { zelf.init_module_dict(args.name.into(), args.doc.to_pyobject(vm), vm); } - fn getattr_inner(zelf: &PyObjectView, name: PyStrRef, vm: &VirtualMachine) -> PyResult { + fn getattr_inner(zelf: &Py, name: PyStrRef, vm: &VirtualMachine) -> PyResult { if let Some(attr) = vm.generic_getattribute_opt(zelf.to_owned().into(), name.clone(), None)? { @@ -89,12 +89,12 @@ impl PyModule { } } -impl PyObjectView { +impl Py { // TODO: to be replaced by the commented-out dict method above once dictoffsets land pub fn dict(&self) -> PyDictRef { self.as_object().dict().unwrap() } - // TODO: should be on PyModule, not PyObjectView + // TODO: should be on PyModule, not Py pub(crate) fn init_module_dict( &self, name: PyObjectRef, diff --git a/vm/src/builtins/namespace.rs b/vm/src/builtins/namespace.rs index 85cae053a3..f50120dcfb 100644 --- a/vm/src/builtins/namespace.rs +++ b/vm/src/builtins/namespace.rs @@ -5,7 +5,7 @@ use crate::{ pyclass::PyClassImpl, types::{Comparable, Constructor, PyComparisonOp}, vm::ReprGuard, - AsObject, PyContext, PyObject, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObject, PyPayload, PyRef, PyResult, VirtualMachine, }; /// A simple attribute-based namespace. @@ -15,7 +15,7 @@ use crate::{ #[derive(Debug)] pub struct PyNamespace {} -impl PyValue for PyNamespace { +impl PyPayload for PyNamespace { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.namespace_type } @@ -80,7 +80,7 @@ impl PyNamespace { impl Comparable for PyNamespace { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, diff --git a/vm/src/builtins/object.rs b/vm/src/builtins/object.rs index 43d71acf34..9c0d79ffc4 100644 --- a/vm/src/builtins/object.rs +++ b/vm/src/builtins/object.rs @@ -5,7 +5,7 @@ use crate::{ pyclass::PyClassImpl, types::PyComparisonOp, utils::Either, - AsObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; /// object() @@ -19,7 +19,7 @@ use crate::{ #[derive(Debug)] pub struct PyBaseObject; -impl PyValue for PyBaseObject { +impl PyPayload for PyBaseObject { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.object_type } diff --git a/vm/src/builtins/property.rs b/vm/src/builtins/property.rs index 1353e7f2e6..9248824884 100644 --- a/vm/src/builtins/property.rs +++ b/vm/src/builtins/property.rs @@ -5,7 +5,7 @@ use super::PyTypeRef; use crate::common::lock::PyRwLock; use crate::{ function::FuncArgs, pyclass::PyClassImpl, types::GetDescriptor, AsObject, PyContext, - PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; /// Property attribute. @@ -49,7 +49,7 @@ pub struct PyProperty { doc: PyRwLock>, } -impl PyValue for PyProperty { +impl PyPayload for PyProperty { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.property_type } diff --git a/vm/src/builtins/pybool.rs b/vm/src/builtins/pybool.rs index d522b415ce..c678a5298c 100644 --- a/vm/src/builtins/pybool.rs +++ b/vm/src/builtins/pybool.rs @@ -1,7 +1,7 @@ use super::{PyInt, PyStrRef, PyTypeRef}; use crate::{ convert::ToPyObject, function::OptionalArg, pyclass::PyClassImpl, types::Constructor, AsObject, - PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, VirtualMachine, + PyContext, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, }; use num_bigint::Sign; use num_traits::Zero; @@ -78,7 +78,7 @@ impl PyObjectRef { #[pyclass(name = "bool", module = false, base = "PyInt")] pub struct PyBool; -impl PyValue for PyBool { +impl PyPayload for PyBool { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.bool_type } diff --git a/vm/src/builtins/pystr.rs b/vm/src/builtins/pystr.rs index 1c9d0303f9..3d6bbf02f7 100644 --- a/vm/src/builtins/pystr.rs +++ b/vm/src/builtins/pystr.rs @@ -16,7 +16,7 @@ use crate::{ AsMapping, AsSequence, Comparable, Constructor, Hashable, IterNext, IterNextIterable, Iterable, PyComparisonOp, Unconstructible, }, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, VirtualMachine, }; use ascii::{AsciiStr, AsciiString}; @@ -227,7 +227,7 @@ pub struct PyStrIterator { internal: PyMutex<(PositionIterInternal, usize)>, } -impl PyValue for PyStrIterator { +impl PyPayload for PyStrIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.str_iterator_type } @@ -261,7 +261,7 @@ impl Unconstructible for PyStrIterator {} impl IterNextIterable for PyStrIterator {} impl IterNext for PyStrIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let mut internal = zelf.internal.lock(); if let IterStatus::Active(s) = &internal.0.status { @@ -1245,14 +1245,14 @@ impl PyStrRef { impl Hashable for PyStr { #[inline] - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { Ok(zelf.hash(vm)) } } impl Comparable for PyStr { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, _vm: &VirtualMachine, @@ -1275,7 +1275,7 @@ impl Iterable for PyStr { } impl AsMapping for PyStr { - fn as_mapping(_zelf: &PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } @@ -1290,7 +1290,7 @@ impl PyStr { impl AsSequence for PyStr { fn as_sequence( - _zelf: &PyObjectView, + _zelf: &Py, _vm: &VirtualMachine, ) -> std::borrow::Cow<'static, PySequenceMethods> { std::borrow::Cow::Borrowed(&Self::SEQUENCE_METHDOS) @@ -1338,7 +1338,7 @@ pub(crate) fn encode_string( vm.state.codec_registry.encode_text(s, encoding, errors, vm) } -impl PyValue for PyStr { +impl PyPayload for PyStr { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.str_type } diff --git a/vm/src/builtins/pysuper.rs b/vm/src/builtins/pysuper.rs index ad7709c005..7a729a276d 100644 --- a/vm/src/builtins/pysuper.rs +++ b/vm/src/builtins/pysuper.rs @@ -8,7 +8,7 @@ use crate::{ function::OptionalArg, pyclass::PyClassImpl, types::{Constructor, GetAttr, GetDescriptor}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "super")] @@ -18,7 +18,7 @@ pub struct PySuper { obj: Option<(PyObjectRef, PyTypeRef)>, } -impl PyValue for PySuper { +impl PyPayload for PySuper { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.super_type } diff --git a/vm/src/builtins/pytype.rs b/vm/src/builtins/pytype.rs index b99c4fd364..ec3a6892a0 100644 --- a/vm/src/builtins/pytype.rs +++ b/vm/src/builtins/pytype.rs @@ -1,6 +1,6 @@ use super::{ mappingproxy::PyMappingProxy, object, pyunion, PyClassMethod, PyDictRef, PyList, - PyStaticMethod, PyStr, PyStrRef, PyTuple, PyTupleRef, + PyStaticMethod, PyStr, PyStrRef, PyTuple, PyTupleRef, PyWeak, }; use crate::common::{ ascii, @@ -11,7 +11,7 @@ use crate::{ function::{FuncArgs, KwArgs, OptionalArg}, pyclass::{PyClassImpl, StaticType}, types::{Callable, GetAttr, PyTypeFlags, PyTypeSlots, SetAttr}, - AsObject, PyContext, PyObjectRef, PyObjectWeak, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use itertools::Itertools; use std::{ @@ -29,7 +29,7 @@ pub struct PyType { pub base: Option, pub bases: Vec, pub mro: Vec, - pub subclasses: PyRwLock>, + pub subclasses: PyRwLock>>, pub attributes: PyRwLock, pub slots: PyTypeSlots, } @@ -53,7 +53,7 @@ impl fmt::Debug for PyType { } } -impl PyValue for PyType { +impl PyPayload for PyType { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.type_type } @@ -680,7 +680,7 @@ impl GetAttr for PyType { impl SetAttr for PyType { fn setattro( - zelf: &crate::PyObjectView, + zelf: &crate::Py, attr_name: PyStrRef, value: Option, vm: &VirtualMachine, @@ -715,7 +715,7 @@ impl SetAttr for PyType { impl Callable for PyType { type Args = FuncArgs; - fn call(zelf: &crate::PyObjectView, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &crate::Py, args: FuncArgs, vm: &VirtualMachine) -> PyResult { vm_trace!("type_call: {:?}", zelf); let obj = call_slot_new(zelf.to_owned(), zelf.to_owned(), args.clone(), vm)?; diff --git a/vm/src/builtins/pyunion.rs b/vm/src/builtins/pyunion.rs index 49390418bb..f60d7ebbfe 100644 --- a/vm/src/builtins/pyunion.rs +++ b/vm/src/builtins/pyunion.rs @@ -7,8 +7,8 @@ use crate::{ protocol::PyMappingMethods, pyclass::PyClassImpl, types::{AsMapping, Comparable, GetAttr, Hashable, Iterable, PyComparisonOp}, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, - TryFromObject, VirtualMachine, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, }; use std::fmt; @@ -26,7 +26,7 @@ impl fmt::Debug for PyUnion { } } -impl PyValue for PyUnion { +impl PyPayload for PyUnion { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.union_type } @@ -232,14 +232,14 @@ impl PyUnion { } impl AsMapping for PyUnion { - fn as_mapping(_zelf: &PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl Comparable for PyUnion { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -256,7 +256,7 @@ impl Comparable for PyUnion { impl Hashable for PyUnion { #[inline] - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let it = PyTuple::iter(zelf.args.clone(), vm); let set = PyFrozenSet::from_iter(vm, it)?; PyFrozenSet::hash(&set.into_ref(vm), vm) diff --git a/vm/src/builtins/range.rs b/vm/src/builtins/range.rs index d6a4161527..4c170e888b 100644 --- a/vm/src/builtins/range.rs +++ b/vm/src/builtins/range.rs @@ -9,8 +9,8 @@ use crate::{ AsMapping, AsSequence, Comparable, Constructor, Hashable, IterNext, IterNextIterable, Iterable, PyComparisonOp, Unconstructible, }, - AsObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, - TryFromObject, VirtualMachine, + AsObject, Py, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use num_bigint::{BigInt, Sign}; @@ -74,7 +74,7 @@ pub struct PyRange { pub step: PyIntRef, } -impl PyValue for PyRange { +impl PyPayload for PyRange { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.range_type } @@ -414,14 +414,14 @@ impl PyRange { } impl AsMapping for PyRange { - fn as_mapping(_zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &crate::Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl AsSequence for PyRange { fn as_sequence( - _zelf: &crate::PyObjectView, + _zelf: &crate::Py, _vm: &VirtualMachine, ) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHDOS) @@ -429,7 +429,7 @@ impl AsSequence for PyRange { } impl Hashable for PyRange { - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let length = zelf.compute_length(); let elements = if length.is_zero() { [vm.ctx.new_int(length).into(), vm.ctx.none(), vm.ctx.none()] @@ -452,7 +452,7 @@ impl Hashable for PyRange { impl Comparable for PyRange { fn cmp( - zelf: &PyObjectView, + zelf: &Py, other: &PyObject, op: PyComparisonOp, _vm: &VirtualMachine, @@ -528,7 +528,7 @@ pub struct PyLongRangeIterator { length: BigInt, } -impl PyValue for PyLongRangeIterator { +impl PyPayload for PyLongRangeIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.longrange_iterator_type } @@ -567,7 +567,7 @@ impl Unconstructible for PyLongRangeIterator {} impl IterNextIterable for PyLongRangeIterator {} impl IterNext for PyLongRangeIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { // TODO: In pathological case (index == usize::MAX) this can wrap around // (since fetch_add wraps). This would result in the iterator spinning again // from the beginning. @@ -593,7 +593,7 @@ pub struct PyRangeIterator { length: usize, } -impl PyValue for PyRangeIterator { +impl PyPayload for PyRangeIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.range_iterator_type } @@ -633,7 +633,7 @@ impl Unconstructible for PyRangeIterator {} impl IterNextIterable for PyRangeIterator {} impl IterNext for PyRangeIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { // TODO: In pathological case (index == usize::MAX) this can wrap around // (since fetch_add wraps). This would result in the iterator spinning again // from the beginning. diff --git a/vm/src/builtins/set.rs b/vm/src/builtins/set.rs index 233f937662..002c20f06a 100644 --- a/vm/src/builtins/set.rs +++ b/vm/src/builtins/set.rs @@ -17,7 +17,7 @@ use crate::{ }, utils::collection_repr, vm::{ReprGuard, VirtualMachine}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; use std::borrow::Cow; use std::{fmt, ops::Deref}; @@ -70,13 +70,13 @@ impl fmt::Debug for PyFrozenSet { } } -impl PyValue for PySet { +impl PyPayload for PySet { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.set_type } } -impl PyValue for PyFrozenSet { +impl PyPayload for PyFrozenSet { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.frozenset_type } @@ -656,7 +656,7 @@ impl PySet { impl AsSequence for PySet { fn as_sequence( - _zelf: &crate::PyObjectView, + _zelf: &crate::Py, _vm: &VirtualMachine, ) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) @@ -673,7 +673,7 @@ impl PySet { impl Comparable for PySet { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -896,7 +896,7 @@ impl PyFrozenSet { impl AsSequence for PyFrozenSet { fn as_sequence( - _zelf: &crate::PyObjectView, + _zelf: &crate::Py, _vm: &VirtualMachine, ) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHODS) @@ -913,14 +913,14 @@ impl PyFrozenSet { impl Hashable for PyFrozenSet { #[inline] - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { zelf.inner.hash(vm) } } impl Comparable for PyFrozenSet { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -971,7 +971,7 @@ impl fmt::Debug for PySetIterator { } } -impl PyValue for PySetIterator { +impl PyPayload for PySetIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.set_iterator_type } @@ -1004,7 +1004,7 @@ impl Unconstructible for PySetIterator {} impl IterNextIterable for PySetIterator {} impl IterNext for PySetIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let mut internal = zelf.internal.lock(); let next = if let IterStatus::Active(dict) = &internal.status { if dict.has_changed_size(&zelf.size) { diff --git a/vm/src/builtins/singletons.rs b/vm/src/builtins/singletons.rs index 131d6a740e..165a28c0d3 100644 --- a/vm/src/builtins/singletons.rs +++ b/vm/src/builtins/singletons.rs @@ -1,14 +1,14 @@ use super::PyTypeRef; use crate::{ convert::ToPyObject, pyclass::PyClassImpl, types::Constructor, AsObject, PyContext, - PyObjectRef, PyResult, PyValue, VirtualMachine, + PyObjectRef, PyPayload, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "NoneType")] #[derive(Debug)] pub struct PyNone; -impl PyValue for PyNone { +impl PyPayload for PyNone { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.none_type } @@ -56,7 +56,7 @@ impl PyNone { #[derive(Debug)] pub struct PyNotImplemented; -impl PyValue for PyNotImplemented { +impl PyPayload for PyNotImplemented { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.not_implemented_type } diff --git a/vm/src/builtins/slice.rs b/vm/src/builtins/slice.rs index 3ba125053d..e8cff62469 100644 --- a/vm/src/builtins/slice.rs +++ b/vm/src/builtins/slice.rs @@ -5,7 +5,7 @@ use crate::{ function::{FuncArgs, OptionalArg, PyComparisonValue}, pyclass::PyClassImpl, types::{Comparable, Constructor, Hashable, PyComparisonOp, Unhashable}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use num_bigint::{BigInt, ToBigInt}; use num_traits::{One, Signed, ToPrimitive, Zero}; @@ -20,7 +20,7 @@ pub struct PySlice { pub step: Option, } -impl PyValue for PySlice { +impl PyPayload for PySlice { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.slice_type } @@ -213,7 +213,7 @@ impl PySlice { impl Comparable for PySlice { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -423,7 +423,7 @@ pub fn saturate_index(p: isize, len: usize) -> usize { #[derive(Debug)] pub struct PyEllipsis; -impl PyValue for PyEllipsis { +impl PyPayload for PyEllipsis { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.ellipsis_type } diff --git a/vm/src/builtins/staticmethod.rs b/vm/src/builtins/staticmethod.rs index f16d807b0e..63c862458b 100644 --- a/vm/src/builtins/staticmethod.rs +++ b/vm/src/builtins/staticmethod.rs @@ -4,7 +4,7 @@ use crate::{ function::{FuncArgs, IntoPyNativeFunc}, pyclass::PyClassImpl, types::{Callable, Constructor, GetDescriptor}, - PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "staticmethod")] @@ -13,7 +13,7 @@ pub struct PyStaticMethod { pub callable: PyObjectRef, } -impl PyValue for PyStaticMethod { +impl PyPayload for PyStaticMethod { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.staticmethod_type } @@ -80,7 +80,7 @@ impl PyStaticMethod { impl Callable for PyStaticMethod { type Args = FuncArgs; #[inline] - fn call(zelf: &crate::PyObjectView, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &crate::Py, args: FuncArgs, vm: &VirtualMachine) -> PyResult { vm.invoke(&zelf.callable, args) } } diff --git a/vm/src/builtins/traceback.rs b/vm/src/builtins/traceback.rs index 0b14a58bfe..af8cad619a 100644 --- a/vm/src/builtins/traceback.rs +++ b/vm/src/builtins/traceback.rs @@ -1,5 +1,5 @@ use super::PyTypeRef; -use crate::{frame::FrameRef, pyclass::PyClassImpl, PyContext, PyRef, PyValue, VirtualMachine}; +use crate::{frame::FrameRef, pyclass::PyClassImpl, PyContext, PyPayload, PyRef, VirtualMachine}; #[pyclass(module = false, name = "traceback")] #[derive(Debug)] @@ -12,7 +12,7 @@ pub struct PyTraceback { pub type PyTracebackRef = PyRef; -impl PyValue for PyTraceback { +impl PyPayload for PyTraceback { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.traceback_type } diff --git a/vm/src/builtins/tuple.rs b/vm/src/builtins/tuple.rs index c28320717e..09eee110ac 100644 --- a/vm/src/builtins/tuple.rs +++ b/vm/src/builtins/tuple.rs @@ -14,7 +14,7 @@ use crate::{ }, utils::collection_repr, vm::{ReprGuard, VirtualMachine}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; use std::{borrow::Cow, fmt, marker::PhantomData}; @@ -34,7 +34,7 @@ impl fmt::Debug for PyTuple { } } -impl PyValue for PyTuple { +impl PyPayload for PyTuple { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.tuple_type } @@ -322,14 +322,14 @@ impl PyTuple { } impl AsMapping for PyTuple { - fn as_mapping(_zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &crate::Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } impl AsSequence for PyTuple { fn as_sequence( - _zelf: &crate::PyObjectView, + _zelf: &crate::Py, _vm: &VirtualMachine, ) -> Cow<'static, PySequenceMethods> { Cow::Borrowed(&Self::SEQUENCE_METHDOS) @@ -367,14 +367,14 @@ impl PyTuple { impl Hashable for PyTuple { #[inline] - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { crate::utils::hash_iter(zelf.elements.iter(), vm) } } impl Comparable for PyTuple { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -404,7 +404,7 @@ pub(crate) struct PyTupleIterator { internal: PyMutex>, } -impl PyValue for PyTupleIterator { +impl PyPayload for PyTupleIterator { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.tuple_iterator_type } @@ -435,7 +435,7 @@ impl Unconstructible for PyTupleIterator {} impl IterNextIterable for PyTupleIterator {} impl IterNext for PyTupleIterator { - fn next(zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult { zelf.internal.lock().next(|tuple, pos| { Ok(PyIterReturn::from_result( tuple.as_slice().get(pos).cloned().ok_or(None), diff --git a/vm/src/builtins/weakproxy.rs b/vm/src/builtins/weakproxy.rs index 82243e606b..20ce591fa8 100644 --- a/vm/src/builtins/weakproxy.rs +++ b/vm/src/builtins/weakproxy.rs @@ -1,18 +1,18 @@ -use super::{PyStrRef, PyTypeRef}; +use super::{PyStrRef, PyTypeRef, PyWeak}; use crate::{ function::OptionalArg, pyclass::PyClassImpl, types::{Constructor, SetAttr}, - PyContext, PyObjectRef, PyObjectWeak, PyResult, PyValue, VirtualMachine, + PyContext, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "weakproxy")] #[derive(Debug)] pub struct PyWeakProxy { - weak: PyObjectWeak, + weak: PyRef, } -impl PyValue for PyWeakProxy { +impl PyPayload for PyWeakProxy { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.weakproxy_type } @@ -73,7 +73,7 @@ impl PyWeakProxy { impl SetAttr for PyWeakProxy { fn setattro( - zelf: &crate::PyObjectView, + zelf: &crate::Py, attr_name: PyStrRef, value: Option, vm: &VirtualMachine, diff --git a/vm/src/builtins/weakref.rs b/vm/src/builtins/weakref.rs index faef972c54..2990ffe687 100644 --- a/vm/src/builtins/weakref.rs +++ b/vm/src/builtins/weakref.rs @@ -7,7 +7,7 @@ use crate::{ function::OptionalArg, pyclass::PyClassImpl, types::{Callable, Comparable, Constructor, Hashable, PyComparisonOp}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; pub use crate::pyobject::PyWeak; @@ -20,7 +20,7 @@ pub struct WeakNewArgs { callback: OptionalArg, } -impl PyValue for PyWeak { +impl PyPayload for PyWeak { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.weakref_type } @@ -29,7 +29,7 @@ impl PyValue for PyWeak { impl Callable for PyWeak { type Args = (); #[inline] - fn call(zelf: &crate::PyObjectView, _: Self::Args, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &crate::Py, _: Self::Args, vm: &VirtualMachine) -> PyResult { Ok(vm.unwrap_or_none(zelf.upgrade())) } } @@ -43,8 +43,7 @@ impl Constructor for PyWeak { vm: &VirtualMachine, ) -> PyResult { let weak = referent.downgrade_with_typ(callback.into_option(), cls, vm)?; - let pyref_weak: PyRef = weak.into(); - Ok(pyref_weak.into()) + Ok(weak.into()) } } @@ -72,7 +71,7 @@ impl PyWeak { } impl Hashable for PyWeak { - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let hash = match zelf.hash.load(Ordering::Relaxed) { hash::SENTINEL => { let obj = zelf @@ -98,7 +97,7 @@ impl Hashable for PyWeak { impl Comparable for PyWeak { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, diff --git a/vm/src/builtins/zip.rs b/vm/src/builtins/zip.rs index fa63cbbb72..73e60f9229 100644 --- a/vm/src/builtins/zip.rs +++ b/vm/src/builtins/zip.rs @@ -5,7 +5,7 @@ use crate::{ protocol::{PyIter, PyIterReturn}, pyclass::PyClassImpl, types::{Constructor, IterNext, IterNextIterable}, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use rustpython_common::atomic::{self, PyAtomic, Radium}; @@ -16,7 +16,7 @@ pub struct PyZip { strict: PyAtomic, } -impl PyValue for PyZip { +impl PyPayload for PyZip { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.zip_type } @@ -67,7 +67,7 @@ impl PyZip { impl IterNextIterable for PyZip {} impl IterNext for PyZip { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { if zelf.iterators.is_empty() { return Ok(PyIterReturn::StopIteration(None)); } diff --git a/vm/src/bytesinner.rs b/vm/src/bytesinner.rs index 90d99ee04a..93a6e6dce9 100644 --- a/vm/src/bytesinner.rs +++ b/vm/src/bytesinner.rs @@ -9,7 +9,7 @@ use crate::{ sequence::{SequenceMutOp, SequenceOp}, types::PyComparisonOp, utils::Either, - AsObject, PyObject, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, }; use bstr::ByteSlice; use itertools::Itertools; diff --git a/vm/src/codecs.rs b/vm/src/codecs.rs index 3794d0934a..7f367731a5 100644 --- a/vm/src/codecs.rs +++ b/vm/src/codecs.rs @@ -2,7 +2,7 @@ use crate::{ builtins::{PyBaseExceptionRef, PyBytesRef, PyStr, PyStrRef, PyTuple, PyTupleRef}, common::{ascii, lock::PyRwLock}, convert::ToPyObject, - AsObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use std::{borrow::Cow, collections::HashMap, fmt::Write, ops::Range}; diff --git a/vm/src/convert/transmute_from.rs b/vm/src/convert/transmute_from.rs index 94e0759393..1c112b61b7 100644 --- a/vm/src/convert/transmute_from.rs +++ b/vm/src/convert/transmute_from.rs @@ -1,5 +1,5 @@ use crate::{ - pyobject::{AsObject, PyObject, PyRef, PyResult, PyValue}, + pyobject::{AsObject, PyObject, PyPayload, PyRef, PyResult}, vm::VirtualMachine, }; @@ -13,7 +13,7 @@ pub unsafe trait TransmuteFromObject: Sized { fn check(vm: &VirtualMachine, obj: &PyObject) -> PyResult<()>; } -unsafe impl TransmuteFromObject for PyRef { +unsafe impl TransmuteFromObject for PyRef { fn check(vm: &VirtualMachine, obj: &PyObject) -> PyResult<()> { let class = T::class(vm); if obj.fast_isinstance(class) { diff --git a/vm/src/convert/try_from.rs b/vm/src/convert/try_from.rs index 6fd30b3a6a..7489cb0934 100644 --- a/vm/src/convert/try_from.rs +++ b/vm/src/convert/try_from.rs @@ -1,5 +1,5 @@ use crate::{ - pyobject::{AsObject, PyObject, PyObjectRef, PyRef, PyResult, PyValue}, + pyobject::{AsObject, PyObject, PyObjectRef, PyPayload, PyRef, PyResult}, vm::VirtualMachine, }; @@ -38,7 +38,7 @@ impl PyObject { pub fn try_value_with(&self, f: F, vm: &VirtualMachine) -> PyResult where - T: PyValue, + T: PyPayload, F: Fn(&T) -> PyResult, { let class = T::class(vm); @@ -63,7 +63,7 @@ pub trait TryFromBorrowedObject: Sized { impl TryFromObject for PyRef where - T: PyValue, + T: PyPayload, { #[inline] fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult { diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index ae7faa7ab1..8c5a81e4f4 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -10,7 +10,7 @@ use crate::{ pyclass::{PyClassImpl, StaticType}, stdlib::sys, suggestion::offer_suggestions, - AsObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyContext, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; @@ -27,7 +27,7 @@ impl std::fmt::Debug for PyBaseException { } } -impl PyValue for PyBaseException { +impl PyPayload for PyBaseException { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.exceptions.base_exception_type } diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 99ad67c7d4..16a6e28913 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -16,7 +16,7 @@ use crate::{ scope::Scope, stdlib::builtins, types::PyComparisonOp, - AsObject, PyMethod, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, + AsObject, PyMethod, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use indexmap::IndexMap; @@ -113,7 +113,7 @@ pub struct Frame { state: PyMutex, } -impl PyValue for Frame { +impl PyPayload for Frame { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.frame_type } diff --git a/vm/src/function/argument.rs b/vm/src/function/argument.rs index b1ebe11552..928445c91a 100644 --- a/vm/src/function/argument.rs +++ b/vm/src/function/argument.rs @@ -1,7 +1,7 @@ use crate::{ builtins::{PyBaseExceptionRef, PyTupleRef, PyTypeRef}, convert::ToPyObject, - AsObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use indexmap::IndexMap; use itertools::Itertools; @@ -406,7 +406,7 @@ impl AsRef<[T]> for PosArgs { } } -impl PosArgs> { +impl PosArgs> { pub fn into_tuple(self, vm: &VirtualMachine) -> PyTupleRef { vm.ctx .new_tuple(self.0.into_iter().map(Into::into).collect()) diff --git a/vm/src/function/builtin.rs b/vm/src/function/builtin.rs index 2ef026fbf4..761c6faa1a 100644 --- a/vm/src/function/builtin.rs +++ b/vm/src/function/builtin.rs @@ -1,6 +1,7 @@ use super::{FromArgs, FuncArgs}; use crate::{ - convert::ToPyResult, pyobject::PyThreadingConstraint, PyRef, PyResult, PyValue, VirtualMachine, + convert::ToPyResult, pyobject::PyThreadingConstraint, PyPayload, PyRef, PyResult, + VirtualMachine, }; use std::marker::PhantomData; @@ -83,7 +84,7 @@ macro_rules! into_py_native_func_tuple { impl PyNativeFuncInternal<(RefParam, $(OwnedParam<$T>,)*), R, VirtualMachine> for F where F: Fn(&S, $($T,)* &VirtualMachine) -> R + PyThreadingConstraint + 'static, - S: PyValue, + S: PyPayload, $($T: FromArgs,)* R: ToPyResult, { @@ -110,7 +111,7 @@ macro_rules! into_py_native_func_tuple { impl PyNativeFuncInternal<(RefParam, $(OwnedParam<$T>,)*), R, ()> for F where F: Fn(&S, $($T,)*) -> R + PyThreadingConstraint + 'static, - S: PyValue, + S: PyPayload, $($T: FromArgs,)* R: ToPyResult, { diff --git a/vm/src/function/protocol.rs b/vm/src/function/protocol.rs index 2a4b5743ee..c7468b9ed7 100644 --- a/vm/src/function/protocol.rs +++ b/vm/src/function/protocol.rs @@ -3,7 +3,7 @@ use crate::{ builtins::{iter::PySequenceIterator, PyDict, PyDictRef}, convert::ToPyObject, protocol::{PyIter, PyIterIter, PyMapping, PyMappingMethods}, - AsObject, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use std::{borrow::Borrow, marker::PhantomData}; diff --git a/vm/src/import.rs b/vm/src/import.rs index 0b753d6916..97fae2b359 100644 --- a/vm/src/import.rs +++ b/vm/src/import.rs @@ -8,7 +8,7 @@ use crate::{ scope::Scope, version::get_git_revision, vm::{InitParameter, VirtualMachine}, - AsObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; use rand::Rng; diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 8fbdaa6235..e185fd3d01 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -88,9 +88,9 @@ mod pyobject { // pub use self::Executor; pub use self::convert::{TryFromBorrowedObject, TryFromObject}; // pyobject items -pub use self::pyobject::{AsObject, PyContext, PyMethod, PyRefExact, PyResult, PyValue}; +pub use self::pyobject::{AsObject, PyContext, PyMethod, PyPayload, PyRefExact, PyResult}; // pyobjectrc items -pub use self::pyobject::{PyObject, PyObjectRef, PyObjectView, PyObjectWeak, PyRef, PyWeakRef}; +pub use self::pyobject::{Py, PyObject, PyObjectRef, PyRef, PyWeakRef}; pub use self::types::PyStructSequence; pub use self::vm::{InitParameter, Interpreter, PySettings, VirtualMachine}; diff --git a/vm/src/macros.rs b/vm/src/macros.rs index 99e691481a..72ffda9fe4 100644 --- a/vm/src/macros.rs +++ b/vm/src/macros.rs @@ -69,7 +69,7 @@ macro_rules! py_namespace { /// /// use rustpython_vm::match_class; /// use rustpython_vm::builtins::{PyFloat, PyInt}; -/// use rustpython_vm::{PyValue}; +/// use rustpython_vm::{PyPayload}; /// /// # rustpython_vm::Interpreter::default().enter(|vm| { /// let obj = PyInt::from(0).into_pyobject(vm); @@ -93,7 +93,7 @@ macro_rules! py_namespace { /// /// use rustpython_vm::match_class; /// use rustpython_vm::builtins::{PyFloat, PyInt}; -/// use rustpython_vm::{ PyValue}; +/// use rustpython_vm::{ PyPayload}; /// /// # rustpython_vm::Interpreter::default().enter(|vm| { /// let obj = PyInt::from(0).into_pyobject(vm); diff --git a/vm/src/protocol/buffer.rs b/vm/src/protocol/buffer.rs index 5040a03e10..4a6bd8afb5 100644 --- a/vm/src/protocol/buffer.rs +++ b/vm/src/protocol/buffer.rs @@ -9,7 +9,7 @@ use crate::{ pyobject::PyObjectPayload, sliceable::wrap_index, types::{Constructor, Unconstructible}, - AsObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, TryFromBorrowedObject, + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, VirtualMachine, }; use itertools::Itertools; @@ -65,7 +65,7 @@ impl PyBuffer { pub fn from_byte_vector(bytes: Vec, vm: &VirtualMachine) -> Self { let bytes_len = bytes.len(); PyBuffer::new( - PyValue::into_pyobject(VecBuffer::from(bytes), vm), + PyPayload::into_pyobject(VecBuffer::from(bytes), vm), BufferDescriptor::simple(bytes_len, true), &VEC_BUFFER_METHODS, ) @@ -108,7 +108,7 @@ impl PyBuffer { f(v) } - pub fn obj_as(&self) -> &PyObjectView { + pub fn obj_as(&self) -> &Py { unsafe { self.obj.downcast_unchecked_ref() } } @@ -395,7 +395,7 @@ pub trait BufferResizeGuard<'a> { } #[pyclass(module = false, name = "vec_buffer")] -#[derive(Debug, PyValue)] +#[derive(Debug, PyPayload)] pub struct VecBuffer { data: PyMutex>, } diff --git a/vm/src/protocol/iter.rs b/vm/src/protocol/iter.rs index 5f137aabde..deef0c37ea 100644 --- a/vm/src/protocol/iter.rs +++ b/vm/src/protocol/iter.rs @@ -1,7 +1,7 @@ use crate::{ builtins::iter::PySequenceIterator, convert::{ToPyObject, ToPyResult}, - AsObject, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use std::borrow::Borrow; use std::ops::Deref; diff --git a/vm/src/protocol/sequence.rs b/vm/src/protocol/sequence.rs index d48b86f815..e0b20c468a 100644 --- a/vm/src/protocol/sequence.rs +++ b/vm/src/protocol/sequence.rs @@ -4,7 +4,7 @@ use crate::{ convert::ToPyObject, function::PyArithmeticValue, protocol::PyMapping, - AsObject, PyObject, PyObjectRef, PyResult, PyValue, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use itertools::Itertools; use std::{ diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 0385283b14..583e86fc00 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -18,7 +18,7 @@ use crate::{ pyclass::{PyClassImpl, StaticType}, types::{PyTypeFlags, PyTypeSlots, TypeZoo}, VirtualMachine, - _pyobjectrc::{PyObject, PyObjectRef, PyObjectView, PyRef}, + _pyobjectrc::{Py, PyObject, PyObjectRef, PyRef}, }; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -84,7 +84,7 @@ impl PyContext { let exceptions = exceptions::ExceptionZoo::init(); #[inline] - fn create_object(payload: T, cls: &PyTypeRef) -> PyRef { + fn create_object(payload: T, cls: &PyTypeRef) -> PyRef { PyRef::new_ref(payload, cls.clone(), None) } @@ -347,7 +347,7 @@ where fmt::Display::fmt(&**self, f) } } -impl fmt::Display for PyObjectView +impl fmt::Display for Py where T: PyObjectPayload + fmt::Display, { @@ -359,7 +359,7 @@ where pub struct PyRefExact { obj: PyRef, } -impl TryFromObject for PyRefExact { +impl TryFromObject for PyRefExact { fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult { let target_cls = T::class(vm); let cls = obj.class(); @@ -384,14 +384,14 @@ impl TryFromObject for PyRefExact { } } } -impl Deref for PyRefExact { +impl Deref for PyRefExact { type Target = PyRef; #[inline(always)] fn deref(&self) -> &PyRef { &self.obj } } -impl ToPyObject for PyRefExact { +impl ToPyObject for PyRefExact { #[inline(always)] fn to_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef { self.obj.into() @@ -432,7 +432,7 @@ where /// Determines if `obj` actually an instance of `cls`, this doesn't call __instancecheck__, so only /// use this if `cls` is known to have not overridden the base __instancecheck__ magic method. #[inline] - fn fast_isinstance(&self, cls: &PyObjectView) -> bool { + fn fast_isinstance(&self, cls: &Py) -> bool { self.class().fast_issubclass(cls) } } @@ -466,21 +466,21 @@ pub struct PyLease<'a, T: PyObjectPayload> { inner: PyRwLockReadGuard<'a, PyRef>, } -impl<'a, T: PyObjectPayload + PyValue> PyLease<'a, T> { +impl<'a, T: PyObjectPayload + PyPayload> PyLease<'a, T> { #[inline(always)] pub fn into_owned(self) -> PyRef { self.inner.clone() } } -impl<'a, T: PyObjectPayload + PyValue> Borrow for PyLease<'a, T> { +impl<'a, T: PyObjectPayload + PyPayload> Borrow for PyLease<'a, T> { #[inline(always)] fn borrow(&self) -> &PyObject { self.inner.as_ref() } } -impl<'a, T: PyObjectPayload + PyValue> Deref for PyLease<'a, T> { +impl<'a, T: PyObjectPayload + PyPayload> Deref for PyLease<'a, T> { type Target = PyRef; #[inline(always)] fn deref(&self) -> &Self::Target { @@ -490,7 +490,7 @@ impl<'a, T: PyObjectPayload + PyValue> Deref for PyLease<'a, T> { impl<'a, T> fmt::Display for PyLease<'a, T> where - T: PyValue + fmt::Display, + T: PyPayload + fmt::Display, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&**self, f) @@ -522,11 +522,11 @@ impl ToPyObject for &PyObject { // explicitly implementing `ToPyObject`. impl ToPyObject for T where - T: PyValue + Sized, + T: PyPayload + Sized, { #[inline(always)] fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef { - PyValue::into_pyobject(self, vm) + PyPayload::into_pyobject(self, vm) } } @@ -560,7 +560,7 @@ cfg_if::cfg_if! { } } -pub trait PyValue: fmt::Debug + PyThreadingConstraint + Sized + 'static { +pub trait PyPayload: fmt::Debug + PyThreadingConstraint + Sized + 'static { fn class(vm: &VirtualMachine) -> &PyTypeRef; #[inline] @@ -620,7 +620,7 @@ pub trait PyValue: fmt::Debug + PyThreadingConstraint + Sized + 'static { pub trait PyObjectPayload: Any + fmt::Debug + PyThreadingConstraint + 'static {} -impl PyObjectPayload for T {} +impl PyObjectPayload for T {} pub trait PyObjectWrap where diff --git a/vm/src/pyobjectrc.rs b/vm/src/pyobjectrc.rs index fbdbc784f4..f1dc2b62f9 100644 --- a/vm/src/pyobjectrc.rs +++ b/vm/src/pyobjectrc.rs @@ -1,3 +1,16 @@ +//! Essential types for object models +//! +//! +-------------------------+--------------+---------------+ +//! | Management | Typed | Untyped | +//! +-------------------------+--------------+---------------+ +//! | Interpreter-independent | Py | PyObject | +//! | Reference-counted | PyRef | PyObjectRef | +//! | Weak | PyWeakRef | PyRef | +//! +-------------------------+--------------+---------------+ +//! +//! PyRef may looking like to be called as PyObjectWeak by the rule, +//! but not to do to remember it is a PyRef object. + use crate::common::atomic::{OncePtr, PyAtomic, Radium}; use crate::common::linked_list::{Link, LinkedList, Pointers}; use crate::common::lock::{PyMutex, PyMutexGuard, PyRwLock}; @@ -114,8 +127,8 @@ impl fmt::Debug for WeakRefList { } struct WeakListInner { - list: LinkedList>, - generic_weakref: Option>>, + list: LinkedList>, + generic_weakref: Option>>, obj: Option>, // one for each live PyWeak with a reference to this, + 1 for the referent object if it's not dead ref_count: usize, @@ -147,7 +160,7 @@ impl WeakRefList { cls_is_weakref: bool, callback: Option, dict: Option, - ) -> PyObjectWeak { + ) -> PyRef { let is_generic = cls_is_weakref && callback.is_none(); let inner_ptr = self.inner.get_or_init(|| { Box::new(PyMutex::new(WeakListInner { @@ -162,9 +175,7 @@ impl WeakRefList { if let Some(generic_weakref) = inner.generic_weakref { let generic_weakref = unsafe { generic_weakref.as_ref() }; if generic_weakref.0.ref_count.get() != 0 { - return PyObjectWeak { - weak: generic_weakref.to_owned(), - }; + return generic_weakref.to_owned(); } } } @@ -182,7 +193,7 @@ impl WeakRefList { if is_generic { inner.generic_weakref = Some(NonNull::from(&*weak)); } - PyObjectWeak { weak } + weak } fn clear(&self) { @@ -252,21 +263,19 @@ impl WeakRefList { Box::from_raw(ptr.as_ptr()); } - fn get_weak_references(&self) -> Vec { + fn get_weak_references(&self) -> Vec> { let inner = match self.try_lock() { Some(inner) => inner, None => return vec![], }; let mut v = Vec::with_capacity(inner.ref_count - 1); - v.extend(inner.iter().map(|wr| PyObjectWeak { - weak: wr.to_owned(), - })); + v.extend(inner.iter().map(|wr| wr.to_owned())); v } } impl WeakListInner { - fn iter(&self) -> impl Iterator> { + fn iter(&self) -> impl Iterator> { self.list.iter().filter(|wr| wr.0.ref_count.get() > 0) } } @@ -281,7 +290,7 @@ struct WeakLink; unsafe impl Link for WeakLink { type Handle = PyRef; - type Target = PyObjectView; + type Target = Py; #[inline(always)] fn as_raw(handle: &PyRef) -> NonNull { @@ -302,7 +311,7 @@ unsafe impl Link for WeakLink { #[pyclass(name = "weakref", module = false)] #[derive(Debug)] pub struct PyWeak { - pointers: Pointers>, + pointers: Pointers>, parent: NonNull>, // this is treated as part of parent's mutex - you must hold that lock to access it callback: UnsafeCell>, @@ -339,7 +348,7 @@ impl PyWeak { let mut guard = unsafe { self.parent.as_ref().lock() }; let offset = memoffset::offset_of!(PyInner, payload); let pyinner = (self as *const Self as usize - offset) as *const PyInner; - let node_ptr = unsafe { NonNull::new_unchecked(pyinner as *mut PyObjectView) }; + let node_ptr = unsafe { NonNull::new_unchecked(pyinner as *mut Py) }; // the list doesn't have ownership over its PyRef! we're being dropped // right now so that should be obvious!! std::mem::forget(unsafe { guard.list.remove(node_ptr) }); @@ -365,6 +374,13 @@ impl Drop for PyWeak { } } +impl PyRef { + #[inline(always)] + pub fn upgrade(&self) -> Option { + PyWeak::upgrade(self) + } +} + #[derive(Debug)] struct InstanceDict { d: PyRwLock, @@ -439,12 +455,6 @@ cfg_if::cfg_if! { } } -#[derive(Clone)] -#[repr(transparent)] -pub struct PyObjectWeak { - weak: PyRef, -} - #[repr(transparent)] pub struct PyObject(PyInner); @@ -502,7 +512,7 @@ impl PyObjectRef { } #[inline(always)] - pub fn downcast_ref(&self) -> Option<&PyObjectView> { + pub fn downcast_ref(&self) -> Option<&Py> { if self.payload_is::() { // SAFETY: just checked that the payload is T, and PyRef is repr(transparent) over // PyObjectRef @@ -522,7 +532,7 @@ impl PyObjectRef { /// # Safety /// T must be the exact payload type #[inline(always)] - pub unsafe fn downcast_unchecked_ref(&self) -> &crate::PyObjectView { + pub unsafe fn downcast_unchecked_ref(&self) -> &crate::Py { debug_assert!(self.payload_is::()); &*(self as *const PyObjectRef as *const PyRef) } @@ -534,7 +544,7 @@ impl PyObjectRef { /// If the downcast fails, the original ref is returned in as `Err` so /// another downcast can be attempted without unnecessary cloning. #[inline] - pub fn downcast_exact( + pub fn downcast_exact( self, vm: &VirtualMachine, ) -> Result, Self> { @@ -563,7 +573,7 @@ impl PyObject { callback: Option, // a reference to weakref_type **specifically** typ: PyTypeRef, - ) -> Option { + ) -> Option> { self.weak_ref_list() .map(|wrl| wrl.add(self, typ, true, callback, None)) } @@ -573,7 +583,7 @@ impl PyObject { callback: Option, typ: PyTypeRef, vm: &VirtualMachine, - ) -> PyResult { + ) -> PyResult> { let dict = if typ .slots .flags @@ -598,11 +608,11 @@ impl PyObject { &self, callback: Option, vm: &VirtualMachine, - ) -> PyResult { + ) -> PyResult> { self.downgrade_with_typ(callback, vm.ctx.types.weakref_type.clone(), vm) } - pub fn get_weak_references(&self) -> Option> { + pub fn get_weak_references(&self) -> Option>> { self.weak_ref_list().map(|wrl| wrl.get_weak_references()) } @@ -629,7 +639,7 @@ impl PyObject { } #[inline(always)] - pub fn payload_if_exact( + pub fn payload_if_exact( &self, vm: &VirtualMachine, ) -> Option<&T> { @@ -663,7 +673,7 @@ impl PyObject { } #[inline(always)] - pub fn payload_if_subclass(&self, vm: &VirtualMachine) -> Option<&T> { + pub fn payload_if_subclass(&self, vm: &VirtualMachine) -> Option<&T> { if self.class().fast_issubclass(T::class(vm)) { self.payload() } else { @@ -672,7 +682,7 @@ impl PyObject { } #[inline(always)] - pub fn downcast_ref(&self) -> Option<&PyObjectView> { + pub fn downcast_ref(&self) -> Option<&Py> { if self.payload_is::() { // SAFETY: just checked that the payload is T, and PyRef is repr(transparent) over // PyObjectRef @@ -683,10 +693,10 @@ impl PyObject { } #[inline(always)] - pub fn downcast_ref_if_exact( + pub fn downcast_ref_if_exact( &self, vm: &VirtualMachine, - ) -> Option<&PyObjectView> { + ) -> Option<&Py> { self.class() .is(T::class(vm)) .then(|| unsafe { self.downcast_unchecked_ref::() }) @@ -695,9 +705,9 @@ impl PyObject { /// # Safety /// T must be the exact payload type #[inline(always)] - pub unsafe fn downcast_unchecked_ref(&self) -> &PyObjectView { + pub unsafe fn downcast_unchecked_ref(&self) -> &Py { debug_assert!(self.payload_is::()); - &*(self as *const PyObject as *const PyObjectView) + &*(self as *const PyObject as *const Py) } #[inline(always)] @@ -778,34 +788,13 @@ impl AsRef for PyObject { } } -impl<'a, T: PyObjectPayload> From<&'a PyObjectView> for &'a PyObject { +impl<'a, T: PyObjectPayload> From<&'a Py> for &'a PyObject { #[inline(always)] - fn from(py_ref: &'a PyObjectView) -> Self { + fn from(py_ref: &'a Py) -> Self { py_ref.as_object() } } -impl Borrow for PyObjectWeak { - #[inline(always)] - fn borrow(&self) -> &PyObject { - self.weak.as_object() - } -} - -impl From for PyRef { - #[inline(always)] - fn from(value: PyObjectWeak) -> Self { - value.weak - } -} - -impl PyObjectWeak { - #[inline(always)] - pub fn upgrade(&self) -> Option { - self.weak.upgrade() - } -} - impl Drop for PyObjectRef { #[inline] fn drop(&mut self) { @@ -843,16 +832,10 @@ impl fmt::Debug for PyObjectRef { } } -impl fmt::Debug for PyObjectWeak { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "(PyWeak)") - } -} - #[repr(transparent)] -pub struct PyObjectView(PyInner); +pub struct Py(PyInner); -impl PyObjectView { +impl Py { pub fn downgrade( &self, callback: Option, @@ -865,7 +848,7 @@ impl PyObjectView { } } -impl ToOwned for PyObjectView { +impl ToOwned for Py { type Owned = PyRef; #[inline(always)] @@ -877,7 +860,7 @@ impl ToOwned for PyObjectView { } } -impl Deref for PyObjectView { +impl Deref for Py { type Target = T; #[inline(always)] @@ -886,14 +869,14 @@ impl Deref for PyObjectView { } } -impl Borrow for PyObjectView { +impl Borrow for Py { #[inline(always)] fn borrow(&self) -> &PyObject { unsafe { &*(&self.0 as *const PyInner as *const PyObject) } } } -impl AsRef for PyObjectView +impl AsRef for Py where T: PyObjectPayload, { @@ -903,7 +886,7 @@ where } } -impl fmt::Debug for PyObjectView { +impl fmt::Debug for Py { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) } @@ -920,7 +903,7 @@ impl fmt::Debug for PyObjectView { /// where a reference to the same object must be returned. #[repr(transparent)] pub struct PyRef { - ptr: NonNull>, + ptr: NonNull>, } cfg_if::cfg_if! { @@ -954,7 +937,7 @@ impl Clone for PyRef { impl PyRef { #[inline(always)] - unsafe fn from_raw(raw: *const PyObjectView) -> Self { + unsafe fn from_raw(raw: *const Py) -> Self { Self { ptr: NonNull::new_unchecked(raw as *mut _), } @@ -974,7 +957,7 @@ impl PyRef { pub fn new_ref(payload: T, typ: crate::builtins::PyTypeRef, dict: Option) -> Self { let inner = Box::into_raw(PyInner::new(payload, typ, dict)); Self { - ptr: unsafe { NonNull::new_unchecked(inner.cast::>()) }, + ptr: unsafe { NonNull::new_unchecked(inner.cast::>()) }, } } } @@ -1010,12 +993,12 @@ where } } -impl Borrow> for PyRef +impl Borrow> for PyRef where T: PyObjectPayload, { #[inline(always)] - fn borrow(&self) -> &PyObjectView { + fn borrow(&self) -> &Py { self } } @@ -1024,17 +1007,17 @@ impl Deref for PyRef where T: PyObjectPayload, { - type Target = PyObjectView; + type Target = Py; #[inline(always)] - fn deref(&self) -> &PyObjectView { + fn deref(&self) -> &Py { unsafe { self.ptr.as_ref() } } } #[repr(transparent)] pub struct PyWeakRef { - weak: PyObjectWeak, + weak: PyRef, _marker: PhantomData, } diff --git a/vm/src/stdlib/ast.rs b/vm/src/stdlib/ast.rs index a6e4e7cd5f..3ab006511a 100644 --- a/vm/src/stdlib/ast.rs +++ b/vm/src/stdlib/ast.rs @@ -8,7 +8,7 @@ mod gen; use crate::{ builtins::{self, PyStrRef, PyTypeRef}, pyclass::{PyClassImpl, StaticType}, - AsObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use num_complex::Complex64; use num_traits::{ToPrimitive, Zero}; @@ -21,12 +21,12 @@ use rustpython_parser::parser; #[pymodule] mod _ast { use crate::{ - builtins::PyStrRef, function::FuncArgs, AsObject, PyObjectRef, PyResult, PyValue, + builtins::PyStrRef, function::FuncArgs, AsObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; #[pyattr] #[pyclass(module = "_ast", name = "AST")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub(crate) struct AstNode; #[pyimpl(flags(BASETYPE, HAS_DICT))] diff --git a/vm/src/stdlib/builtins.rs b/vm/src/stdlib/builtins.rs index c1829d3dfd..5e59e03b95 100644 --- a/vm/src/stdlib/builtins.rs +++ b/vm/src/stdlib/builtins.rs @@ -34,7 +34,7 @@ mod builtins { stdlib::sys, types::PyComparisonOp, utils::Either, - AsObject, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use num_traits::{Signed, ToPrimitive, Zero}; diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index 0289d9a3d3..7400628ff5 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -19,7 +19,7 @@ mod _collections { }, utils::collection_repr, vm::ReprGuard, - AsObject, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use std::cmp::max; @@ -27,7 +27,7 @@ mod _collections { #[pyattr] #[pyclass(name = "deque")] - #[derive(Debug, Default, PyValue)] + #[derive(Debug, Default, PyPayload)] struct PyDeque { deque: PyRwLock>, maxlen: Option, @@ -508,7 +508,7 @@ mod _collections { impl AsSequence for PyDeque { fn as_sequence( - _zelf: &crate::PyObjectView, + _zelf: &crate::Py, _vm: &VirtualMachine, ) -> std::borrow::Cow<'static, PySequenceMethods> { std::borrow::Cow::Borrowed(&Self::SEQUENCE_METHDOS) @@ -552,7 +552,7 @@ mod _collections { impl Comparable for PyDeque { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -577,7 +577,7 @@ mod _collections { #[pyattr] #[pyclass(name = "_deque_iterator")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyDequeIterator { state: usize, internal: PyMutex>, @@ -642,7 +642,7 @@ mod _collections { impl IterNextIterable for PyDequeIterator {} impl IterNext for PyDequeIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { zelf.internal.lock().next(|deque, pos| { if zelf.state != deque.state.load() { return Err(vm.new_runtime_error("Deque mutated during iteration".to_owned())); @@ -657,7 +657,7 @@ mod _collections { #[pyattr] #[pyclass(name = "_deque_reverse_iterator")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyReverseDequeIterator { state: usize, // position is counting from the tail @@ -708,7 +708,7 @@ mod _collections { impl IterNextIterable for PyReverseDequeIterator {} impl IterNext for PyReverseDequeIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { zelf.internal.lock().next(|deque, pos| { if deque.state.load() != zelf.state { return Err(vm.new_runtime_error("Deque mutated during iteration".to_owned())); diff --git a/vm/src/stdlib/imp.rs b/vm/src/stdlib/imp.rs index f8deeb4363..12922cccb4 100644 --- a/vm/src/stdlib/imp.rs +++ b/vm/src/stdlib/imp.rs @@ -52,7 +52,7 @@ mod lock { mod _imp { use crate::{ builtins::{PyBytesRef, PyCode, PyModule, PyStr, PyStrRef}, - import, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + import, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; #[pyfunction] diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index 1bf65dd2a4..ffc7b6c3d1 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -114,7 +114,7 @@ mod _io { types::{Constructor, Destructor, IterNext, Iterable}, utils::Either, vm::{ReprGuard, VirtualMachine}, - AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, + AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, TryFromObject, }; use bstr::ByteSlice; @@ -369,7 +369,7 @@ mod _io { #[pyattr] #[pyclass(name = "_IOBase")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct _IOBase; #[pyimpl(with(IterNext, Destructor), flags(BASETYPE, HAS_DICT))] @@ -536,7 +536,7 @@ mod _io { } #[cold] - fn del(_zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyResult<()> { + fn del(_zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult<()> { unreachable!("slot_del is implemented") } } @@ -562,7 +562,7 @@ mod _io { }) } - fn next(_zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn next(_zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult { unreachable!("slot_iternext is implemented") } } @@ -1359,7 +1359,7 @@ mod _io { } #[pyimpl] - trait BufferedMixin: PyValue { + trait BufferedMixin: PyPayload { const READABLE: bool; const WRITABLE: bool; const SEEKABLE: bool = false; @@ -1562,7 +1562,7 @@ mod _io { } #[pyimpl] - trait BufferedReadable: PyValue { + trait BufferedReadable: PyPayload { type Reader: BufferedMixin; fn reader(&self) -> &Self::Reader; #[pymethod] @@ -1644,7 +1644,7 @@ mod _io { #[pyattr] #[pyclass(name = "BufferedReader", base = "_BufferedIOBase")] - #[derive(Debug, Default, PyValue)] + #[derive(Debug, Default, PyPayload)] struct BufferedReader { data: PyThreadMutex, } @@ -1671,7 +1671,7 @@ mod _io { } #[pyimpl] - trait BufferedWritable: PyValue { + trait BufferedWritable: PyPayload { type Writer: BufferedMixin; fn writer(&self) -> &Self::Writer; #[pymethod] @@ -1693,7 +1693,7 @@ mod _io { #[pyattr] #[pyclass(name = "BufferedWriter", base = "_BufferedIOBase")] - #[derive(Debug, Default, PyValue)] + #[derive(Debug, Default, PyPayload)] struct BufferedWriter { data: PyThreadMutex, } @@ -1721,7 +1721,7 @@ mod _io { #[pyattr] #[pyclass(name = "BufferedRandom", base = "_BufferedIOBase")] - #[derive(Debug, Default, PyValue)] + #[derive(Debug, Default, PyPayload)] struct BufferedRandom { data: PyThreadMutex, } @@ -1759,7 +1759,7 @@ mod _io { #[pyattr] #[pyclass(name = "BufferedRWPair", base = "_BufferedIOBase")] - #[derive(Debug, Default, PyValue)] + #[derive(Debug, Default, PyPayload)] struct BufferedRWPair { read: BufferedReader, write: BufferedWriter, @@ -2166,7 +2166,7 @@ mod _io { #[pyattr] #[pyclass(name = "TextIOWrapper", base = "_TextIOBase")] - #[derive(Debug, Default, PyValue)] + #[derive(Debug, Default, PyPayload)] struct TextIOWrapper { data: PyThreadMutex>, } @@ -3022,7 +3022,7 @@ mod _io { #[pyattr] #[pyclass(name = "StringIO", base = "_TextIOBase")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct StringIO { buffer: PyRwLock, closed: AtomicCell, @@ -3171,7 +3171,7 @@ mod _io { #[pyattr] #[pyclass(name = "BytesIO", base = "_BufferedIOBase")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct BytesIO { buffer: PyRwLock, closed: AtomicCell, @@ -3686,7 +3686,7 @@ mod fileio { crt_fd::Fd, function::{ArgBytesLike, ArgMemoryBuffer, FuncArgs, OptionalArg, OptionalOption}, stdlib::os, - AsObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use std::io::{Read, Write}; @@ -3792,7 +3792,7 @@ mod fileio { #[pyattr] #[pyclass(module = "io", name, base = "_RawIOBase")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub(super) struct FileIO { fd: AtomicCell, closefd: AtomicCell, diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index 400cc10b9b..803886192a 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -13,7 +13,7 @@ mod decl { protocol::{PyIter, PyIterReturn}, stdlib::sys, types::{Constructor, IterNext, IterNextIterable}, - AsObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, PyWeakRef, VirtualMachine, + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, PyWeakRef, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use num_bigint::BigInt; @@ -22,7 +22,7 @@ mod decl { #[pyattr] #[pyclass(name = "chain")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsChain { iterables: Vec, cur_idx: AtomicCell, @@ -62,7 +62,7 @@ mod decl { } impl IterNextIterable for PyItertoolsChain {} impl IterNext for PyItertoolsChain { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { loop { let pos = zelf.cur_idx.load(); if pos >= zelf.iterables.len() { @@ -99,7 +99,7 @@ mod decl { #[pyattr] #[pyclass(name = "compress")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsCompress { data: PyIter, selector: PyIter, @@ -130,7 +130,7 @@ mod decl { impl IterNextIterable for PyItertoolsCompress {} impl IterNext for PyItertoolsCompress { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { loop { let sel_obj = match zelf.selector.next(vm)? { PyIterReturn::Return(obj) => obj, @@ -148,7 +148,7 @@ mod decl { #[pyattr] #[pyclass(name = "count")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsCount { cur: PyRwLock, step: BigInt, @@ -192,7 +192,7 @@ mod decl { impl PyItertoolsCount {} impl IterNextIterable for PyItertoolsCount {} impl IterNext for PyItertoolsCount { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let mut cur = zelf.cur.write(); let result = cur.clone(); *cur += &zelf.step; @@ -202,7 +202,7 @@ mod decl { #[pyattr] #[pyclass(name = "cycle")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsCycle { iter: PyIter, saved: PyRwLock>, @@ -226,7 +226,7 @@ mod decl { impl PyItertoolsCycle {} impl IterNextIterable for PyItertoolsCycle {} impl IterNext for PyItertoolsCycle { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let item = if let PyIterReturn::Return(item) = zelf.iter.next(vm)? { zelf.saved.write().push(item.clone()); item @@ -251,7 +251,7 @@ mod decl { #[pyattr] #[pyclass(name = "repeat")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsRepeat { object: PyObjectRef, times: Option>, @@ -317,7 +317,7 @@ mod decl { impl IterNextIterable for PyItertoolsRepeat {} impl IterNext for PyItertoolsRepeat { - fn next(zelf: &PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, _vm: &VirtualMachine) -> PyResult { if let Some(ref times) = zelf.times { let mut times = times.write(); if *times == 0 { @@ -331,7 +331,7 @@ mod decl { #[pyattr] #[pyclass(name = "starmap")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsStarmap { function: PyObjectRef, iterable: PyIter, @@ -361,7 +361,7 @@ mod decl { impl PyItertoolsStarmap {} impl IterNextIterable for PyItertoolsStarmap {} impl IterNext for PyItertoolsStarmap { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let obj = zelf.iterable.next(vm)?; let function = &zelf.function; match obj { @@ -376,7 +376,7 @@ mod decl { #[pyattr] #[pyclass(name = "takewhile")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsTakewhile { predicate: PyObjectRef, iterable: PyIter, @@ -415,7 +415,7 @@ mod decl { impl PyItertoolsTakewhile {} impl IterNextIterable for PyItertoolsTakewhile {} impl IterNext for PyItertoolsTakewhile { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { if zelf.stop_flag.load() { return Ok(PyIterReturn::StopIteration(None)); } @@ -440,7 +440,7 @@ mod decl { #[pyattr] #[pyclass(name = "dropwhile")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsDropwhile { predicate: ArgCallable, iterable: PyIter, @@ -479,7 +479,7 @@ mod decl { impl PyItertoolsDropwhile {} impl IterNextIterable for PyItertoolsDropwhile {} impl IterNext for PyItertoolsDropwhile { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let predicate = &zelf.predicate; let iterable = &zelf.iterable; @@ -521,7 +521,7 @@ mod decl { } impl GroupByState { - fn is_current(&self, grouper: &PyObjectView) -> bool { + fn is_current(&self, grouper: &Py) -> bool { self.grouper .as_ref() .and_then(|g| g.upgrade()) @@ -531,7 +531,7 @@ mod decl { #[pyattr] #[pyclass(name = "groupby")] - #[derive(PyValue)] + #[derive(PyPayload)] struct PyItertoolsGroupBy { iterable: PyIter, key_func: Option, @@ -597,7 +597,7 @@ mod decl { } impl IterNextIterable for PyItertoolsGroupBy {} impl IterNext for PyItertoolsGroupBy { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let mut state = zelf.state.lock(); state.grouper = None; @@ -648,7 +648,7 @@ mod decl { #[pyattr] #[pyclass(name = "_grouper")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsGrouper { groupby: PyRef, } @@ -657,7 +657,7 @@ mod decl { impl PyItertoolsGrouper {} impl IterNextIterable for PyItertoolsGrouper {} impl IterNext for PyItertoolsGrouper { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let old_key = { let mut state = zelf.groupby.state.lock(); @@ -691,7 +691,7 @@ mod decl { #[pyattr] #[pyclass(name = "islice")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsIslice { iterable: PyIter, cur: AtomicCell, @@ -790,7 +790,7 @@ mod decl { impl IterNextIterable for PyItertoolsIslice {} impl IterNext for PyItertoolsIslice { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { while zelf.cur.load() < zelf.next.load() { zelf.iterable.next(vm)?; zelf.cur.fetch_add(1); @@ -818,7 +818,7 @@ mod decl { #[pyattr] #[pyclass(name = "filterfalse")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsFilterFalse { predicate: PyObjectRef, iterable: PyIter, @@ -855,7 +855,7 @@ mod decl { impl PyItertoolsFilterFalse {} impl IterNextIterable for PyItertoolsFilterFalse {} impl IterNext for PyItertoolsFilterFalse { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let predicate = &zelf.predicate; let iterable = &zelf.iterable; @@ -879,7 +879,7 @@ mod decl { #[pyattr] #[pyclass(name = "accumulate")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsAccumulate { iterable: PyIter, binop: Option, @@ -915,7 +915,7 @@ mod decl { impl IterNextIterable for PyItertoolsAccumulate {} impl IterNext for PyItertoolsAccumulate { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let iterable = &zelf.iterable; let acc_value = zelf.acc_value.read().clone(); @@ -977,7 +977,7 @@ mod decl { #[pyattr] #[pyclass(name = "tee")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsTee { tee_data: PyRc, index: AtomicCell, @@ -1043,7 +1043,7 @@ mod decl { } impl IterNextIterable for PyItertoolsTee {} impl IterNext for PyItertoolsTee { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let value = match zelf.tee_data.get_item(vm, zelf.index.load())? { PyIterReturn::Return(obj) => obj, PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)), @@ -1055,7 +1055,7 @@ mod decl { #[pyattr] #[pyclass(name = "product")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsProduct { pools: Vec>, idxs: PyRwLock>, @@ -1122,7 +1122,7 @@ mod decl { } impl IterNextIterable for PyItertoolsProduct {} impl IterNext for PyItertoolsProduct { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { // stop signal if zelf.stop.load() { return Ok(PyIterReturn::StopIteration(None)); @@ -1153,7 +1153,7 @@ mod decl { #[pyattr] #[pyclass(name = "combinations")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsCombinations { pool: Vec, indices: PyRwLock>, @@ -1201,7 +1201,7 @@ mod decl { impl PyItertoolsCombinations {} impl IterNextIterable for PyItertoolsCombinations {} impl IterNext for PyItertoolsCombinations { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { // stop signal if zelf.exhausted.load() { return Ok(PyIterReturn::StopIteration(None)); @@ -1252,7 +1252,7 @@ mod decl { #[pyattr] #[pyclass(name = "combinations_with_replacement")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsCombinationsWithReplacement { pool: Vec, indices: PyRwLock>, @@ -1292,7 +1292,7 @@ mod decl { impl IterNextIterable for PyItertoolsCombinationsWithReplacement {} impl IterNext for PyItertoolsCombinationsWithReplacement { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { // stop signal if zelf.exhausted.load() { return Ok(PyIterReturn::StopIteration(None)); @@ -1338,7 +1338,7 @@ mod decl { #[pyattr] #[pyclass(name = "permutations")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsPermutations { pool: Vec, // Collected input iterable indices: PyRwLock>, // One index per element in pool @@ -1400,7 +1400,7 @@ mod decl { impl PyItertoolsPermutations {} impl IterNextIterable for PyItertoolsPermutations {} impl IterNext for PyItertoolsPermutations { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { // stop signal if zelf.exhausted.load() { return Ok(PyIterReturn::StopIteration(None)); @@ -1492,7 +1492,7 @@ mod decl { #[pyattr] #[pyclass(name = "zip_longest")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsZipLongest { iterators: Vec, fillvalue: PyObjectRef, @@ -1502,7 +1502,7 @@ mod decl { impl PyItertoolsZipLongest {} impl IterNextIterable for PyItertoolsZipLongest {} impl IterNext for PyItertoolsZipLongest { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { if zelf.iterators.is_empty() { return Ok(PyIterReturn::StopIteration(None)); } @@ -1528,7 +1528,7 @@ mod decl { #[pyattr] #[pyclass(name = "pairwise")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItertoolsPairwise { iterator: PyIter, old: PyRwLock>, @@ -1550,7 +1550,7 @@ mod decl { impl PyItertoolsPairwise {} impl IterNextIterable for PyItertoolsPairwise {} impl IterNext for PyItertoolsPairwise { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let old = match zelf.old.read().clone() { None => match zelf.iterator.next(vm)? { PyIterReturn::Return(obj) => obj, diff --git a/vm/src/stdlib/operator.rs b/vm/src/stdlib/operator.rs index e22a07fb05..9fe571cce0 100644 --- a/vm/src/stdlib/operator.rs +++ b/vm/src/stdlib/operator.rs @@ -20,7 +20,7 @@ mod _operator { }, utils::Either, vm::ReprGuard, - AsObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; /// Same as a < b. @@ -423,7 +423,7 @@ mod _operator { /// (r.name.first, r.name.last). #[pyattr] #[pyclass(name = "attrgetter")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyAttrGetter { attrs: Vec, } @@ -496,7 +496,7 @@ mod _operator { impl Callable for PyAttrGetter { type Args = PyObjectRef; - fn call(zelf: &PyObjectView, obj: Self::Args, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &Py, obj: Self::Args, vm: &VirtualMachine) -> PyResult { // Handle case where we only have one attribute. if zelf.attrs.len() == 1 { return Self::get_single_attr(obj, zelf.attrs[0].as_str(), vm); @@ -517,7 +517,7 @@ mod _operator { /// After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3]) #[pyattr] #[pyclass(name = "itemgetter")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyItemGetter { items: Vec, } @@ -561,7 +561,7 @@ mod _operator { impl Callable for PyItemGetter { type Args = PyObjectRef; - fn call(zelf: &PyObjectView, obj: Self::Args, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &Py, obj: Self::Args, vm: &VirtualMachine) -> PyResult { // Handle case where we only have one attribute. if zelf.items.len() == 1 { return obj.get_item(zelf.items[0].clone(), vm); @@ -583,7 +583,7 @@ mod _operator { /// r.name('date', foo=1). #[pyattr] #[pyclass(name = "methodcaller")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyMethodCaller { name: PyStrRef, args: FuncArgs, @@ -659,7 +659,7 @@ mod _operator { type Args = PyObjectRef; #[inline] - fn call(zelf: &PyObjectView, obj: Self::Args, vm: &VirtualMachine) -> PyResult { + fn call(zelf: &Py, obj: Self::Args, vm: &VirtualMachine) -> PyResult { vm.call_method(&obj, zelf.name.as_str(), zelf.args.clone()) } } diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index e1d7289b71..9569db0f13 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -4,7 +4,7 @@ use crate::{ crt_fd::Fd, function::{ArgumentError, FromArgs, FuncArgs}, protocol::PyBuffer, - AsObject, PyObject, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, TryFromObject, + AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use std::{ @@ -416,7 +416,7 @@ pub(super) mod _os { types::{IterNext, IterNextIterable, PyStructSequence}, utils::Either, vm::{ReprGuard, VirtualMachine}, - AsObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; @@ -703,7 +703,7 @@ pub(super) mod _os { #[pyattr] #[pyclass(name)] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct DirEntry { entry: fs::DirEntry, mode: OutputMode, @@ -875,7 +875,7 @@ pub(super) mod _os { #[pyattr] #[pyclass(name = "ScandirIter")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct ScandirIterator { entries: PyRwLock, exhausted: AtomicCell, @@ -901,7 +901,7 @@ pub(super) mod _os { } impl IterNextIterable for ScandirIterator {} impl IterNext for ScandirIterator { - fn next(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { if zelf.exhausted.load() { return Ok(PyIterReturn::StopIteration(None)); } diff --git a/vm/src/stdlib/posix.rs b/vm/src/stdlib/posix.rs index 9c31d17dd4..ab86351154 100644 --- a/vm/src/stdlib/posix.rs +++ b/vm/src/stdlib/posix.rs @@ -38,7 +38,7 @@ pub mod module { }, types::Constructor, utils::{Either, ToCString}, - AsObject, PyObjectRef, PyResult, PyValue, VirtualMachine, + AsObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use bitflags::bitflags; use nix::{ @@ -522,7 +522,7 @@ pub mod module { #[pyattr] #[pyclass(name = "sched_param")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct SchedParam { sched_priority: PyObjectRef, } diff --git a/vm/src/stdlib/sre.rs b/vm/src/stdlib/sre.rs index 3a9b85bfd0..389257d602 100644 --- a/vm/src/stdlib/sre.rs +++ b/vm/src/stdlib/sre.rs @@ -13,7 +13,7 @@ mod _sre { protocol::{PyBuffer, PyMappingMethods}, stdlib::sys, types::{AsMapping, Comparable, Hashable}, - PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject, TryFromObject, + PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use core::str; @@ -123,7 +123,7 @@ mod _sre { #[pyattr] #[pyclass(name = "Pattern")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub(crate) struct Pattern { pub pattern: PyObjectRef, pub flags: SreFlag, @@ -504,7 +504,7 @@ mod _sre { } impl Hashable for Pattern { - fn hash(zelf: &crate::PyObjectView, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let hash = zelf.pattern.hash(vm)?; let (_, code, _) = unsafe { zelf.code.align_to::() }; let hash = hash ^ vm.state.hash_secret.hash_bytes(code); @@ -516,7 +516,7 @@ mod _sre { impl Comparable for Pattern { fn cmp( - zelf: &crate::PyObjectView, + zelf: &crate::Py, other: &PyObject, op: crate::types::PyComparisonOp, vm: &VirtualMachine, @@ -541,7 +541,7 @@ mod _sre { #[pyattr] #[pyclass(name = "Match")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub(crate) struct Match { string: PyObjectRef, pattern: PyRef, @@ -793,14 +793,14 @@ mod _sre { } impl AsMapping for Match { - fn as_mapping(_zelf: &crate::PyObjectView, _vm: &VirtualMachine) -> PyMappingMethods { + fn as_mapping(_zelf: &crate::Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS } } #[pyattr] #[pyclass(name = "SRE_Scanner")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct SreScanner { pattern: PyRef, string: PyObjectRef, diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index e847b0f058..404ad430e0 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -5,7 +5,7 @@ mod symtable { use crate::{ builtins::PyStrRef, compile::{self, Symbol, SymbolScope, SymbolTable, SymbolTableType}, - PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use std::fmt; @@ -39,7 +39,7 @@ mod symtable { #[pyattr] #[pyclass(name = "SymbolTable")] - #[derive(PyValue)] + #[derive(PyPayload)] struct PySymbolTable { symtable: SymbolTable, } @@ -151,7 +151,7 @@ mod symtable { #[pyattr] #[pyclass(name = "Symbol")] - #[derive(PyValue)] + #[derive(PyPayload)] struct PySymbol { symbol: Symbol, namespaces: Vec, diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index 90af5479c6..87e5d4ecde 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -11,7 +11,7 @@ pub(crate) mod _thread { py_io, types::{Constructor, GetAttr, SetAttr}, utils::Either, - AsObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use parking_lot::{ lock_api::{RawMutex as RawMutexT, RawMutexTimed, RawReentrantMutex}, @@ -95,7 +95,7 @@ pub(crate) mod _thread { #[pyattr(name = "LockType")] #[pyclass(module = "thread", name = "lock")] - #[derive(PyValue)] + #[derive(PyPayload)] struct Lock { mu: RawMutex, } @@ -150,7 +150,7 @@ pub(crate) mod _thread { pub type RawRMutex = RawReentrantMutex; #[pyattr] #[pyclass(module = "thread", name = "RLock")] - #[derive(PyValue)] + #[derive(PyPayload)] struct RLock { mu: RawRMutex, } @@ -305,7 +305,7 @@ pub(crate) mod _thread { #[pyattr] #[pyclass(module = "thread", name = "_local")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct Local { data: ThreadLocal, } @@ -345,7 +345,7 @@ pub(crate) mod _thread { impl SetAttr for Local { fn setattro( - zelf: &crate::PyObjectView, + zelf: &crate::Py, attr: PyStrRef, value: Option, vm: &VirtualMachine, diff --git a/vm/src/stdlib/weakref.rs b/vm/src/stdlib/weakref.rs index 59620625d4..1866e9abe0 100644 --- a/vm/src/stdlib/weakref.rs +++ b/vm/src/stdlib/weakref.rs @@ -8,8 +8,10 @@ pub(crate) use _weakref::make_module; #[pymodule] mod _weakref { - use crate::builtins::{PyDictRef, PyTypeRef, PyWeak}; - use crate::{PyObjectRef, PyRef, PyResult, VirtualMachine}; + use crate::{ + builtins::{PyDictRef, PyTypeRef, PyWeak}, + PyObjectRef, PyResult, VirtualMachine, + }; #[pyattr(name = "ref")] fn ref_(vm: &VirtualMachine) -> PyTypeRef { @@ -40,7 +42,7 @@ mod _weakref { #[pyfunction] fn getweakrefs(obj: PyObjectRef) -> Vec { match obj.get_weak_references() { - Some(v) => v.into_iter().map(|weak| PyRef::from(weak).into()).collect(), + Some(v) => v.into_iter().map(Into::into).collect(), None => vec![], } } diff --git a/vm/src/stdlib/winreg.rs b/vm/src/stdlib/winreg.rs index 59c46fa1f2..275444e9d0 100644 --- a/vm/src/stdlib/winreg.rs +++ b/vm/src/stdlib/winreg.rs @@ -29,7 +29,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef { mod winreg { use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crate::{ - builtins::PyStrRef, convert::ToPyException, PyObjectRef, PyRef, PyResult, PyValue, + builtins::PyStrRef, convert::ToPyException, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use ::winreg::{enums::RegType, RegKey, RegValue}; @@ -53,7 +53,7 @@ mod winreg { #[pyattr] #[pyclass(module = "winreg", name = "HKEYType")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct PyHkey { key: PyRwLock, } diff --git a/vm/src/suggestion.rs b/vm/src/suggestion.rs index c215b611ef..774abff7d7 100644 --- a/vm/src/suggestion.rs +++ b/vm/src/suggestion.rs @@ -2,7 +2,7 @@ use crate::{ builtins::{PyStr, PyStrRef}, exceptions::types::PyBaseExceptionRef, sliceable::SliceableSequenceOp, - AsObject, PyObjectRef, PyObjectView, VirtualMachine, + AsObject, Py, PyObjectRef, VirtualMachine, }; use rustpython_common::str::levenshtein::{levenshtein_distance, MOVE_COST}; use std::iter::ExactSizeIterator; @@ -17,7 +17,7 @@ fn calculate_suggestions<'a>( return None; } - let mut suggestion: Option<&PyObjectView> = None; + let mut suggestion: Option<&Py> = None; let mut suggestion_distance = usize::MAX; let name = name.downcast_ref::()?; diff --git a/vm/src/types/slot.rs b/vm/src/types/slot.rs index 00d51216bc..5680c7386e 100644 --- a/vm/src/types/slot.rs +++ b/vm/src/types/slot.rs @@ -8,7 +8,7 @@ use crate::{ PyBuffer, PyIterReturn, PyMapping, PyMappingMethods, PySequence, PySequenceMethods, }, utils::Either, - AsObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use num_traits::{Signed, ToPrimitive}; @@ -392,7 +392,7 @@ impl PyType { } #[pyimpl] -pub trait Constructor: PyValue { +pub trait Constructor: PyPayload { type Args: FromArgs; #[inline] @@ -406,7 +406,7 @@ pub trait Constructor: PyValue { } /// For types that cannot be instantiated through Python code. -pub trait Unconstructible: PyValue {} +pub trait Unconstructible: PyPayload {} impl Constructor for T where @@ -420,7 +420,7 @@ where } #[pyimpl] -pub trait Destructor: PyValue { +pub trait Destructor: PyPayload { #[inline] // for __del__ #[pyslot] fn slot_del(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<()> { @@ -436,11 +436,11 @@ pub trait Destructor: PyValue { Self::slot_del(&zelf, vm) } - fn del(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult<()>; + fn del(zelf: &Py, vm: &VirtualMachine) -> PyResult<()>; } #[pyimpl] -pub trait Callable: PyValue { +pub trait Callable: PyPayload { type Args: FromArgs; #[inline] @@ -458,11 +458,11 @@ pub trait Callable: PyValue { fn __call__(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult { Self::slot_call(&zelf, args.bind(vm)?, vm) } - fn call(zelf: &PyObjectView, args: Self::Args, vm: &VirtualMachine) -> PyResult; + fn call(zelf: &Py, args: Self::Args, vm: &VirtualMachine) -> PyResult; } #[pyimpl] -pub trait GetDescriptor: PyValue { +pub trait GetDescriptor: PyPayload { #[pyslot] fn descr_get( zelf: PyObjectRef, @@ -530,7 +530,7 @@ pub trait GetDescriptor: PyValue { } #[pyimpl] -pub trait Hashable: PyValue { +pub trait Hashable: PyPayload { #[inline] #[pyslot] fn slot_hash(zelf: &PyObject, vm: &VirtualMachine) -> PyResult { @@ -547,10 +547,10 @@ pub trait Hashable: PyValue { Self::slot_hash(&zelf, vm) } - fn hash(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult; + fn hash(zelf: &Py, vm: &VirtualMachine) -> PyResult; } -pub trait Unhashable: PyValue {} +pub trait Unhashable: PyPayload {} impl Hashable for T where @@ -561,13 +561,13 @@ where } #[cold] - fn hash(_zelf: &PyObjectView, _vm: &VirtualMachine) -> PyResult { + fn hash(_zelf: &Py, _vm: &VirtualMachine) -> PyResult { unreachable!("slot_hash is implemented for unhashable types"); } } #[pyimpl] -pub trait Comparable: PyValue { +pub trait Comparable: PyPayload { #[inline] #[pyslot] fn slot_richcompare( @@ -584,7 +584,7 @@ pub trait Comparable: PyValue { } fn cmp( - zelf: &PyObjectView, + zelf: &Py, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, @@ -748,7 +748,7 @@ impl PyComparisonOp { } #[pyimpl] -pub trait GetAttr: PyValue { +pub trait GetAttr: PyPayload { #[pyslot] fn slot_getattro(obj: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult { if let Ok(zelf) = obj.downcast::() { @@ -758,7 +758,7 @@ pub trait GetAttr: PyValue { } } - // TODO: make zelf: &PyObjectView + // TODO: make zelf: &Py fn getattro(zelf: PyRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult; #[inline] @@ -769,7 +769,7 @@ pub trait GetAttr: PyValue { } #[pyimpl] -pub trait SetAttr: PyValue { +pub trait SetAttr: PyPayload { #[pyslot] #[inline] fn slot_setattro( @@ -786,7 +786,7 @@ pub trait SetAttr: PyValue { } fn setattro( - zelf: &PyObjectView, + zelf: &Py, name: PyStrRef, value: Option, vm: &VirtualMachine, @@ -811,7 +811,7 @@ pub trait SetAttr: PyValue { } #[pyimpl] -pub trait AsBuffer: PyValue { +pub trait AsBuffer: PyPayload { // TODO: `flags` parameter #[inline] #[pyslot] @@ -822,11 +822,11 @@ pub trait AsBuffer: PyValue { Self::as_buffer(zelf, vm) } - fn as_buffer(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult; + fn as_buffer(zelf: &Py, vm: &VirtualMachine) -> PyResult; } #[pyimpl] -pub trait AsMapping: PyValue { +pub trait AsMapping: PyPayload { #[inline] #[pyslot] fn slot_as_mapping(zelf: &PyObject, vm: &VirtualMachine) -> PyMappingMethods { @@ -834,15 +834,15 @@ pub trait AsMapping: PyValue { Self::as_mapping(zelf, vm) } - fn as_mapping(zelf: &PyObjectView, vm: &VirtualMachine) -> PyMappingMethods; + fn as_mapping(zelf: &Py, vm: &VirtualMachine) -> PyMappingMethods; - fn mapping_downcast<'a>(mapping: &'a PyMapping) -> &'a PyObjectView { + fn mapping_downcast<'a>(mapping: &'a PyMapping) -> &'a Py { unsafe { mapping.obj.downcast_unchecked_ref() } } } #[pyimpl] -pub trait AsSequence: PyValue { +pub trait AsSequence: PyPayload { #[inline] #[pyslot] fn slot_as_sequence(zelf: &PyObject, vm: &VirtualMachine) -> Cow<'static, PySequenceMethods> { @@ -850,18 +850,15 @@ pub trait AsSequence: PyValue { Self::as_sequence(zelf, vm) } - fn as_sequence( - zelf: &PyObjectView, - vm: &VirtualMachine, - ) -> Cow<'static, PySequenceMethods>; + fn as_sequence(zelf: &Py, vm: &VirtualMachine) -> Cow<'static, PySequenceMethods>; - fn sequence_downcast<'a>(seq: &'a PySequence) -> &'a PyObjectView { + fn sequence_downcast<'a>(seq: &'a PySequence) -> &'a Py { unsafe { seq.obj.downcast_unchecked_ref() } } } #[pyimpl] -pub trait Iterable: PyValue { +pub trait Iterable: PyPayload { #[pyslot] #[pymethod(name = "__iter__")] fn slot_iter(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult { @@ -877,7 +874,7 @@ pub trait Iterable: PyValue { // `Iterator` fits better, but to avoid confusion with rust std::iter::Iterator #[pyimpl(with(Iterable))] -pub trait IterNext: PyValue + Iterable { +pub trait IterNext: PyPayload + Iterable { #[pyslot] fn slot_iternext(zelf: &PyObject, vm: &VirtualMachine) -> PyResult { if let Some(zelf) = zelf.downcast_ref() { @@ -887,7 +884,7 @@ pub trait IterNext: PyValue + Iterable { } } - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult; + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult; #[inline] #[pymethod] @@ -896,7 +893,7 @@ pub trait IterNext: PyValue + Iterable { } } -pub trait IterNextIterable: PyValue {} +pub trait IterNextIterable: PyPayload {} impl Iterable for T where diff --git a/vm/src/types/structseq.rs b/vm/src/types/structseq.rs index d56de4fb71..2bb47599f9 100644 --- a/vm/src/types/structseq.rs +++ b/vm/src/types/structseq.rs @@ -2,7 +2,7 @@ use crate::{ builtins::{PyTuple, PyTupleRef, PyTypeRef}, pyclass::{PyClassImpl, StaticType}, pyobject::PyContext, - AsObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyimpl] diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 88c4df2628..551ca5b0bc 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -24,8 +24,8 @@ use crate::{ import, protocol::PyIterIter, scope::Scope, - signal, stdlib, AsObject, PyContext, PyObject, PyObjectRef, PyRef, PyRefExact, PyResult, - PyValue, + signal, stdlib, AsObject, PyContext, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, + PyResult, }; use crossbeam_utils::atomic::AtomicCell; use std::{ diff --git a/vm/src/vm_new.rs b/vm/src/vm_new.rs index 6f03565d05..dd4a3ec3ef 100644 --- a/vm/src/vm_new.rs +++ b/vm/src/vm_new.rs @@ -10,7 +10,7 @@ use crate::{ convert::ToPyObject, scope::Scope, vm::VirtualMachine, - AsObject, PyObject, PyObjectRef, PyRef, PyValue, + AsObject, PyObject, PyObjectRef, PyPayload, PyRef, }; /// Collection of object creation helpers @@ -23,7 +23,7 @@ impl VirtualMachine { pub fn new_pyref(&self, value: T) -> PyRef

where T: Into

, - P: PyValue, + P: PyPayload, { value.into().into_ref(self) } diff --git a/vm/src/vm_object.rs b/vm/src/vm_object.rs index 8e39ebae66..02849e9ed0 100644 --- a/vm/src/vm_object.rs +++ b/vm/src/vm_object.rs @@ -2,7 +2,7 @@ use crate::{ builtins::{PyBaseExceptionRef, PyList, PyStr}, function::{FuncArgs, IntoFuncArgs}, vm::VirtualMachine, - AsObject, PyMethod, PyObject, PyObjectRef, PyResult, PyValue, + AsObject, PyMethod, PyObject, PyObjectRef, PyPayload, PyResult, }; /// Trace events for sys.settrace and sys.setprofile. diff --git a/wasm/lib/src/browser_module.rs b/wasm/lib/src/browser_module.rs index d73031b28d..3b21432a3d 100644 --- a/wasm/lib/src/browser_module.rs +++ b/wasm/lib/src/browser_module.rs @@ -12,7 +12,7 @@ mod _browser { function::{ArgCallable, OptionalArg}, import::import_file, pyclass::PyClassImpl, - PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, + PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use wasm_bindgen::{prelude::*, JsCast}; use wasm_bindgen_futures::JsFuture; @@ -161,7 +161,7 @@ mod _browser { #[pyattr] #[pyclass(module = "browser", name)] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct Document { doc: web_sys::Document, } @@ -193,7 +193,7 @@ mod _browser { #[pyattr] #[pyclass(module = "browser", name)] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] struct Element { elem: web_sys::Element, } diff --git a/wasm/lib/src/convert.rs b/wasm/lib/src/convert.rs index 8a516e2b9a..edb002a219 100644 --- a/wasm/lib/src/convert.rs +++ b/wasm/lib/src/convert.rs @@ -7,7 +7,7 @@ use rustpython_vm::{ compile::{CompileError, CompileErrorType}, exceptions, function::{ArgBytesLike, FuncArgs}, - py_serde, AsObject, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, VirtualMachine, + py_serde, AsObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, }; use wasm_bindgen::{closure::Closure, prelude::*, JsCast}; diff --git a/wasm/lib/src/js_module.rs b/wasm/lib/src/js_module.rs index a81281ae9f..aaa3f2d309 100644 --- a/wasm/lib/src/js_module.rs +++ b/wasm/lib/src/js_module.rs @@ -18,7 +18,7 @@ mod _js { function::{ArgCallable, OptionalArg, OptionalOption, PosArgs}, protocol::PyIterReturn, types::{IterNext, IterNextIterable}, - PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, + Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use std::{cell, fmt, future}; use wasm_bindgen::{closure::Closure, prelude::*, JsCast}; @@ -59,7 +59,7 @@ mod _js { #[pyattr] #[pyclass(module = "_js", name = "JSValue")] - #[derive(Debug, PyValue)] + #[derive(Debug, PyPayload)] pub struct PyJsValue { pub(crate) value: JsValue, } @@ -291,7 +291,7 @@ mod _js { #[pyattr] #[pyclass(module = "_js", name = "JSClosure")] - #[derive(PyValue)] + #[derive(PyPayload)] struct JsClosure { closure: cell::RefCell>, destroyed: cell::Cell, @@ -386,7 +386,7 @@ mod _js { #[pyattr] #[pyclass(module = "_js", name = "Promise")] - #[derive(Debug, Clone, PyValue)] + #[derive(Debug, Clone, PyPayload)] pub struct PyPromise { value: PromiseKind, } @@ -558,7 +558,7 @@ mod _js { } #[pyclass(noattr, module = "_js", name = "AwaitPromise")] - #[derive(PyValue)] + #[derive(PyPayload)] struct AwaitPromise { obj: cell::Cell>, } @@ -606,7 +606,7 @@ mod _js { impl IterNextIterable for AwaitPromise {} impl IterNext for AwaitPromise { - fn next(zelf: &PyObjectView, vm: &VirtualMachine) -> PyResult { + fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { zelf.send(None, vm) } } diff --git a/wasm/lib/src/vm_class.rs b/wasm/lib/src/vm_class.rs index 731c0173c6..969ac06ca7 100644 --- a/wasm/lib/src/vm_class.rs +++ b/wasm/lib/src/vm_class.rs @@ -5,9 +5,10 @@ use crate::{ }; use js_sys::{Object, TypeError}; use rustpython_vm::{ + builtins::PyWeak, compile::{self, Mode}, scope::Scope, - InitParameter, Interpreter, PyObjectRef, PyObjectWeak, PyResult, PySettings, PyValue, + InitParameter, Interpreter, PyObjectRef, PyPayload, PyRef, PyResult, PySettings, VirtualMachine, }; use std::{ @@ -197,7 +198,10 @@ impl WASMVirtualMachine { STORED_VMS.with(|cell| cell.borrow().contains_key(&self.id)) } - pub(crate) fn push_held_rc(&self, obj: PyObjectRef) -> Result, JsValue> { + pub(crate) fn push_held_rc( + &self, + obj: PyObjectRef, + ) -> Result>, JsValue> { self.with_vm(|vm, stored_vm| { let weak = obj.downgrade(None, vm)?; stored_vm.held_objects.borrow_mut().push(obj);