Skip to content

Update _mut_iter_equal_skeleton method #3968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Lib/test/list_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ def test_pop(self):
self.assertRaises(TypeError, a.pop, 42, 42)
a = self.type2test([0, 10, 20, 30, 40])

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_remove(self):
a = self.type2test([0, 0, 1])
a.remove(1)
Expand Down Expand Up @@ -365,8 +363,6 @@ def __eq__(self, other):
# verify that original order and values are retained.
self.assertIs(x, y)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_index(self):
super().test_index()
a = self.type2test([-2, -1, 0, 0, 1, 2])
Expand Down
15 changes: 0 additions & 15 deletions Lib/test/test_deque.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,21 +929,6 @@ def test_free_after_iterating(self):
# For now, bypass tests that require slicing
self.skipTest("Exhausted deque iterator doesn't free a deque")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_contains_fake(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_contains_fake()

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_count(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_count()

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_index(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_index()

#==============================================================================

libreftest = """
Expand Down
10 changes: 0 additions & 10 deletions Lib/test/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,5 @@ def __eq__(self, other):
lst = [X(), X()]
X() in lst

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_count(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_count()

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_contains_fake(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_contains_fake()

if __name__ == "__main__":
unittest.main()
10 changes: 0 additions & 10 deletions Lib/test/test_userlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
class UserListTest(list_tests.CommonTest):
type2test = UserList

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_contains_fake(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_contains_fake()

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_count(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_count()

import sys
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, unexpectedly panics somewhere")
def test_repr_deep(self): # XXX: RUSTPYTHON; remove this method when fixed
Expand Down
103 changes: 5 additions & 98 deletions vm/src/sequence.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use crate::{
builtins::PyIntRef,
function::{Either, OptionalArg, PyComparisonValue},
sliceable::SequenceIndexOp,
types::{richcompare_wrapper, PyComparisonOp, RichCompareFunc},
vm::VirtualMachine,
AsObject, PyObject, PyObjectRef, PyResult,
builtins::PyIntRef, function::OptionalArg, sliceable::SequenceIndexOp, types::PyComparisonOp,
vm::VirtualMachine, AsObject, PyObject, PyObjectRef, PyResult,
};
use optional::Optioned;
use std::ops::Range;
Expand Down Expand Up @@ -50,11 +46,6 @@ pub trait MutObjectSequenceOp<'a> {
where
F: FnMut(),
{
let needle_cls = needle.class();
let needle_cmp = needle_cls
.mro_find_map(|cls| cls.slots.richcompare.load())
.unwrap();

let mut borrower = None;
let mut i = range.start;

Expand All @@ -81,94 +72,10 @@ pub trait MutObjectSequenceOp<'a> {
}
borrower = Some(guard);
} else {
let elem_cls = elem.class();
let reverse_first =
!elem_cls.is(&needle_cls) && elem_cls.fast_issubclass(&needle_cls);

let eq = if reverse_first {
let elem_cmp = elem_cls
.mro_find_map(|cls| cls.slots.richcompare.load())
.unwrap();
drop(elem_cls);

fn cmp(
elem: &PyObject,
needle: &PyObject,
elem_cmp: RichCompareFunc,
needle_cmp: RichCompareFunc,
vm: &VirtualMachine,
) -> PyResult<bool> {
match elem_cmp(elem, needle, PyComparisonOp::Eq, vm)? {
Either::B(PyComparisonValue::Implemented(value)) => Ok(value),
Either::A(obj) if !obj.is(&vm.ctx.not_implemented) => {
obj.try_to_bool(vm)
}
_ => match needle_cmp(needle, elem, PyComparisonOp::Eq, vm)? {
Either::B(PyComparisonValue::Implemented(value)) => Ok(value),
Either::A(obj) if !obj.is(&vm.ctx.not_implemented) => {
obj.try_to_bool(vm)
}
_ => Ok(false),
},
}
}

if elem_cmp as usize == richcompare_wrapper as usize {
let elem = elem.clone();
drop(guard);
cmp(&elem, needle, elem_cmp, needle_cmp, vm)?
} else {
let eq = cmp(elem, needle, elem_cmp, needle_cmp, vm)?;
borrower = Some(guard);
eq
}
} else {
match needle_cmp(needle, elem, PyComparisonOp::Eq, vm)? {
Either::B(PyComparisonValue::Implemented(value)) => {
drop(elem_cls);
borrower = Some(guard);
value
}
Either::A(obj) if !obj.is(&vm.ctx.not_implemented) => {
drop(elem_cls);
borrower = Some(guard);
obj.try_to_bool(vm)?
}
_ => {
let elem_cmp = elem_cls
.mro_find_map(|cls| cls.slots.richcompare.load())
.unwrap();
drop(elem_cls);

fn cmp(
elem: &PyObject,
needle: &PyObject,
elem_cmp: RichCompareFunc,
vm: &VirtualMachine,
) -> PyResult<bool> {
match elem_cmp(elem, needle, PyComparisonOp::Eq, vm)? {
Either::B(PyComparisonValue::Implemented(value)) => Ok(value),
Either::A(obj) if !obj.is(&vm.ctx.not_implemented) => {
obj.try_to_bool(vm)
}
_ => Ok(false),
}
}

if elem_cmp as usize == richcompare_wrapper as usize {
let elem = elem.clone();
drop(guard);
cmp(&elem, needle, elem_cmp, vm)?
} else {
let eq = cmp(elem, needle, elem_cmp, vm)?;
borrower = Some(guard);
eq
}
}
}
};
let elem = elem.clone();
drop(guard);

if eq {
if elem.rich_compare_bool(needle, PyComparisonOp::Eq, vm)? {
f();
if SHORT {
break Optioned::<usize>::some(i);
Expand Down