Skip to content

Commit 7ea52cb

Browse files
authored
Merge pull request RustPython#3110 from youknowone/use-regroup
Group use for vm stuff to prevent reorder for rustpython_stdlib
2 parents f357a95 + 137a543 commit 7ea52cb

51 files changed

Lines changed: 324 additions & 407 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

vm/src/builtins/module.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use crate::{
1010

1111
#[pyclass(module = false, name = "module")]
1212
#[derive(Debug)]
13-
pub struct PyModule {}
14-
pub type PyModuleRef = PyRef<PyModule>;
13+
pub struct PyModule;
1514

1615
impl PyValue for PyModule {
1716
fn class(vm: &VirtualMachine) -> &PyTypeRef {

vm/src/stdlib/array.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,27 @@ pub(crate) use array::make_module;
22

33
#[pymodule(name = "array")]
44
mod array {
5-
use crate::buffer::{BufferOptions, PyBuffer, PyBufferInternal, ResizeGuard};
6-
use crate::builtins::list::{PyList, PyListRef};
7-
use crate::builtins::pystr::{PyStr, PyStrRef};
8-
use crate::builtins::pytype::PyTypeRef;
9-
use crate::builtins::slice::PySliceRef;
10-
use crate::builtins::IntoPyFloat;
11-
use crate::builtins::{PyByteArray, PyBytes, PyBytesRef, PyIntRef};
12-
use crate::byteslike::ArgBytesLike;
13-
use crate::common::borrow::{BorrowedValue, BorrowedValueMut};
14-
use crate::common::lock::{
15-
PyMappedRwLockReadGuard, PyMappedRwLockWriteGuard, PyRwLock, PyRwLockReadGuard,
16-
PyRwLockWriteGuard,
5+
use crate::common::{
6+
borrow::{BorrowedValue, BorrowedValueMut},
7+
lock::{
8+
PyMappedRwLockReadGuard, PyMappedRwLockWriteGuard, PyRwLock, PyRwLockReadGuard,
9+
PyRwLockWriteGuard,
10+
},
11+
str::wchar_t,
1712
};
18-
use crate::common::str::wchar_t;
19-
use crate::function::OptionalArg;
20-
use crate::sliceable::{
21-
saturate_index, PySliceableSequence, PySliceableSequenceMut, SequenceIndex,
22-
};
23-
use crate::slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter, SlotConstructor};
2413
use crate::{
25-
IdProtocol, IntoPyObject, PyComparisonValue, PyIterable, PyObjectRef, PyRef, PyResult,
26-
PyValue, StaticType, TryFromObject, TypeProtocol,
14+
buffer::{BufferOptions, PyBuffer, PyBufferInternal, ResizeGuard},
15+
builtins::{
16+
IntoPyFloat, PyByteArray, PyBytes, PyBytesRef, PyIntRef, PyList, PyListRef, PySliceRef,
17+
PyStr, PyStrRef, PyTypeRef,
18+
},
19+
byteslike::ArgBytesLike,
20+
function::OptionalArg,
21+
sliceable::{saturate_index, PySliceableSequence, PySliceableSequenceMut, SequenceIndex},
22+
slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter, SlotConstructor},
23+
IdProtocol, IntoPyObject, IntoPyResult, PyComparisonValue, PyIterable, PyObjectRef, PyRef,
24+
PyResult, PyValue, StaticType, TryFromObject, TypeProtocol, VirtualMachine,
2725
};
28-
use crate::{IntoPyResult, VirtualMachine};
2926
use crossbeam_utils::atomic::AtomicCell;
3027
use itertools::Itertools;
3128
use lexical_core::Integer;

vm/src/stdlib/ast.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
//! This module makes use of the parser logic, and translates all ast nodes
44
//! into python ast.AST objects.
55
6+
use crate::{
7+
builtins::{self, PyStrRef, PyTypeRef},
8+
function::FuncArgs,
9+
IdProtocol, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyResult, PyValue, StaticType,
10+
TryFromObject, TypeProtocol, VirtualMachine,
11+
};
612
use num_complex::Complex64;
713
use num_traits::{ToPrimitive, Zero};
8-
914
use rustpython_ast as ast;
10-
11-
#[cfg(feature = "rustpython-parser")]
12-
use rustpython_parser::parser;
13-
1415
#[cfg(feature = "rustpython-compiler")]
1516
use rustpython_compiler as compile;
16-
17-
use crate::builtins::{self, PyStrRef, PyTypeRef};
18-
use crate::function::FuncArgs;
19-
use crate::vm::VirtualMachine;
20-
use crate::{
21-
IdProtocol, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyResult, PyValue, StaticType,
22-
TryFromObject, TypeProtocol,
23-
};
17+
#[cfg(feature = "rustpython-parser")]
18+
use rustpython_parser::parser;
2419

2520
#[rustfmt::skip]
2621
#[allow(clippy::all)]

vm/src/stdlib/atexit.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ pub(crate) use atexit::make_module;
22

33
#[pymodule]
44
mod atexit {
5-
use crate::function::FuncArgs;
6-
use crate::VirtualMachine;
7-
use crate::{PyObjectRef, PyResult};
5+
use crate::{function::FuncArgs, PyObjectRef, PyResult, VirtualMachine};
86

97
#[pyfunction]
108
fn register(func: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyObjectRef {

vm/src/stdlib/binascii.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ pub(crate) use decl::make_module;
22

33
#[pymodule(name = "binascii")]
44
mod decl {
5-
use crate::builtins::bytearray::{PyByteArray, PyByteArrayRef};
6-
use crate::builtins::bytes::{PyBytes, PyBytesRef};
7-
use crate::builtins::pystr::{PyStr, PyStrRef};
8-
use crate::builtins::PyTypeRef;
9-
use crate::byteslike::ArgBytesLike;
10-
use crate::function::OptionalArg;
11-
use crate::vm::VirtualMachine;
12-
use crate::{PyObjectRef, PyResult, TryFromObject, TypeProtocol};
5+
use crate::{
6+
builtins::{PyByteArray, PyBytes, PyStr, PyTypeRef},
7+
byteslike::ArgBytesLike,
8+
function::OptionalArg,
9+
PyObjectRef, PyRef, PyResult, TryFromObject, TypeProtocol, VirtualMachine,
10+
};
1311
use crc::{crc32, Hasher32};
1412
use itertools::Itertools;
1513

1614
enum SerializedData {
17-
Bytes(PyBytesRef),
18-
Buffer(PyByteArrayRef),
19-
Ascii(PyStrRef),
15+
Bytes(PyRef<PyBytes>),
16+
Buffer(PyRef<PyByteArray>),
17+
Ascii(PyRef<PyStr>),
2018
}
2119

2220
impl TryFromObject for SerializedData {

vm/src/stdlib/bisect.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ pub(crate) use _bisect::make_module;
22

33
#[pymodule]
44
mod _bisect {
5-
use std::convert::TryFrom;
6-
7-
use crate::function::OptionalArg;
8-
use crate::slots::PyComparisonOp::Lt;
9-
use crate::vm::VirtualMachine;
10-
use crate::{ItemProtocol, PyObjectRef, PyResult};
5+
use crate::{
6+
function::OptionalArg, slots::PyComparisonOp::Lt, ItemProtocol, PyObjectRef, PyResult,
7+
VirtualMachine,
8+
};
119
use num_traits::ToPrimitive;
10+
use std::convert::TryFrom;
1211

1312
#[derive(FromArgs)]
1413
struct BisectArgs {

vm/src/stdlib/cmath.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
2222
/// This module provides access to mathematical functions for complex numbers.
2323
#[pymodule]
2424
mod cmath {
25-
use crate::builtins::{IntoPyComplex, IntoPyFloat};
26-
use crate::function::OptionalArg;
27-
use crate::{PyResult, VirtualMachine};
25+
use crate::{
26+
builtins::{IntoPyComplex, IntoPyFloat},
27+
function::OptionalArg,
28+
PyResult, VirtualMachine,
29+
};
2830
use num_complex::Complex64;
2931

3032
/// Return argument, also known as the phase angle, of a complex.

vm/src/stdlib/codecs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ pub(crate) use _codecs::make_module;
22

33
#[pymodule]
44
mod _codecs {
5-
use std::ops::Range;
6-
7-
use crate::builtins::{PyBytesRef, PyStr, PyStrRef, PyTuple};
8-
use crate::byteslike::ArgBytesLike;
9-
use crate::codecs;
105
use crate::common::encodings;
11-
use crate::exceptions::PyBaseExceptionRef;
12-
use crate::function::FuncArgs;
13-
use crate::VirtualMachine;
14-
use crate::{IdProtocol, PyObjectRef, PyResult, TryFromBorrowedObject};
6+
use crate::{
7+
builtins::{PyBytesRef, PyStr, PyStrRef, PyTuple},
8+
byteslike::ArgBytesLike,
9+
codecs,
10+
exceptions::PyBaseExceptionRef,
11+
function::FuncArgs,
12+
IdProtocol, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine,
13+
};
14+
use std::ops::Range;
1515

1616
#[pyfunction]
1717
fn register(search_function: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {

vm/src/stdlib/collections.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ pub(crate) use _collections::make_module;
33
#[pymodule]
44
mod _collections {
55
use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard};
6-
use crate::function::{FuncArgs, KwArgs, OptionalArg};
7-
use crate::slots::{
8-
Comparable, Hashable, Iterable, PyComparisonOp, PyIter, SlotConstructor, Unhashable,
9-
};
10-
use crate::vm::ReprGuard;
11-
use crate::VirtualMachine;
126
use crate::{
137
builtins::{
148
IterStatus::{self, Active, Exhausted},
159
PyInt, PyTypeRef,
1610
},
17-
TypeProtocol,
11+
function::{FuncArgs, KwArgs, OptionalArg},
12+
sequence, sliceable,
13+
slots::{
14+
Comparable, Hashable, Iterable, PyComparisonOp, PyIter, SlotConstructor, Unhashable,
15+
},
16+
vm::ReprGuard,
17+
PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TypeProtocol,
18+
VirtualMachine,
1819
};
19-
use crate::{sequence, sliceable};
20-
use crate::{PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, StaticType};
2120
use crossbeam_utils::atomic::AtomicCell;
2221
use itertools::Itertools;
2322
use num_traits::ToPrimitive;

vm/src/stdlib/csv.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
use itertools::{self, Itertools};
2-
use std::fmt;
3-
4-
use crate::builtins::pystr::{PyStr, PyStrRef};
5-
use crate::builtins::pytype::PyTypeRef;
61
use crate::common::lock::PyMutex;
7-
use crate::function::{ArgumentError, FromArgs, FuncArgs};
8-
use crate::iterator;
9-
use crate::slots::PyIter;
10-
use crate::types::create_simple_type;
11-
use crate::VirtualMachine;
122
use crate::{
3+
builtins::{PyStr, PyStrRef, PyTypeRef},
4+
function::{ArgumentError, FromArgs, FuncArgs},
5+
iterator,
6+
slots::PyIter,
7+
types::create_simple_type,
138
PyClassImpl, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject,
14-
TypeProtocol,
9+
TypeProtocol, VirtualMachine,
1510
};
11+
use itertools::{self, Itertools};
12+
use std::fmt;
1613

1714
#[repr(i32)]
1815
pub enum QuoteStyle {

0 commit comments

Comments
 (0)