Skip to content

Commit fa0006d

Browse files
committed
Use new slot lookups in library nodes
1 parent 697eeef commit fa0006d

File tree

6 files changed

+102
-102
lines changed

6 files changed

+102
-102
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,22 @@
5353
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ENTER__;
5454
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
5555
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EXIT__;
56+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__FLOAT__;
5657
import static com.oracle.graal.python.nodes.SpecialMethodNames.__FORMAT__;
5758
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTRIBUTE__;
5859
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTR__;
5960
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__;
6061
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GET__;
62+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GE__;
6163
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GT__;
6264
import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
65+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INDEX__;
6366
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INIT__;
6467
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INSTANCECHECK__;
68+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INT__;
6569
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
6670
import static com.oracle.graal.python.nodes.SpecialMethodNames.__LEN__;
71+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__LE__;
6772
import static com.oracle.graal.python.nodes.SpecialMethodNames.__LT__;
6873
import static com.oracle.graal.python.nodes.SpecialMethodNames.__MISSING__;
6974
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
@@ -139,41 +144,55 @@ public enum SpecialMethodSlot {
139144
GetAttribute(__GETATTRIBUTE__),
140145
GetAttr(__GETATTR__),
141146
SetAttr(__SETATTR__),
142-
Str(__STR__),
143-
// Note: __format__ does not seem to be actual slot in CPython, but it is looked up frequently
144-
Format(__FORMAT__),
145147
DelAttr(__DELATTR__),
148+
149+
Class(__CLASS__),
150+
Dict(__DICT__),
151+
152+
Get(__GET__),
153+
Set(__SET__),
154+
Delete(__DELETE__),
155+
146156
Iter(__ITER__),
147157
Next(__NEXT__),
148-
Get(__GET__),
149-
Eq(__EQ__),
158+
150159
New(__NEW__),
151160
Init(__INIT__),
161+
Prepare(__PREPARE__),
162+
SetName(__SET_NAME__),
163+
InstanceCheck(__INSTANCECHECK__),
164+
Subclasscheck(__SUBCLASSCHECK__),
152165
Call(__CALL__),
153-
Set(__SET__),
166+
154167
GetItem(__GETITEM__),
155168
SetItem(__SETITEM__),
156-
Len(__LEN__),
169+
DelItem(__DELITEM__),
170+
157171
Exit(__EXIT__),
158172
Enter(__ENTER__),
173+
174+
Len(__LEN__),
159175
Contains(__CONTAINS__),
160-
DelItem(__DELITEM__),
161-
Class(__CLASS__),
162-
InstanceCheck(__INSTANCECHECK__),
163-
Ne(__NE__),
164-
Lt(__LT__),
165-
Missing(__MISSING__),
166176
Bool(__BOOL__),
167177
Hash(__HASH__),
168-
Dict(__DICT__),
169-
Delete(__DELETE__),
170-
Prepare(__PREPARE__),
178+
Index(__INDEX__),
179+
Float(__FLOAT__),
180+
Int(__INT__),
181+
Str(__STR__),
182+
Repr(__REPR__),
183+
// Note: __format__ does not seem to be actual slot in CPython, but it is looked up frequently
184+
Format(__FORMAT__),
185+
Missing(__MISSING__),
186+
187+
Eq(__EQ__),
188+
Ne(__NE__),
189+
Lt(__LT__),
190+
Le(__LE__),
171191
Gt(__GT__),
192+
Ge(__GE__),
193+
172194
And(__AND__),
173195
RAnd(__RAND__),
174-
SetName(__SET_NAME__),
175-
Repr(__REPR__),
176-
Subclasscheck(__SUBCLASSCHECK__),
177196
Add(__ADD__);
178197

179198
public static final SpecialMethodSlot[] VALUES = values();
@@ -612,6 +631,8 @@ public static SpecialMethodSlot findSpecialSlot(String name) {
612631
return Ne;
613632
case __LT__:
614633
return Lt;
634+
case __LE__:
635+
return Le;
615636
case __MISSING__:
616637
return Missing;
617638
case __BOOL__:
@@ -626,6 +647,8 @@ public static SpecialMethodSlot findSpecialSlot(String name) {
626647
return Prepare;
627648
case __GT__:
628649
return Gt;
650+
case __GE__:
651+
return Ge;
629652
case __AND__:
630653
return And;
631654
case __RAND__:
@@ -638,6 +661,12 @@ public static SpecialMethodSlot findSpecialSlot(String name) {
638661
return Subclasscheck;
639662
case __ADD__:
640663
return Add;
664+
case __INDEX__:
665+
return Index;
666+
case __INT__:
667+
return Int;
668+
case __FLOAT__:
669+
return Float;
641670
default:
642671
return null;
643672
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CanBeDoubleNode.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@
4040
*/
4141
package com.oracle.graal.python.lib;
4242

43-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__FLOAT__;
44-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INDEX__;
45-
4643
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4744
import com.oracle.graal.python.builtins.objects.PNone;
4845
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
46+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
4947
import com.oracle.graal.python.nodes.PNodeWithContext;
50-
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
48+
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
5149
import com.oracle.graal.python.nodes.object.GetClassNode;
5250
import com.oracle.truffle.api.dsl.Cached;
5351
import com.oracle.truffle.api.dsl.GenerateUncached;
52+
import com.oracle.truffle.api.dsl.ImportStatic;
5453
import com.oracle.truffle.api.dsl.Specialization;
5554
import com.oracle.truffle.api.interop.InteropLibrary;
5655
import com.oracle.truffle.api.library.CachedLibrary;
@@ -61,6 +60,7 @@
6160
* checks for the {@code nb_float} and {@code nb_index} slots directly.
6261
*/
6362
@GenerateUncached
63+
@ImportStatic(SpecialMethodSlot.class)
6464
public abstract class CanBeDoubleNode extends PNodeWithContext {
6565
public abstract boolean execute(Object object);
6666

@@ -82,10 +82,10 @@ static boolean doLong(@SuppressWarnings("unused") Long object) {
8282
@Specialization
8383
static boolean doPythonObject(PythonAbstractObject object,
8484
@Cached GetClassNode getClassNode,
85-
@Cached LookupAttributeInMRONode.Dynamic lookupFloat,
86-
@Cached LookupAttributeInMRONode.Dynamic lookupIndex) {
85+
@Cached(parameters = "Float") LookupCallableSlotInMRONode lookupFloat,
86+
@Cached(parameters = "Index") LookupCallableSlotInMRONode lookupIndex) {
8787
Object type = getClassNode.execute(object);
88-
return lookupFloat.execute(type, __FLOAT__) != PNone.NO_VALUE || lookupIndex.execute(type, __INDEX__) != PNone.NO_VALUE;
88+
return lookupFloat.execute(type) != PNone.NO_VALUE || lookupIndex.execute(type) != PNone.NO_VALUE;
8989
}
9090

9191
@Specialization
@@ -106,14 +106,14 @@ static boolean doPBCT(@SuppressWarnings("unused") PythonBuiltinClassType object)
106106
@Specialization(replaces = "doPythonObject")
107107
static boolean doGeneric(Object object,
108108
@CachedLibrary(limit = "3") InteropLibrary interopLibrary,
109-
@Cached LookupAttributeInMRONode.Dynamic lookupFloat,
110-
@Cached LookupAttributeInMRONode.Dynamic lookupIndex,
109+
@Cached(parameters = "Float") LookupCallableSlotInMRONode lookupFloat,
110+
@Cached(parameters = "Index") LookupCallableSlotInMRONode lookupIndex,
111111
@Cached GetClassNode getClassNode) {
112112
Object type = getClassNode.execute(object);
113113
if (type == PythonBuiltinClassType.ForeignObject) {
114114
return interopLibrary.fitsInDouble(object) || interopLibrary.fitsInLong(object) || interopLibrary.isBoolean(object);
115115
}
116-
return lookupFloat.execute(type, __FLOAT__) != PNone.NO_VALUE || lookupIndex.execute(type, __INDEX__) != PNone.NO_VALUE;
116+
return lookupFloat.execute(type) != PNone.NO_VALUE || lookupIndex.execute(type) != PNone.NO_VALUE;
117117
}
118118

119119
public static CanBeDoubleNode create() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatAsDoubleNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins;
4949
import com.oracle.graal.python.builtins.objects.PNone;
5050
import com.oracle.graal.python.builtins.objects.floats.PFloat;
51+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
5152
import com.oracle.graal.python.nodes.ErrorMessages;
52-
import com.oracle.graal.python.nodes.PGuards;
5353
import com.oracle.graal.python.nodes.PNodeWithContext;
5454
import com.oracle.graal.python.nodes.PRaiseNode;
5555
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
56-
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodNode;
56+
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
5757
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
5858
import com.oracle.graal.python.nodes.object.GetClassNode;
5959
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
@@ -72,7 +72,7 @@
7272
* {@code __index__} and the returned integer wouldn't fit into double.
7373
*/
7474
@GenerateUncached
75-
@ImportStatic({PGuards.class, PythonBuiltinClassType.class})
75+
@ImportStatic(SpecialMethodSlot.class)
7676
public abstract class PyFloatAsDoubleNode extends PNodeWithContext {
7777
public abstract double execute(Frame frame, Object object);
7878

@@ -106,7 +106,7 @@ static double doLong(long object) {
106106
@Specialization(guards = {"!isDouble(object)", "!isInteger(object)", "!isBoolean(object)", "!isPFloat(object)"})
107107
static double doObject(VirtualFrame frame, Object object,
108108
@Cached GetClassNode getClassNode,
109-
@Cached LookupSpecialMethodNode.Dynamic lookup,
109+
@Cached(parameters = "Float") LookupSpecialMethodSlotNode lookup,
110110
@Cached CallUnaryMethodNode call,
111111
@Cached GetClassNode resultClassNode,
112112
@Cached IsBuiltinClassProfile resultProfile,
@@ -117,7 +117,7 @@ static double doObject(VirtualFrame frame, Object object,
117117
@Cached WarningsModuleBuiltins.WarnNode warnNode,
118118
@Cached PRaiseNode raiseNode) {
119119
Object type = getClassNode.execute(object);
120-
Object floatDescr = lookup.execute(frame, type, __FLOAT__, object);
120+
Object floatDescr = lookup.execute(frame, type, object);
121121
if (floatDescr != PNone.NO_VALUE) {
122122
Object result = call.executeObject(frame, floatDescr, object);
123123
Object resultType = resultClassNode.execute(result);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIndexCheckNode.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@
4040
*/
4141
package com.oracle.graal.python.lib;
4242

43-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INDEX__;
44-
4543
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4644
import com.oracle.graal.python.builtins.objects.PNone;
4745
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
46+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
4847
import com.oracle.graal.python.nodes.PNodeWithContext;
49-
import com.oracle.graal.python.nodes.SpecialMethodNames;
50-
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
48+
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
5149
import com.oracle.graal.python.nodes.object.GetClassNode;
5250
import com.oracle.truffle.api.dsl.Cached;
5351
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -60,7 +58,7 @@
6058
* Check if the object supports conversion to index (integer). Equivalent of CPython's
6159
* {@code PyIndex_Check}. The return value doesn't need to be profiled in most cases.
6260
*/
63-
@ImportStatic(SpecialMethodNames.class)
61+
@ImportStatic(SpecialMethodSlot.class)
6462
@GenerateUncached
6563
public abstract class PyIndexCheckNode extends PNodeWithContext {
6664
public abstract boolean execute(Object object);
@@ -80,8 +78,8 @@ static boolean doString(@SuppressWarnings("unused") String object) {
8078
@Specialization
8179
static boolean doPythonObject(PythonAbstractObject object,
8280
@Cached GetClassNode getClassNode,
83-
@Cached LookupAttributeInMRONode.Dynamic lookup) {
84-
return lookup.execute(getClassNode.execute(object), __INDEX__) != PNone.NO_VALUE;
81+
@Cached(parameters = "Index") LookupCallableSlotInMRONode lookupIndex) {
82+
return lookupIndex.execute(getClassNode.execute(object)) != PNone.NO_VALUE;
8583
}
8684

8785
@Specialization
@@ -108,12 +106,12 @@ static boolean doPBCT(@SuppressWarnings("unused") PythonBuiltinClassType object)
108106
static boolean doGeneric(Object object,
109107
@CachedLibrary(limit = "3") InteropLibrary interopLibrary,
110108
@Cached GetClassNode getClassNode,
111-
@Cached LookupAttributeInMRONode.Dynamic lookup) {
109+
@Cached(parameters = "Index") LookupCallableSlotInMRONode lookupIndex) {
112110
Object type = getClassNode.execute(object);
113111
if (type == PythonBuiltinClassType.ForeignObject) {
114112
return interopLibrary.fitsInLong(object) || interopLibrary.isBoolean(object);
115113
}
116-
return lookup.execute(type, __INDEX__) != PNone.NO_VALUE;
114+
return lookupIndex.execute(type) != PNone.NO_VALUE;
117115
}
118116

119117
public static PyIndexCheckNode create() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsLongAndOverflowNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins;
5050
import com.oracle.graal.python.builtins.objects.PNone;
5151
import com.oracle.graal.python.builtins.objects.ints.PInt;
52+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
5253
import com.oracle.graal.python.nodes.ErrorMessages;
53-
import com.oracle.graal.python.nodes.PGuards;
5454
import com.oracle.graal.python.nodes.PNodeWithContext;
5555
import com.oracle.graal.python.nodes.PRaiseNode;
5656
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
57-
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodNode;
57+
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
5858
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
5959
import com.oracle.graal.python.nodes.object.GetClassNode;
6060
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
@@ -73,7 +73,7 @@
7373
* {@link com.oracle.graal.python.util.OverflowException}.
7474
*/
7575
@GenerateUncached
76-
@ImportStatic({PGuards.class, PythonBuiltinClassType.class})
76+
@ImportStatic(SpecialMethodSlot.class)
7777
public abstract class PyLongAsLongAndOverflowNode extends PNodeWithContext {
7878
public abstract long execute(Frame frame, Object object) throws OverflowException;
7979

@@ -103,22 +103,22 @@ static long doBoolean(boolean x) {
103103
long doObject(VirtualFrame frame, Object object,
104104
@Cached GetClassNode getClassNode,
105105
@Cached GetClassNode resultClassNode,
106-
@Cached LookupSpecialMethodNode.Dynamic lookupIndex,
107-
@Cached LookupSpecialMethodNode.Dynamic lookupInt,
106+
@Cached(parameters = "Index") LookupSpecialMethodSlotNode lookupIndex,
107+
@Cached(parameters = "Int") LookupSpecialMethodSlotNode lookupInt,
108108
@Cached CallUnaryMethodNode call,
109109
@Cached IsSubtypeNode resultSubtype,
110110
@Cached IsBuiltinClassProfile resultIsInt,
111111
@Cached WarningsModuleBuiltins.WarnNode warnNode,
112112
@Cached PRaiseNode raiseNode,
113113
@Cached PyLongAsLongAndOverflowNode recursive) throws OverflowException {
114114
Object type = getClassNode.execute(object);
115-
Object indexDescr = lookupIndex.execute(frame, type, __INDEX__, object);
115+
Object indexDescr = lookupIndex.execute(frame, type, object);
116116
Object result = null;
117117
if (indexDescr != PNone.NO_VALUE) {
118118
result = call.executeObject(frame, indexDescr, object);
119119
checkResult(frame, object, result, resultClassNode, resultSubtype, resultIsInt, raiseNode, warnNode, __INDEX__);
120120
}
121-
Object intDescr = lookupInt.execute(frame, type, __INT__, object);
121+
Object intDescr = lookupInt.execute(frame, type, object);
122122
if (intDescr != PNone.NO_VALUE) {
123123
result = call.executeObject(frame, intDescr, object);
124124
checkResult(frame, object, result, resultClassNode, resultSubtype, resultIsInt, raiseNode, warnNode, __INT__);

0 commit comments

Comments
 (0)