Skip to content

Commit 39a5c91

Browse files
author
Stefan Anzinger
committed
[GR-35424] Use slots on the fast-path in LookupAndCallXYNode.
PullRequest: graalpython/2056
2 parents d34630d + 8444007 commit 39a5c91

39 files changed

+118
-84
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@
8585
import static com.oracle.graal.python.nodes.SpecialMethodNames.__COMPLEX__;
8686
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
8787
import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
88-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INDEX__;
8988
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INT__;
90-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__;
9189
import static com.oracle.graal.python.nodes.SpecialMethodNames.__TRUNC__;
9290
import static com.oracle.graal.python.runtime.exception.PythonErrorType.NotImplementedError;
9391
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
@@ -641,7 +639,7 @@ private PComplex convertStringToComplex(VirtualFrame frame, String src, Object c
641639
if (str == null) {
642640
if (callReprNode == null) {
643641
CompilerDirectives.transferToInterpreterAndInvalidate();
644-
callReprNode = insert(LookupAndCallUnaryNode.create(__REPR__));
642+
callReprNode = insert(LookupAndCallUnaryNode.create(SpecialMethodSlot.Repr));
645643
}
646644
Object strStr = callReprNode.executeObject(frame, origObj);
647645
if (PGuards.isString(strStr)) {
@@ -856,7 +854,7 @@ public Object reversed(VirtualFrame frame, Object cls, Object sequence,
856854
@Cached GetClassNode getClassNode,
857855
@Cached("create(Reversed)") LookupSpecialMethodSlotNode lookupReversed,
858856
@Cached CallUnaryMethodNode callReversed,
859-
@Cached("create(__LEN__)") LookupAndCallUnaryNode lookupLen,
857+
@Cached("create(Len)") LookupAndCallUnaryNode lookupLen,
860858
@Cached("create(GetItem)") LookupSpecialMethodSlotNode getItemNode,
861859
@Cached ConditionProfile noReversedProfile,
862860
@Cached ConditionProfile noGetItemProfile) {
@@ -1053,7 +1051,7 @@ private Object stringToInt(VirtualFrame frame, Object cls, String number, int ba
10531051
invalidValueProfile.enter();
10541052
if (callReprNode == null) {
10551053
CompilerDirectives.transferToInterpreterAndInvalidate();
1056-
callReprNode = insert(LookupAndCallUnaryNode.create(__REPR__));
1054+
callReprNode = insert(LookupAndCallUnaryNode.create(SpecialMethodSlot.Repr));
10571055
}
10581056
Object str = callReprNode.executeObject(frame, origObj);
10591057
if (PGuards.isString(str)) {
@@ -1449,7 +1447,7 @@ protected static FloatBuiltins.IntNode createFloatInt() {
14491447
private Object callIndex(VirtualFrame frame, Object obj) {
14501448
if (callIndexNode == null) {
14511449
CompilerDirectives.transferToInterpreterAndInvalidate();
1452-
callIndexNode = insert(LookupAndCallUnaryNode.create(__INDEX__));
1450+
callIndexNode = insert(LookupAndCallUnaryNode.create(SpecialMethodSlot.Index));
14531451
}
14541452
Object result = callIndexNode.executeObject(frame, obj);
14551453
// the case when the result is NO_VALUE (i.e. the object does not provide __index__)
@@ -1471,7 +1469,7 @@ private Object callTrunc(VirtualFrame frame, Object obj) {
14711469
private Object callInt(VirtualFrame frame, Object object) {
14721470
if (callIntNode == null) {
14731471
CompilerDirectives.transferToInterpreterAndInvalidate();
1474-
callIntNode = insert(LookupAndCallUnaryNode.create(__INT__));
1472+
callIntNode = insert(LookupAndCallUnaryNode.create(SpecialMethodSlot.Int));
14751473
}
14761474
Object result = callIntNode.executeObject(frame, object);
14771475
if (result != PNone.NO_VALUE && !isIntegerType(result)) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ private static TriState isInstanceCheckInternal(VirtualFrame frame, Object insta
14111411

14121412
@Specialization(guards = "isPythonClass(cls)")
14131413
static boolean isInstance(VirtualFrame frame, Object instance, Object cls,
1414-
@Shared("instanceCheck") @Cached("create(__INSTANCECHECK__)") LookupAndCallBinaryNode instanceCheckNode,
1414+
@Shared("instanceCheck") @Cached("create(InstanceCheck)") LookupAndCallBinaryNode instanceCheckNode,
14151415
@Shared("boolCast") @Cached("createIfTrueNode()") CoerceToBooleanNode castToBooleanNode,
14161416
@Cached GetClassNode getClassNode,
14171417
@Cached TypeNodes.IsSameTypeNode isSameTypeNode,
@@ -1423,7 +1423,7 @@ static boolean isInstance(VirtualFrame frame, Object instance, Object cls,
14231423

14241424
@Specialization(guards = {"!isPTuple(cls)", "!isPythonClass(cls)"})
14251425
static boolean isInstance(VirtualFrame frame, Object instance, Object cls,
1426-
@Shared("instanceCheck") @Cached("create(__INSTANCECHECK__)") LookupAndCallBinaryNode instanceCheckNode,
1426+
@Shared("instanceCheck") @Cached("create(InstanceCheck)") LookupAndCallBinaryNode instanceCheckNode,
14271427
@Shared("boolCast") @Cached("createIfTrueNode()") CoerceToBooleanNode castToBooleanNode,
14281428
@Cached TypeBuiltins.InstanceCheckNode typeInstanceCheckNode) {
14291429
TriState check = isInstanceCheckInternal(frame, instance, cls, instanceCheckNode, castToBooleanNode);
@@ -1454,7 +1454,7 @@ public IsSubClassNode createRecursive(byte newDepth) {
14541454

14551455
@Specialization(guards = "!isPTuple(cls)")
14561456
static boolean isSubclass(VirtualFrame frame, Object derived, Object cls,
1457-
@Cached("create(__SUBCLASSCHECK__)") LookupAndCallBinaryNode subclassCheckNode,
1457+
@Cached("create(Subclasscheck)") LookupAndCallBinaryNode subclassCheckNode,
14581458
@Cached("createIfTrueNode()") CoerceToBooleanNode castToBooleanNode,
14591459
@Cached IsSubtypeNode isSubtypeNode) {
14601460
Object instanceCheckResult = subclassCheckNode.executeObject(frame, cls, derived);
@@ -1884,13 +1884,13 @@ public abstract static class FormatNode extends PythonBinaryBuiltinNode {
18841884

18851885
@Specialization(guards = "isNoValue(formatSpec)")
18861886
Object format(VirtualFrame frame, Object obj, @SuppressWarnings("unused") PNone formatSpec,
1887-
@Shared("callFormat") @Cached("create(__FORMAT__)") LookupAndCallBinaryNode callFormat) {
1887+
@Shared("callFormat") @Cached("create(Format)") LookupAndCallBinaryNode callFormat) {
18881888
return format(frame, obj, "", callFormat);
18891889
}
18901890

18911891
@Specialization(guards = "!isNoValue(formatSpec)")
18921892
Object format(VirtualFrame frame, Object obj, Object formatSpec,
1893-
@Shared("callFormat") @Cached("create(__FORMAT__)") LookupAndCallBinaryNode callFormat) {
1893+
@Shared("callFormat") @Cached("create(Format)") LookupAndCallBinaryNode callFormat) {
18941894
Object res = callFormat.executeObject(frame, obj, formatSpec);
18951895
if (res == NO_VALUE) {
18961896
throw raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_FORMAT, obj);
@@ -1920,7 +1920,7 @@ public static String ascii(VirtualFrame frame, Object obj,
19201920
public abstract static class RoundNode extends PythonBuiltinNode {
19211921
@Specialization
19221922
Object round(VirtualFrame frame, Object x, @SuppressWarnings("unused") PNone n,
1923-
@Cached("create(__ROUND__)") LookupAndCallUnaryNode callRound) {
1923+
@Cached("create(Round)") LookupAndCallUnaryNode callRound) {
19241924
Object result = callRound.executeObject(frame, x);
19251925
if (result == PNone.NO_VALUE) {
19261926
throw raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, x, __ROUND__);
@@ -1930,7 +1930,7 @@ Object round(VirtualFrame frame, Object x, @SuppressWarnings("unused") PNone n,
19301930

19311931
@Specialization(guards = "!isPNone(n)")
19321932
Object round(VirtualFrame frame, Object x, Object n,
1933-
@Cached("create(__ROUND__)") LookupAndCallBinaryNode callRound) {
1933+
@Cached("create(Round)") LookupAndCallBinaryNode callRound) {
19341934
Object result = callRound.executeObject(frame, x, n);
19351935
if (result == NOT_IMPLEMENTED) {
19361936
throw raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, x, __ROUND__);
@@ -2037,7 +2037,7 @@ Object ternary(VirtualFrame frame, Object x, Object y, Object z,
20372037
@GenerateNodeFactory
20382038
public abstract static class SumFunctionNode extends PythonBuiltinNode {
20392039

2040-
@Child private LookupAndCallUnaryNode next = LookupAndCallUnaryNode.create(__NEXT__);
2040+
@Child private LookupAndCallUnaryNode next = LookupAndCallUnaryNode.create(SpecialMethodSlot.Next);
20412041
@Child private AddNode add = AddNode.create();
20422042

20432043
@Child private IsBuiltinClassProfile errorProfile1 = IsBuiltinClassProfile.create();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626
package com.oracle.graal.python.builtins.modules;
2727

28-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEXT__;
2928
import static com.oracle.graal.python.runtime.exception.PythonErrorType.NotImplementedError;
3029
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
3130
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
@@ -49,6 +48,7 @@
4948
import com.oracle.graal.python.builtins.objects.function.PKeyword;
5049
import com.oracle.graal.python.builtins.objects.ints.PInt;
5150
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
51+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
5252
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
5353
import com.oracle.graal.python.lib.PyNumberIndexNode;
5454
import com.oracle.graal.python.lib.PyObjectGetIter;
@@ -948,7 +948,7 @@ public abstract static class FsumNode extends PythonUnaryBuiltinNode {
948948
@Specialization
949949
double doIt(VirtualFrame frame, Object iterable,
950950
@Cached PyObjectGetIter getIter,
951-
@Cached("create(__NEXT__)") LookupAndCallUnaryNode callNextNode,
951+
@Cached("create(Next)") LookupAndCallUnaryNode callNextNode,
952952
@Cached PyFloatAsDoubleNode asDoubleNode,
953953
@Cached IsBuiltinClassProfile stopProfile) {
954954
Object iterator = getIter.execute(frame, iterable);
@@ -2259,7 +2259,7 @@ private void raiseIfNegative(boolean condition) {
22592259
@GenerateNodeFactory
22602260
public abstract static class ProdNode extends PythonBuiltinNode {
22612261

2262-
@Child private LookupAndCallUnaryNode callNextNode = LookupAndCallUnaryNode.create(__NEXT__);
2262+
@Child private LookupAndCallUnaryNode callNextNode = LookupAndCallUnaryNode.create(SpecialMethodSlot.Next);
22632263
@Child private BinaryOpNode mul = BinaryArithmetic.Mul.create();
22642264
@Child private IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.create();
22652265

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,7 +3395,7 @@ abstract static class PyTruffle_OS_DoubleToString extends NativeBuiltin {
33953395
@Specialization(guards = "isReprFormatCode(formatCode)")
33963396
@SuppressWarnings("unused")
33973397
PTuple doRepr(VirtualFrame frame, Object module, double val, int formatCode, int precision, int flags,
3398-
@Cached("create(__REPR__)") LookupAndCallUnaryNode callReprNode,
3398+
@Cached("create(Repr)") LookupAndCallUnaryNode callReprNode,
33993399
@Cached CastToJavaStringNode castToStringNode,
34003400
@Cached GetNativeNullNode getNativeNullNode) {
34013401
Object reprString = callReprNode.executeObject(frame, val);
@@ -3409,7 +3409,7 @@ PTuple doRepr(VirtualFrame frame, Object module, double val, int formatCode, int
34093409

34103410
@Specialization(guards = "!isReprFormatCode(formatCode)")
34113411
Object doGeneric(VirtualFrame frame, Object module, double val, int formatCode, int precision, @SuppressWarnings("unused") int flags,
3412-
@Cached("create(__FORMAT__)") LookupAndCallBinaryNode callReprNode,
3412+
@Cached("create(Format)") LookupAndCallBinaryNode callReprNode,
34133413
@Cached CastToJavaStringNode castToStringNode,
34143414
@Cached GetNativeNullNode getNativeNullNode) {
34153415
try {
@@ -3493,7 +3493,7 @@ static int doMapping(PHashingCollection container,
34933493

34943494
@Specialization(guards = "!isMappingOrSequence(obj)")
34953495
static Object doGenericUnboxed(VirtualFrame frame, Object obj,
3496-
@Cached("create(__LEN__)") LookupAndCallUnaryNode callLenNode,
3496+
@Cached("create(Len)") LookupAndCallUnaryNode callLenNode,
34973497
@Cached ConditionProfile noLenProfile,
34983498
@Cached CastToNativeLongNode castToLongNode,
34993499
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ protected abstract static class UnpickleNode extends PythonBinaryBuiltinNode {
500500
@Specialization
501501
Object unpickle(VirtualFrame frame, Object typ, PTuple state,
502502
@Cached CallNode callNode,
503-
@Cached("create(__NEW__)") LookupAndCallUnaryNode lookupAndCallUnaryNode,
503+
@Cached("create(New)") LookupAndCallUnaryNode lookupAndCallUnaryNode,
504504
@Cached("create(__SETSTATE__)") GetAttributeNode setStateAttr) {
505505
Object obj = lookupAndCallUnaryNode.executeObject(frame, typ);
506506
Object meth = setStateAttr.executeObject(frame, obj);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ static Object doit(@SuppressWarnings("unused") PFileIO self) {
11201120
@Specialization(guards = "!self.isClosed()")
11211121
Object doit(VirtualFrame frame, PFileIO self,
11221122
@Cached PyObjectLookupAttr lookupName,
1123-
@Cached("create(__REPR__)") LookupAndCallUnaryNode repr) {
1123+
@Cached("create(Repr)") LookupAndCallUnaryNode repr) {
11241124
String mode = ModeNode.modeString(self);
11251125
String closefd = self.isCloseFD() ? "True" : "False";
11261126
Object nameobj = lookupName.execute(frame, self, "name");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ abstract static class ReprNode extends InitCheckPythonUnaryBuiltinNode {
11591159
@Specialization(guards = "self.isOK()")
11601160
Object doit(VirtualFrame frame, PTextIO self,
11611161
@Cached PyObjectLookupAttr lookup,
1162-
@Cached("create(__REPR__)") LookupAndCallUnaryNode repr,
1162+
@Cached("create(Repr)") LookupAndCallUnaryNode repr,
11631163
@Cached IONodes.ToStringNode toString,
11641164
@Cached IsBuiltinClassProfile isValueError) {
11651165
if (!getContext().reprEnter(self)) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.oracle.graal.python.builtins.objects.list.PList;
3434
import com.oracle.graal.python.builtins.objects.str.PString;
3535
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
36+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
3637
import com.oracle.graal.python.nodes.PGuards;
3738
import com.oracle.graal.python.nodes.PRaiseNode;
3839
import com.oracle.graal.python.nodes.SpecialMethodNames;
@@ -73,12 +74,12 @@ public abstract static class CallEncoderNode extends PythonTernaryClinicBuiltinN
7374
@Child private CallUnaryMethodNode callDefaultFn = CallUnaryMethodNode.create();
7475
@Child private CastToJavaStringNode castEncodeResult = CastToJavaStringNode.create();
7576
@Child private LookupAndCallUnaryNode callGetItems = LookupAndCallUnaryNode.create(SpecialMethodNames.ITEMS);
76-
@Child private LookupAndCallUnaryNode callGetDictIter = LookupAndCallUnaryNode.create(SpecialMethodNames.__ITER__);
77+
@Child private LookupAndCallUnaryNode callGetDictIter = LookupAndCallUnaryNode.create(SpecialMethodSlot.Iter);
7778
@Child private GetNextNode callDictNext = GetNextNode.create();
7879
@Child private IsBuiltinClassProfile stopDictIterationProfile = IsBuiltinClassProfile.create();
7980
@Child private HashingStorageLibrary dictLib = HashingStorageLibrary.getFactory().createDispatched(6);
8081
@Child private ListSortNode sortList = ListSortNode.create();
81-
@Child private LookupAndCallUnaryNode callGetListIter = LookupAndCallUnaryNode.create(SpecialMethodNames.__ITER__);
82+
@Child private LookupAndCallUnaryNode callGetListIter = LookupAndCallUnaryNode.create(SpecialMethodSlot.Iter);
8283
@Child private GetNextNode callListNext = GetNextNode.create();
8384
@Child private IsBuiltinClassProfile stopListIterationProfile = IsBuiltinClassProfile.create();
8485
@Child private GetClassNode getDictClass = GetClassNode.create();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static boolean contains(VirtualFrame frame, PArray self, Object value,
437437
abstract static class ReprNode extends PythonUnaryBuiltinNode {
438438
@Specialization
439439
static String repr(VirtualFrame frame, PArray self,
440-
@Cached("create(__REPR__)") LookupAndCallUnaryNode reprNode,
440+
@Cached("create(Repr)") LookupAndCallUnaryNode reprNode,
441441
@Cached ConditionProfile isEmptyProfile,
442442
@Cached ConditionProfile isUnicodeProfile,
443443
@Cached CastToJavaStringNode cast,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/FormatNodeBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
5959
// applies to all types: empty format string => use __str__
6060
@Specialization(guards = "formatString.isEmpty()")
6161
public static Object formatEmptyString(VirtualFrame frame, Object self, @SuppressWarnings("unused") String formatString,
62-
@Cached("create(__STR__)") LookupAndCallUnaryNode lookupAndCallNode) {
62+
@Cached("create(Str)") LookupAndCallUnaryNode lookupAndCallNode) {
6363
return lookupAndCallNode.executeObject(frame, self);
6464
}
6565
}

0 commit comments

Comments
 (0)