From e5142e36fd0b4aac1090bbd31dec656a72127231 Mon Sep 17 00:00:00 2001 From: Hyunmin Shin Date: Thu, 28 Jul 2022 02:31:51 +0900 Subject: [PATCH 1/2] Update _mut_iter_equal_skeleton method --- vm/src/sequence.rs | 103 +++------------------------------------------ 1 file changed, 5 insertions(+), 98 deletions(-) diff --git a/vm/src/sequence.rs b/vm/src/sequence.rs index dc7a3b86e..2ed07b62c 100644 --- a/vm/src/sequence.rs +++ b/vm/src/sequence.rs @@ -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; @@ -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; @@ -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 elem = elem.clone(); + drop(guard); - 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 { - 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 { - 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 - } - } - } - }; - - if eq { + if elem.rich_compare_bool(needle, PyComparisonOp::Eq, vm)? { f(); if SHORT { break Optioned::::some(i); From a6780040c8ef7529c62a30f6e18760ad3c6fdd43 Mon Sep 17 00:00:00 2001 From: Hyunmin Shin Date: Fri, 29 Jul 2022 21:24:19 +0900 Subject: [PATCH 2/2] Update test_{list, deque, userlist}.py --- Lib/test/list_tests.py | 4 ---- Lib/test/test_deque.py | 15 --------------- Lib/test/test_list.py | 10 ---------- Lib/test/test_userlist.py | 10 ---------- 4 files changed, 39 deletions(-) diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py index 65a5118e4..0e11af6f3 100644 --- a/Lib/test/list_tests.py +++ b/Lib/test/list_tests.py @@ -304,8 +304,6 @@ class CommonTest(seq_tests.CommonTest): 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) @@ -365,8 +363,6 @@ class CommonTest(seq_tests.CommonTest): # 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]) diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 34729e734..0cf3a3663 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -929,21 +929,6 @@ class TestSequence(seq_tests.CommonTest): # 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 = """ diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index 419eb945b..ee96f64a0 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -231,15 +231,5 @@ class ListTest(list_tests.CommonTest): 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() diff --git a/Lib/test/test_userlist.py b/Lib/test/test_userlist.py index 63f47f572..f49930cbb 100644 --- a/Lib/test/test_userlist.py +++ b/Lib/test/test_userlist.py @@ -7,16 +7,6 @@ import unittest 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