Skip to content

Commit 520c965

Browse files
committed
remove unsed slots
1 parent 882e6d0 commit 520c965

File tree

4 files changed

+13
-463
lines changed

4 files changed

+13
-463
lines changed

crates/vm/src/builtins/bool.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ impl PyBool {
126126
.and_then(|format_spec| format_spec.format_bool(new_bool))
127127
.map_err(|err| err.into_pyexception(vm))
128128
}
129+
}
129130

130-
#[pymethod(name = "__ror__")]
131-
#[pymethod]
132-
fn __or__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
131+
impl PyBool {
132+
// Called from AsNumber slots, exposed as wrapper_descriptor
133+
pub(crate) fn __or__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
133134
if lhs.fast_isinstance(vm.ctx.types.bool_type)
134135
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
135136
{
@@ -143,9 +144,7 @@ impl PyBool {
143144
}
144145
}
145146

146-
#[pymethod(name = "__rand__")]
147-
#[pymethod]
148-
fn __and__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
147+
pub(crate) fn __and__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
149148
if lhs.fast_isinstance(vm.ctx.types.bool_type)
150149
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
151150
{
@@ -159,9 +158,7 @@ impl PyBool {
159158
}
160159
}
161160

162-
#[pymethod(name = "__rxor__")]
163-
#[pymethod]
164-
fn __xor__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
161+
pub(crate) fn __xor__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
165162
if lhs.fast_isinstance(vm.ctx.types.bool_type)
166163
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
167164
{

crates/vm/src/builtins/complex.rs

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -268,133 +268,11 @@ impl PyComplex {
268268
self.value.im
269269
}
270270

271-
#[pymethod]
272-
fn __abs__(&self, vm: &VirtualMachine) -> PyResult<f64> {
273-
let Complex64 { im, re } = self.value;
274-
let is_finite = im.is_finite() && re.is_finite();
275-
let abs_result = re.hypot(im);
276-
if is_finite && abs_result.is_infinite() {
277-
Err(vm.new_overflow_error("absolute value too large"))
278-
} else {
279-
Ok(abs_result)
280-
}
281-
}
282-
283-
#[inline]
284-
fn op<F>(
285-
&self,
286-
other: PyObjectRef,
287-
op: F,
288-
vm: &VirtualMachine,
289-
) -> PyResult<PyArithmeticValue<Complex64>>
290-
where
291-
F: Fn(Complex64, Complex64) -> PyResult<Complex64>,
292-
{
293-
to_op_complex(&other, vm)?.map_or_else(
294-
|| Ok(NotImplemented),
295-
|other| Ok(Implemented(op(self.value, other)?)),
296-
)
297-
}
298-
299-
#[pymethod(name = "__radd__")]
300-
#[pymethod]
301-
fn __add__(
302-
&self,
303-
other: PyObjectRef,
304-
vm: &VirtualMachine,
305-
) -> PyResult<PyArithmeticValue<Complex64>> {
306-
self.op(other, |a, b| Ok(a + b), vm)
307-
}
308-
309-
#[pymethod]
310-
fn __sub__(
311-
&self,
312-
other: PyObjectRef,
313-
vm: &VirtualMachine,
314-
) -> PyResult<PyArithmeticValue<Complex64>> {
315-
self.op(other, |a, b| Ok(a - b), vm)
316-
}
317-
318-
#[pymethod]
319-
fn __rsub__(
320-
&self,
321-
other: PyObjectRef,
322-
vm: &VirtualMachine,
323-
) -> PyResult<PyArithmeticValue<Complex64>> {
324-
self.op(other, |a, b| Ok(b - a), vm)
325-
}
326-
327271
#[pymethod]
328272
fn conjugate(&self) -> Complex64 {
329273
self.value.conj()
330274
}
331275

332-
#[pymethod(name = "__rmul__")]
333-
#[pymethod]
334-
fn __mul__(
335-
&self,
336-
other: PyObjectRef,
337-
vm: &VirtualMachine,
338-
) -> PyResult<PyArithmeticValue<Complex64>> {
339-
self.op(other, |a, b| Ok(a * b), vm)
340-
}
341-
342-
#[pymethod]
343-
fn __truediv__(
344-
&self,
345-
other: PyObjectRef,
346-
vm: &VirtualMachine,
347-
) -> PyResult<PyArithmeticValue<Complex64>> {
348-
self.op(other, |a, b| inner_div(a, b, vm), vm)
349-
}
350-
351-
#[pymethod]
352-
fn __rtruediv__(
353-
&self,
354-
other: PyObjectRef,
355-
vm: &VirtualMachine,
356-
) -> PyResult<PyArithmeticValue<Complex64>> {
357-
self.op(other, |a, b| inner_div(b, a, vm), vm)
358-
}
359-
360-
#[pymethod]
361-
const fn __pos__(&self) -> Complex64 {
362-
self.value
363-
}
364-
365-
#[pymethod]
366-
fn __neg__(&self) -> Complex64 {
367-
-self.value
368-
}
369-
370-
#[pymethod]
371-
fn __pow__(
372-
&self,
373-
other: PyObjectRef,
374-
mod_val: OptionalOption<PyObjectRef>,
375-
vm: &VirtualMachine,
376-
) -> PyResult<PyArithmeticValue<Complex64>> {
377-
if mod_val.flatten().is_some() {
378-
Err(vm.new_value_error("complex modulo not allowed"))
379-
} else {
380-
self.op(other, |a, b| inner_pow(a, b, vm), vm)
381-
}
382-
}
383-
384-
#[pymethod]
385-
fn __rpow__(
386-
&self,
387-
other: PyObjectRef,
388-
vm: &VirtualMachine,
389-
) -> PyResult<PyArithmeticValue<Complex64>> {
390-
self.op(other, |a, b| inner_pow(b, a, vm), vm)
391-
}
392-
393-
#[pymethod]
394-
fn __bool__(&self) -> bool {
395-
!Complex64::is_zero(&self.value)
396-
}
397-
398276
#[pymethod]
399277
const fn __getnewargs__(&self) -> (f64, f64) {
400278
let Complex64 { re, im } = self.value;

crates/vm/src/builtins/float.rs

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -239,182 +239,6 @@ impl PyFloat {
239239
.to_owned())
240240
}
241241

242-
#[pymethod]
243-
const fn __abs__(&self) -> f64 {
244-
self.value.abs()
245-
}
246-
247-
#[inline]
248-
fn simple_op<F>(
249-
&self,
250-
other: PyObjectRef,
251-
op: F,
252-
vm: &VirtualMachine,
253-
) -> PyResult<PyArithmeticValue<f64>>
254-
where
255-
F: Fn(f64, f64) -> PyResult<f64>,
256-
{
257-
to_op_float(&other, vm)?.map_or_else(
258-
|| Ok(NotImplemented),
259-
|other| Ok(Implemented(op(self.value, other)?)),
260-
)
261-
}
262-
263-
#[inline]
264-
fn complex_op<F>(&self, other: PyObjectRef, op: F, vm: &VirtualMachine) -> PyResult
265-
where
266-
F: Fn(f64, f64) -> PyResult,
267-
{
268-
to_op_float(&other, vm)?.map_or_else(
269-
|| Ok(vm.ctx.not_implemented()),
270-
|other| op(self.value, other),
271-
)
272-
}
273-
274-
#[inline]
275-
fn tuple_op<F>(
276-
&self,
277-
other: PyObjectRef,
278-
op: F,
279-
vm: &VirtualMachine,
280-
) -> PyResult<PyArithmeticValue<(f64, f64)>>
281-
where
282-
F: Fn(f64, f64) -> PyResult<(f64, f64)>,
283-
{
284-
to_op_float(&other, vm)?.map_or_else(
285-
|| Ok(NotImplemented),
286-
|other| Ok(Implemented(op(self.value, other)?)),
287-
)
288-
}
289-
290-
#[pymethod(name = "__radd__")]
291-
#[pymethod]
292-
fn __add__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<f64>> {
293-
self.simple_op(other, |a, b| Ok(a + b), vm)
294-
}
295-
296-
#[pymethod]
297-
const fn __bool__(&self) -> bool {
298-
self.value != 0.0
299-
}
300-
301-
#[pymethod]
302-
fn __divmod__(
303-
&self,
304-
other: PyObjectRef,
305-
vm: &VirtualMachine,
306-
) -> PyResult<PyArithmeticValue<(f64, f64)>> {
307-
self.tuple_op(other, |a, b| inner_divmod(a, b, vm), vm)
308-
}
309-
310-
#[pymethod]
311-
fn __rdivmod__(
312-
&self,
313-
other: PyObjectRef,
314-
vm: &VirtualMachine,
315-
) -> PyResult<PyArithmeticValue<(f64, f64)>> {
316-
self.tuple_op(other, |a, b| inner_divmod(b, a, vm), vm)
317-
}
318-
319-
#[pymethod]
320-
fn __floordiv__(
321-
&self,
322-
other: PyObjectRef,
323-
vm: &VirtualMachine,
324-
) -> PyResult<PyArithmeticValue<f64>> {
325-
self.simple_op(other, |a, b| inner_floordiv(a, b, vm), vm)
326-
}
327-
328-
#[pymethod]
329-
fn __rfloordiv__(
330-
&self,
331-
other: PyObjectRef,
332-
vm: &VirtualMachine,
333-
) -> PyResult<PyArithmeticValue<f64>> {
334-
self.simple_op(other, |a, b| inner_floordiv(b, a, vm), vm)
335-
}
336-
337-
#[pymethod(name = "__mod__")]
338-
fn mod_(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<f64>> {
339-
self.simple_op(other, |a, b| inner_mod(a, b, vm), vm)
340-
}
341-
342-
#[pymethod]
343-
fn __rmod__(
344-
&self,
345-
other: PyObjectRef,
346-
vm: &VirtualMachine,
347-
) -> PyResult<PyArithmeticValue<f64>> {
348-
self.simple_op(other, |a, b| inner_mod(b, a, vm), vm)
349-
}
350-
351-
#[pymethod]
352-
const fn __pos__(&self) -> f64 {
353-
self.value
354-
}
355-
356-
#[pymethod]
357-
const fn __neg__(&self) -> f64 {
358-
-self.value
359-
}
360-
361-
#[pymethod]
362-
fn __pow__(
363-
&self,
364-
other: PyObjectRef,
365-
mod_val: OptionalOption<PyObjectRef>,
366-
vm: &VirtualMachine,
367-
) -> PyResult {
368-
if mod_val.flatten().is_some() {
369-
Err(vm.new_type_error("floating point pow() does not accept a 3rd argument"))
370-
} else {
371-
self.complex_op(other, |a, b| float_pow(a, b, vm), vm)
372-
}
373-
}
374-
375-
#[pymethod]
376-
fn __rpow__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
377-
self.complex_op(other, |a, b| float_pow(b, a, vm), vm)
378-
}
379-
380-
#[pymethod]
381-
fn __sub__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<f64>> {
382-
self.simple_op(other, |a, b| Ok(a - b), vm)
383-
}
384-
385-
#[pymethod]
386-
fn __rsub__(
387-
&self,
388-
other: PyObjectRef,
389-
vm: &VirtualMachine,
390-
) -> PyResult<PyArithmeticValue<f64>> {
391-
self.simple_op(other, |a, b| Ok(b - a), vm)
392-
}
393-
394-
#[pymethod]
395-
fn __truediv__(
396-
&self,
397-
other: PyObjectRef,
398-
vm: &VirtualMachine,
399-
) -> PyResult<PyArithmeticValue<f64>> {
400-
self.simple_op(other, |a, b| inner_div(a, b, vm), vm)
401-
}
402-
403-
#[pymethod]
404-
fn __rtruediv__(
405-
&self,
406-
other: PyObjectRef,
407-
vm: &VirtualMachine,
408-
) -> PyResult<PyArithmeticValue<f64>> {
409-
self.simple_op(other, |a, b| inner_div(b, a, vm), vm)
410-
}
411-
412-
#[pymethod(name = "__rmul__")]
413-
#[pymethod]
414-
fn __mul__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<f64>> {
415-
self.simple_op(other, |a, b| Ok(a * b), vm)
416-
}
417-
418242
#[pymethod]
419243
fn __trunc__(&self, vm: &VirtualMachine) -> PyResult<BigInt> {
420244
try_to_bigint(self.value, vm)
@@ -460,16 +284,6 @@ impl PyFloat {
460284
Ok(value)
461285
}
462286

463-
#[pymethod]
464-
fn __int__(&self, vm: &VirtualMachine) -> PyResult<BigInt> {
465-
self.__trunc__(vm)
466-
}
467-
468-
#[pymethod]
469-
const fn __float__(zelf: PyRef<Self>) -> PyRef<Self> {
470-
zelf
471-
}
472-
473287
#[pygetset]
474288
const fn real(zelf: PyRef<Self>) -> PyRef<Self> {
475289
zelf

0 commit comments

Comments
 (0)