9999import com .oracle .graal .python .lib .PyObjectReprAsTruffleStringNode ;
100100import com .oracle .graal .python .lib .PyObjectSizeNode ;
101101import com .oracle .graal .python .lib .PyObjectStrAsObjectNode ;
102+ import com .oracle .graal .python .lib .PyTupleCheckNode ;
102103import com .oracle .graal .python .nodes .ErrorMessages ;
103104import com .oracle .graal .python .nodes .PGuards ;
104105import com .oracle .graal .python .nodes .PRaiseNode ;
@@ -603,6 +604,10 @@ private int getHashingStorageLength(HashingStorage storage) {
603604 return hashingStorageLenNode .executeCached (storage );
604605 }
605606
607+ private boolean isTuple (Object object ) {
608+ return PyTupleCheckNode .executeUncached (object );
609+ }
610+
606611 private void save (VirtualFrame frame , PPickler pickler , Object obj , int persSave ) {
607612 if (recursiveSaveNode == null ) {
608613 CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -787,7 +792,7 @@ private void saveIteratorBatchedUnrolled(VirtualFrame frame, PPickler pickler, O
787792 private void saveDictIteratorBatchUnrolled (VirtualFrame frame , PPickler pickler , Object iterator ) {
788793 saveIteratorBatchedUnrolled (frame , pickler , iterator , PickleUtils .OPCODE_SETITEM , PickleUtils .OPCODE_SETITEMS ,
789794 (Object item ) -> {
790- if (!(item instanceof PTuple ) || length (frame , item ) != 2 ) {
795+ if (!isTuple (item ) || length (frame , item ) != 2 ) {
791796 throw raise (TypeError , ErrorMessages .MUST_S_ITER_RETURN_2TUPLE , DICT_ITEMS );
792797 }
793798 },
@@ -832,7 +837,7 @@ private void saveFrozenSetIterator(VirtualFrame frame, PPickler pickler, Object
832837 private void saveDictIterator (VirtualFrame frame , PPickler pickler , Object iterator ) {
833838 saveIterator (frame , pickler , iterator , PickleUtils .OPCODE_SETITEM ,
834839 (Object item ) -> {
835- if (!(item instanceof PTuple ) || length (frame , item ) != 2 ) {
840+ if (!isTuple (item ) || length (frame , item ) != 2 ) {
836841 throw raise (TypeError , ErrorMessages .MUST_S_ITER_RETURN_2TUPLE , DICT_ITEMS );
837842 }
838843 save (frame , pickler , getItem (frame , item , 0 ), 0 );
@@ -945,7 +950,7 @@ private void handleReduce(VirtualFrame frame, BoundaryCallData boundaryCallData,
945950 return ;
946951 }
947952
948- if (!(reduceValue instanceof PTuple )) {
953+ if (!isTuple (reduceValue )) {
949954 throw raise (PicklingError , ErrorMessages .S_MUST_RETURN_S_OR_S , T___REDUCE__ , "string" , "tuple" );
950955 }
951956
@@ -958,7 +963,7 @@ private void saveReduce(VirtualFrame frame, PythonContext ctx, PPickler pickler,
958963
959964 boolean useNewobj = false , useNewobjEx = false ;
960965
961- if (!(arguments instanceof PTuple )) {
966+ if (!isTuple (arguments )) {
962967 throw raise (PythonBuiltinClassType .SystemError , ErrorMessages .BAD_ARG_TO_INTERNAL_FUNC );
963968 }
964969 int size = length (frame , arguments );
@@ -977,7 +982,7 @@ private void saveReduce(VirtualFrame frame, PythonContext ctx, PPickler pickler,
977982 throw raise (PicklingError , ErrorMessages .S_ITEM_REDUCE_MUST_BE_S , "first" , "callable" );
978983 }
979984
980- if (!(argtup instanceof PTuple )) {
985+ if (!isTuple (argtup )) {
981986 throw raise (PicklingError , ErrorMessages .S_ITEM_REDUCE_MUST_BE_S , "second" , "a tuple" );
982987 }
983988
@@ -1033,7 +1038,7 @@ private void saveReduce(VirtualFrame frame, PythonContext ctx, PPickler pickler,
10331038 }
10341039
10351040 args = getItem (frame , argtup , 1 );
1036- if (!(args instanceof PTuple )) {
1041+ if (!isTuple (args )) {
10371042 throw raise (PicklingError , ErrorMessages .S_ITEM_FROM_S_MUST_BE_S_NOT_P , "second" , "NEWOBJ_EX" , "a tuple" , args );
10381043 }
10391044
0 commit comments