Skip to content

Commit 19e1794

Browse files
msimacektimfel
authored andcommitted
Remove POL.isSequenceType
1 parent 3a6b091 commit 19e1794

File tree

2 files changed

+9
-34
lines changed

2 files changed

+9
-34
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/DynamicObjectNativeWrapper.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTRIBUTE__;
7070
import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
7171
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INIT__;
72-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__LEN__;
7372
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
7473
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEXT__;
7574
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__;
@@ -139,6 +138,7 @@
139138
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
140139
import com.oracle.graal.python.builtins.objects.type.PythonClass;
141140
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
141+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
142142
import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
143143
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
144144
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
@@ -153,6 +153,7 @@
153153
import com.oracle.graal.python.nodes.SpecialAttributeNames;
154154
import com.oracle.graal.python.nodes.SpecialMethodNames;
155155
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
156+
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
156157
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
157158
import com.oracle.graal.python.nodes.attributes.WriteAttributeToBuiltinTypeNode;
158159
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
@@ -343,7 +344,7 @@ public final Throwable fillInStackTrace() {
343344
}
344345
}
345346

346-
@ImportStatic({NativeMember.class, SpecialMethodNames.class, SpecialAttributeNames.class, PythonOptions.class})
347+
@ImportStatic({NativeMember.class, SpecialMethodNames.class, SpecialAttributeNames.class, PythonOptions.class, SpecialMethodSlot.class})
347348
@TypeSystemReference(PythonArithmeticTypes.class)
348349
abstract static class ReadNativeMemberNode extends Node {
349350

@@ -510,22 +511,23 @@ static Object doTpAsBuffer(PythonManagedClass object, @SuppressWarnings("unused"
510511

511512
@Specialization(guards = "eq(TP_AS_SEQUENCE, key)")
512513
static Object doTpAsSequence(PythonManagedClass object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key,
513-
@Cached LookupAttributeInMRONode.Dynamic getAttrNode,
514+
@Shared("lookupLen") @Cached(parameters = "Len") LookupCallableSlotInMRONode lookupLen,
514515
@Shared("getNativeNullNode") @Cached GetNativeNullNode getNativeNullNode,
515516
@Shared("nullToSulongNode") @Cached ToSulongNode toSulongNode) {
516-
if (getAttrNode.execute(object, __LEN__) != PNone.NO_VALUE) {
517+
if (lookupLen.execute(object) != PNone.NO_VALUE) {
517518
return new PySequenceMethodsWrapper(object);
518519
} else {
519520
return toSulongNode.execute(getNativeNullNode.execute());
520521
}
521522
}
522523

523-
@Specialization(guards = "eq(TP_AS_MAPPING, key)", limit = "1")
524+
@Specialization(guards = "eq(TP_AS_MAPPING, key)")
524525
static Object doTpAsMapping(PythonManagedClass object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key,
525-
@CachedLibrary("object") PythonObjectLibrary pythonTypeLibrary,
526+
@Cached(parameters = "GetItem") LookupCallableSlotInMRONode lookupGetitem,
527+
@Shared("lookupLen") @Cached(parameters = "Len") LookupCallableSlotInMRONode lookupLen,
526528
@Shared("getNativeNullNode") @Cached GetNativeNullNode getNativeNullNode,
527529
@Shared("nullToSulongNode") @Cached ToSulongNode toSulongNode) {
528-
if (pythonTypeLibrary.isSequenceType(object)) {
530+
if (lookupGetitem.execute(object) != PNone.NO_VALUE && lookupLen.execute(object) != PNone.NONE) {
529531
return new PyMappingMethodsWrapper(object);
530532
} else {
531533
return toSulongNode.execute(getNativeNullNode.execute());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObjectLibrary.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,6 @@ public final Object lookupAndCallRegularMethod(Object receiver, VirtualFrame fra
620620
* <a href="https://docs.python.org/3/library/collections.abc.html">Abstract Base Classes for
621621
* Containers</a>
622622
*
623-
* <br>
624-
* See {@link #isSequenceType(Object)}
625-
*
626623
* @param receiver the receiver Object
627624
* @return True if object is a Python sequence object
628625
*/
@@ -644,30 +641,6 @@ public boolean isMapping(Object receiver) {
644641
return lookupAttributeOnType(receiver, SpecialMethodNames.__GETITEM__) != PNone.NO_VALUE;
645642
}
646643

647-
/**
648-
* Checks whether the receiver is a Python sequence type. As described in the
649-
* <a href="https://docs.python.org/3/reference/datamodel.html">Python Data Model</a> and
650-
* <a href="https://docs.python.org/3/library/collections.abc.html">Abstract Base Classes for
651-
* Containers</a>
652-
*
653-
* <br>
654-
* Specifically the default implementation checks for the implementation of the following
655-
* special methods: <b>
656-
* <ul>
657-
* <li>__getitem__</li>
658-
* <li>__len__</li>
659-
* </ul>
660-
* </b>
661-
*
662-
* @param receiver the receiver Object
663-
* @return True if a sequence type
664-
*/
665-
public boolean isSequenceType(Object receiver) {
666-
return isLazyPythonClass(receiver) &&
667-
lookupAttribute(receiver, null, SpecialMethodNames.__LEN__) != PNone.NO_VALUE &&
668-
lookupAttribute(receiver, null, SpecialMethodNames.__GETITEM__) != PNone.NO_VALUE;
669-
}
670-
671644
/**
672645
* Checks whether the reciever is a buffer, e.g. bytes-like, object storage.
673646
*

0 commit comments

Comments
 (0)