Skip to content

Commit 09e6e74

Browse files
committed
LookupAndCallTernaryNode: accept either String name or SpecialMethodSlot
1 parent 073911d commit 09e6e74

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/SetAttributeNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETATTR__;
4444

45+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
4546
import com.oracle.graal.python.nodes.PNodeWithContext;
4647
import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
4748
import com.oracle.graal.python.nodes.expression.ExpressionNode;
@@ -57,7 +58,7 @@
5758
public abstract class SetAttributeNode extends StatementNode implements WriteNode {
5859

5960
public static final class Dynamic extends PNodeWithContext {
60-
@Child private LookupAndCallTernaryNode call = LookupAndCallTernaryNode.create(__SETATTR__);
61+
@Child private LookupAndCallTernaryNode call = LookupAndCallTernaryNode.create(SpecialMethodSlot.SetAttr);
6162

6263
public void execute(VirtualFrame frame, Object object, Object key, Object value) {
6364
call.execute(frame, object, key, value);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallNonReversibleTernaryNode.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
package com.oracle.graal.python.nodes.call.special;
4242

4343
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
44+
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor.TernaryBuiltinDescriptor;
4445
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
46+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
4547
import com.oracle.graal.python.nodes.SpecialMethodNames;
4648
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
4749
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
@@ -62,6 +64,10 @@ public abstract class LookupAndCallNonReversibleTernaryNode extends LookupAndCal
6264
super(name);
6365
}
6466

67+
LookupAndCallNonReversibleTernaryNode(SpecialMethodSlot slot) {
68+
super(slot);
69+
}
70+
6571
protected static PythonBuiltinClassType getBuiltinClass(Object receiver, GetClassNode getClassNode) {
6672
Object clazz = getClassNode.execute(receiver);
6773
return clazz instanceof PythonBuiltinClassType ? (PythonBuiltinClassType) clazz : null;
@@ -72,6 +78,14 @@ protected static boolean isClazz(PythonBuiltinClassType clazz, Object receiver,
7278
}
7379

7480
protected final PythonTernaryBuiltinNode getTernaryBuiltin(PythonBuiltinClassType clazz) {
81+
if (slot != null) {
82+
Object attribute = slot.getValue(clazz);
83+
if (attribute instanceof TernaryBuiltinDescriptor) {
84+
return ((TernaryBuiltinDescriptor) attribute).createNode();
85+
}
86+
// If the slot does not contain builtin, full lookup wouldn't find a builtin either
87+
return null;
88+
}
7589
Object attribute = LookupAttributeInMRONode.Dynamic.getUncached().execute(clazz, name);
7690
if (attribute instanceof PBuiltinFunction) {
7791
PBuiltinFunction builtinFunction = (PBuiltinFunction) attribute;
@@ -94,7 +108,7 @@ static Object callObjectBuiltin(VirtualFrame frame, Object v, Object w, Object z
94108
Object callObject(VirtualFrame frame, Object arg1, Object arg2, Object arg3,
95109
@SuppressWarnings("unused") @Cached("arg1.getClass()") Class<?> cachedArg1Class,
96110
@Cached GetClassNode getClassNode,
97-
@Cached("create(name)") LookupSpecialBaseNode getattr) {
111+
@Cached("createLookup()") LookupSpecialBaseNode getattr) {
98112
Object klass = getClassNode.execute(arg1);
99113
return dispatchNode.execute(frame, getattr.execute(frame, klass, arg1), arg1, arg2, arg3);
100114
}
@@ -103,7 +117,7 @@ Object callObject(VirtualFrame frame, Object arg1, Object arg2, Object arg3,
103117
@Megamorphic
104118
Object callObjectMegamorphic(VirtualFrame frame, Object arg1, Object arg2, Object arg3,
105119
@Cached GetClassNode getClassNode,
106-
@Cached("create(name)") LookupSpecialBaseNode getattr) {
120+
@Cached("createLookup()") LookupSpecialBaseNode getattr) {
107121
Object klass = getClassNode.execute(arg1);
108122
return dispatchNode.execute(frame, getattr.execute(frame, klass, arg1), arg1, arg2, arg3);
109123
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleTernaryNode.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import com.oracle.graal.python.builtins.objects.PNone;
4444
import com.oracle.graal.python.builtins.objects.PNotImplemented;
45+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
4546
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
4647
import com.oracle.graal.python.nodes.SpecialMethodNames;
4748
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
@@ -72,11 +73,16 @@ public abstract class LookupAndCallReversibleTernaryNode extends LookupAndCallTe
7273
this.handlerFactory = handlerFactory;
7374
}
7475

76+
public LookupAndCallReversibleTernaryNode(SpecialMethodSlot slot, Supplier<NotImplementedHandler> handlerFactory) {
77+
super(slot);
78+
this.handlerFactory = handlerFactory;
79+
}
80+
7581
@Specialization(guards = "v.getClass() == cachedVClass", limit = "getCallSiteInlineCacheMaxDepth()")
7682
Object callObjectR(VirtualFrame frame, Object v, Object w, Object z,
7783
@SuppressWarnings("unused") @Cached("v.getClass()") Class<?> cachedVClass,
78-
@Cached("create(name)") LookupSpecialMethodNode getattr,
79-
@Cached("create(name)") LookupSpecialMethodNode getattrR,
84+
@Cached("createLookup()") LookupSpecialMethodNode getattr,
85+
@Cached("createLookup()") LookupSpecialMethodNode getattrR,
8086
@Cached GetClassNode getClass,
8187
@Cached GetClassNode getClassR,
8288
@Cached IsSubtypeNode isSubtype,
@@ -88,8 +94,8 @@ Object callObjectR(VirtualFrame frame, Object v, Object w, Object z,
8894
@Specialization(replaces = "callObjectR")
8995
@Megamorphic
9096
Object callObjectRMegamorphic(VirtualFrame frame, Object v, Object w, Object z,
91-
@Cached("create(name)") LookupSpecialMethodNode getattr,
92-
@Cached("create(name)") LookupSpecialMethodNode getattrR,
97+
@Cached("createLookup()") LookupSpecialMethodNode getattr,
98+
@Cached("createLookup()") LookupSpecialMethodNode getattrR,
9399
@Cached GetClassNode getClass,
94100
@Cached GetClassNode getClassR,
95101
@Cached IsSubtypeNode isSubtype,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallTernaryNode.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141
package com.oracle.graal.python.nodes.call.special;
4242

43+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
4344
import com.oracle.graal.python.nodes.PNodeWithContext;
4445
import com.oracle.graal.python.nodes.SpecialMethodNames;
4546
import com.oracle.graal.python.runtime.PythonOptions;
@@ -56,6 +57,7 @@ public abstract static class NotImplementedHandler extends PNodeWithContext {
5657
}
5758

5859
protected final String name;
60+
protected final SpecialMethodSlot slot;
5961
@Child protected CallTernaryMethodNode dispatchNode = CallTernaryMethodNode.create();
6062

6163
public abstract Object execute(VirtualFrame frame, Object arg1, Object arg2, Object arg3);
@@ -64,11 +66,32 @@ public static LookupAndCallTernaryNode create(String name) {
6466
return LookupAndCallNonReversibleTernaryNodeGen.create(name);
6567
}
6668

69+
public static LookupAndCallTernaryNode create(SpecialMethodSlot slot) {
70+
return LookupAndCallNonReversibleTernaryNodeGen.create(slot);
71+
}
72+
6773
public static LookupAndCallTernaryNode createReversible(String name, Supplier<NotImplementedHandler> handlerFactory) {
6874
return LookupAndCallReversibleTernaryNodeGen.create(name, handlerFactory);
6975
}
7076

77+
public static LookupAndCallTernaryNode createReversible(SpecialMethodSlot slot, Supplier<NotImplementedHandler> handlerFactory) {
78+
return LookupAndCallReversibleTernaryNodeGen.create(slot, handlerFactory);
79+
}
80+
7181
LookupAndCallTernaryNode(String name) {
7282
this.name = name;
83+
this.slot = null;
84+
}
85+
86+
LookupAndCallTernaryNode(SpecialMethodSlot slot) {
87+
this.slot = slot;
88+
this.name = slot.getName();
89+
}
90+
91+
protected final LookupSpecialBaseNode createLookup() {
92+
if (slot != null) {
93+
return LookupSpecialMethodSlotNode.create(slot);
94+
}
95+
return LookupSpecialMethodNode.create(name);
7396
}
7497
}

0 commit comments

Comments
 (0)