From 0d09bc72852bebf00e84475a890c21ffdbd1a26b Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 24 Sep 2021 20:41:11 +0900 Subject: [PATCH] derive(PyValue) not to depend on local context --- derive/src/pyvalue.rs | 3 ++- vm/src/stdlib/array.rs | 2 +- vm/src/stdlib/collections.rs | 3 +-- vm/src/stdlib/csv.rs | 4 ++-- vm/src/stdlib/hashlib.rs | 2 +- vm/src/stdlib/io.rs | 2 +- vm/src/stdlib/itertools.rs | 4 ++-- vm/src/stdlib/json.rs | 2 +- vm/src/stdlib/operator.rs | 4 ++-- vm/src/stdlib/os.rs | 2 +- vm/src/stdlib/posix.rs | 3 +-- vm/src/stdlib/pyexpat.rs | 1 - vm/src/stdlib/pystruct.rs | 3 +-- vm/src/stdlib/random.rs | 2 +- vm/src/stdlib/select.rs | 4 ++-- vm/src/stdlib/socket.rs | 4 ++-- vm/src/stdlib/sre.rs | 3 +-- vm/src/stdlib/ssl.rs | 3 +-- vm/src/stdlib/symtable.rs | 4 ++-- vm/src/stdlib/thread.rs | 4 ++-- vm/src/stdlib/unicodedata.rs | 5 ++--- vm/src/stdlib/winreg.rs | 2 +- vm/src/stdlib/zlib.rs | 2 +- wasm/lib/src/browser_module.rs | 4 ++-- wasm/lib/src/js_module.rs | 2 +- 25 files changed, 34 insertions(+), 40 deletions(-) diff --git a/derive/src/pyvalue.rs b/derive/src/pyvalue.rs index a3bb0b3b07..fc9c7826e2 100644 --- a/derive/src/pyvalue.rs +++ b/derive/src/pyvalue.rs @@ -8,7 +8,8 @@ pub(crate) fn impl_pyvalue(input: DeriveInput) -> std::result::Result &PyTypeRef { + fn class(_vm: &::rustpython_vm::VirtualMachine) -> &rustpython_vm::builtins::PyTypeRef { + use ::rustpython_vm::StaticType; Self::static_type() } } diff --git a/vm/src/stdlib/array.rs b/vm/src/stdlib/array.rs index 6baa015a7b..30b9f958b8 100644 --- a/vm/src/stdlib/array.rs +++ b/vm/src/stdlib/array.rs @@ -21,7 +21,7 @@ mod array { sliceable::{saturate_index, PySliceableSequence, PySliceableSequenceMut, SequenceIndex}, slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter, SlotConstructor}, IdProtocol, IntoPyObject, IntoPyResult, PyComparisonValue, PyObjectRef, PyRef, PyResult, - PyValue, StaticType, TryFromObject, TypeProtocol, VirtualMachine, + PyValue, TryFromObject, TypeProtocol, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index 7806414090..640eb24a6b 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -14,8 +14,7 @@ mod _collections { Comparable, Hashable, Iterable, PyComparisonOp, PyIter, SlotConstructor, Unhashable, }, vm::ReprGuard, - PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TypeProtocol, - VirtualMachine, + PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; diff --git a/vm/src/stdlib/csv.rs b/vm/src/stdlib/csv.rs index 85a08c64e3..33843fb3c0 100644 --- a/vm/src/stdlib/csv.rs +++ b/vm/src/stdlib/csv.rs @@ -1,11 +1,11 @@ use crate::common::lock::PyMutex; use crate::{ - builtins::{PyStr, PyStrRef, PyTypeRef}, + builtins::{PyStr, PyStrRef}, function::{ArgIterable, ArgumentError, FromArgs, FuncArgs}, iterator, slots::PyIter, types::create_simple_type, - PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, TypeProtocol, + PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine, }; use itertools::{self, Itertools}; diff --git a/vm/src/stdlib/hashlib.rs b/vm/src/stdlib/hashlib.rs index c2e72f87d9..d6ccdde15e 100644 --- a/vm/src/stdlib/hashlib.rs +++ b/vm/src/stdlib/hashlib.rs @@ -6,7 +6,7 @@ mod hashlib { use crate::{ builtins::{PyBytes, PyBytesRef, PyStrRef, PyTypeRef}, function::{FuncArgs, OptionalArg}, - PyResult, PyValue, StaticType, VirtualMachine, + PyResult, PyValue, VirtualMachine, }; use blake2::{Blake2b, Blake2s}; use digest::DynDigest; diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index 42d7ffcb5b..0f9567faf3 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -3682,7 +3682,7 @@ mod fileio { use crate::function::{FuncArgs, OptionalArg}; use crate::stdlib::os; use crate::vm::VirtualMachine; - use crate::{PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, TypeProtocol}; + use crate::{PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol}; use crossbeam_utils::atomic::AtomicCell; use std::io::{Read, Write}; diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index ea76b38afc..83de9a59e4 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -11,8 +11,8 @@ mod decl { function::{ArgCallable, FuncArgs, OptionalArg, OptionalOption, PosArgs}, iterator::{call_next, get_iter, get_next_object}, slots::{PyIter, SlotConstructor}, - IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef, StaticType, - TypeProtocol, VirtualMachine, + IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef, TypeProtocol, + VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use num_bigint::BigInt; diff --git a/vm/src/stdlib/json.rs b/vm/src/stdlib/json.rs index 417f0656ef..29f908abc0 100644 --- a/vm/src/stdlib/json.rs +++ b/vm/src/stdlib/json.rs @@ -10,7 +10,7 @@ mod _json { function::{FuncArgs, OptionalArg}, iterator, slots::{Callable, SlotConstructor}, - IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, + IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, }; use num_bigint::BigInt; diff --git a/vm/src/stdlib/operator.rs b/vm/src/stdlib/operator.rs index 9ede7ea2a2..0c815a0cea 100644 --- a/vm/src/stdlib/operator.rs +++ b/vm/src/stdlib/operator.rs @@ -22,8 +22,8 @@ mod _operator { }, utils::Either, vm::ReprGuard, - IdProtocol, ItemProtocol, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryIntoRef, - TypeProtocol, VirtualMachine, + IdProtocol, ItemProtocol, PyObjectRef, PyRef, PyResult, PyValue, TryIntoRef, TypeProtocol, + VirtualMachine, }; /// Same as a < b. diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 15f1e5ccfd..af0427c33c 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -378,7 +378,7 @@ pub(super) mod _os { suppress_iph, utils::Either, vm::{ReprGuard, VirtualMachine}, - IntoPyObject, PyObjectRef, PyRef, PyResult, PyStructSequence, PyValue, StaticType, + IntoPyObject, PyObjectRef, PyRef, PyResult, PyStructSequence, PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol, }; use crossbeam_utils::atomic::AtomicCell; diff --git a/vm/src/stdlib/posix.rs b/vm/src/stdlib/posix.rs index d8271541d9..87c0f5da7c 100644 --- a/vm/src/stdlib/posix.rs +++ b/vm/src/stdlib/posix.rs @@ -39,8 +39,7 @@ pub mod module { _os, fs_metadata, }, utils::{Either, ToCString}, - IntoPyObject, ItemProtocol, PyObjectRef, PyResult, PyValue, StaticType, TryFromObject, - VirtualMachine, + IntoPyObject, ItemProtocol, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine, }; use bitflags::bitflags; use nix::fcntl; diff --git a/vm/src/stdlib/pyexpat.rs b/vm/src/stdlib/pyexpat.rs index 0d1036ada8..c9fbcc01da 100644 --- a/vm/src/stdlib/pyexpat.rs +++ b/vm/src/stdlib/pyexpat.rs @@ -34,7 +34,6 @@ mod _pyexpat { use crate::builtins::{PyStr, PyStrRef, PyTypeRef}; use crate::byteslike::ArgBytesLike; use crate::function::{IntoFuncArgs, OptionalArg}; - use crate::pyobject::StaticType; use crate::{ ItemProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, diff --git a/vm/src/stdlib/pystruct.rs b/vm/src/stdlib/pystruct.rs index c59ed84af1..45bad49f02 100644 --- a/vm/src/stdlib/pystruct.rs +++ b/vm/src/stdlib/pystruct.rs @@ -22,8 +22,7 @@ pub(crate) mod _struct { function::PosArgs, slots::{PyIter, SlotConstructor}, utils::Either, - IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, - VirtualMachine, + IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use half::f16; diff --git a/vm/src/stdlib/random.rs b/vm/src/stdlib/random.rs index 4e81fbd1e6..5269c12e0a 100644 --- a/vm/src/stdlib/random.rs +++ b/vm/src/stdlib/random.rs @@ -9,7 +9,7 @@ mod _random { builtins::{PyIntRef, PyTypeRef}, function::OptionalOption, slots::SlotConstructor, - PyObjectRef, PyResult, PyValue, StaticType, VirtualMachine, + PyObjectRef, PyResult, PyValue, VirtualMachine, }; use num_bigint::{BigInt, Sign}; use num_traits::{Signed, Zero}; diff --git a/vm/src/stdlib/select.rs b/vm/src/stdlib/select.rs index 85a77f546f..7232c05105 100644 --- a/vm/src/stdlib/select.rs +++ b/vm/src/stdlib/select.rs @@ -252,11 +252,11 @@ mod decl { #[cfg(unix)] pub(super) mod poll { use super::*; - use crate::builtins::{PyFloat, PyTypeRef}; + use crate::builtins::PyFloat; use crate::common::lock::PyMutex; use crate::function::OptionalArg; use crate::stdlib::io::Fildes; - use crate::{IntoPyObject, PyValue, StaticType, TypeProtocol}; + use crate::{IntoPyObject, PyValue, TypeProtocol}; use libc::pollfd; use num_traits::ToPrimitive; use std::time; diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index 6887faa29a..0a79468cc0 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -5,8 +5,8 @@ use crate::{ exceptions::{IntoPyException, PyBaseExceptionRef}, function::{FuncArgs, OptionalArg, OptionalOption}, utils::{Either, ToCString}, - IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, - TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine, + IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject, + TryFromObject, TypeProtocol, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use gethostname::gethostname; diff --git a/vm/src/stdlib/sre.rs b/vm/src/stdlib/sre.rs index dcd70b88d9..f52563911d 100644 --- a/vm/src/stdlib/sre.rs +++ b/vm/src/stdlib/sre.rs @@ -6,13 +6,12 @@ mod _sre { buffer::PyBuffer, builtins::{ PyCallableIterator, PyDictRef, PyInt, PyList, PyListRef, PyStr, PyStrRef, PyTupleRef, - PyTypeRef, }, common::hash::PyHash, function::{ArgCallable, OptionalArg, PosArgs}, slots::{Comparable, Hashable}, IntoPyObject, ItemProtocol, PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, - StaticType, TryFromBorrowedObject, TryFromObject, VirtualMachine, + TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use core::str; use crossbeam_utils::atomic::AtomicCell; diff --git a/vm/src/stdlib/ssl.rs b/vm/src/stdlib/ssl.rs index 2f982ece09..c59fc02f0f 100644 --- a/vm/src/stdlib/ssl.rs +++ b/vm/src/stdlib/ssl.rs @@ -8,8 +8,7 @@ use crate::{ slots::SlotConstructor, stdlib::os::PyPathLike, utils::{Either, ToCString}, - IntoPyObject, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, - VirtualMachine, + IntoPyObject, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use foreign_types_shared::{ForeignType, ForeignTypeRef}; diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index 632134b31c..92278a6f66 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -3,9 +3,9 @@ pub(crate) use decl::make_module; #[pymodule(name = "symtable")] mod decl { use crate::{ - builtins::{PyStrRef, PyTypeRef}, + builtins::PyStrRef, compile::{self, Symbol, SymbolScope, SymbolTable, SymbolTableType}, - PyRef, PyResult, PyValue, StaticType, VirtualMachine, + PyRef, PyResult, PyValue, VirtualMachine, }; use std::fmt; diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index 1cfa3e8a50..aec52abdda 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -7,8 +7,8 @@ use crate::{ py_io, slots::{SlotGetattro, SlotSetattro}, utils::Either, - IdProtocol, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, - TypeProtocol, VirtualMachine, + IdProtocol, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, + VirtualMachine, }; use parking_lot::{ lock_api::{RawMutex as RawMutexT, RawMutexTimed, RawReentrantMutex}, diff --git a/vm/src/stdlib/unicodedata.rs b/vm/src/stdlib/unicodedata.rs index 61195d0791..b75e943a7e 100644 --- a/vm/src/stdlib/unicodedata.rs +++ b/vm/src/stdlib/unicodedata.rs @@ -3,9 +3,8 @@ */ use crate::{ - builtins::{PyStrRef, PyTypeRef}, - function::OptionalArg, - PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue, StaticType, VirtualMachine, + builtins::PyStrRef, function::OptionalArg, PyClassImpl, PyObject, PyObjectRef, PyResult, + PyValue, VirtualMachine, }; use itertools::Itertools; use unic_char_property::EnumeratedCharProperty; diff --git a/vm/src/stdlib/winreg.rs b/vm/src/stdlib/winreg.rs index d1793acbc1..14ad4efde2 100644 --- a/vm/src/stdlib/winreg.rs +++ b/vm/src/stdlib/winreg.rs @@ -4,7 +4,7 @@ use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crate::{ builtins::{PyStrRef, PyTypeRef}, exceptions::IntoPyException, - PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, VirtualMachine, + PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine, }; use std::convert::TryInto; use std::ffi::OsStr; diff --git a/vm/src/stdlib/zlib.rs b/vm/src/stdlib/zlib.rs index 4b5e15815b..6697a46ec4 100644 --- a/vm/src/stdlib/zlib.rs +++ b/vm/src/stdlib/zlib.rs @@ -9,7 +9,7 @@ mod decl { exceptions::PyBaseExceptionRef, function::OptionalArg, types::create_simple_type, - IntoPyRef, PyResult, PyValue, StaticType, VirtualMachine, + IntoPyRef, PyResult, PyValue, VirtualMachine, }; use adler32::RollingAdler32 as Adler32; use crc32fast::Hasher as Crc32; diff --git a/wasm/lib/src/browser_module.rs b/wasm/lib/src/browser_module.rs index 04d2a6e2f9..e69d0ed3cb 100644 --- a/wasm/lib/src/browser_module.rs +++ b/wasm/lib/src/browser_module.rs @@ -3,11 +3,11 @@ use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; use wasm_bindgen_futures::JsFuture; -use rustpython_vm::builtins::{PyDictRef, PyStrRef, PyTypeRef}; +use rustpython_vm::builtins::{PyDictRef, PyStrRef}; use rustpython_vm::function::{ArgCallable, OptionalArg}; use rustpython_vm::import::import_file; use rustpython_vm::{ - IntoPyObject, PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue, StaticType, VirtualMachine, + IntoPyObject, PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue, VirtualMachine, }; use crate::{convert, js_module::PyPromise, vm_class::weak_vm, wasm_builtins::window}; diff --git a/wasm/lib/src/js_module.rs b/wasm/lib/src/js_module.rs index 54b4376f34..676e5e603a 100644 --- a/wasm/lib/src/js_module.rs +++ b/wasm/lib/src/js_module.rs @@ -14,7 +14,7 @@ use rustpython_vm::types::create_simple_type; use rustpython_vm::VirtualMachine; use rustpython_vm::{ function::ArgCallable, IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, - StaticType, TryFromObject, + TryFromObject, }; #[wasm_bindgen(inline_js = "