Skip to content

Commit bf15454

Browse files
committed
Clean up few interfaces use in specializations
1 parent 39abee7 commit bf15454

File tree

4 files changed

+49
-45
lines changed

4 files changed

+49
-45
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
4747
import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
4848
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
49-
import com.oracle.graal.python.builtins.objects.bytes.PIBytesLike;
5049
import com.oracle.graal.python.builtins.objects.code.CodeNodes;
5150
import com.oracle.graal.python.builtins.objects.code.CodeNodes.CreateCodeNode;
5251
import com.oracle.graal.python.builtins.objects.code.PCode;
@@ -75,7 +74,6 @@
7574
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
7675
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
7776
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
78-
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
7977
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
8078
import com.oracle.graal.python.runtime.PythonContext;
8179
import com.oracle.truffle.api.Assumption;
@@ -228,7 +226,6 @@ abstract static class MarshallerNode extends PNodeWithState {
228226

229227
public abstract void execute(VirtualFrame frame, Object x, int version, DataOutputStream buffer);
230228

231-
@Child private CastToJavaStringNode castStrNode;
232229
@Child private MarshallerNode recursiveNode;
233230
private int depth = 0;
234231
@Child private IsBuiltinClassProfile isBuiltinProfile;
@@ -373,7 +370,14 @@ void handleInternedString(InternedString v, int version, DataOutputStream buffer
373370
}
374371

375372
@Specialization
376-
void handleBytesLike(VirtualFrame frame, PIBytesLike v, int version, DataOutputStream buffer,
373+
void handleBytesLike(VirtualFrame frame, PBytes v, int version, DataOutputStream buffer,
374+
@Cached("create()") BytesNodes.ToBytesNode toBytesNode) {
375+
writeByte(TYPE_BYTESLIKE, version, buffer);
376+
writeBytes(toBytesNode.execute(frame, v), version, buffer);
377+
}
378+
379+
@Specialization
380+
void handleBytesLike(VirtualFrame frame, PByteArray v, int version, DataOutputStream buffer,
377381
@Cached("create()") BytesNodes.ToBytesNode toBytesNode) {
378382
writeByte(TYPE_BYTESLIKE, version, buffer);
379383
writeBytes(toBytesNode.execute(frame, v), version, buffer);

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
164164
@ImportStatic(SpecialAttributeNames.class)
165165
public abstract static class ReprNode extends PythonUnaryBuiltinNode {
166166
@Specialization
167-
String repr(VirtualFrame frame, Object self,
167+
static String repr(VirtualFrame frame, Object self,
168168
@Cached("create(__MODULE__)") GetFixedAttributeNode readModuleNode,
169169
@Cached("create(__QUALNAME__)") GetFixedAttributeNode readQualNameNode) {
170170
Object moduleName = readModuleNode.executeObject(frame, self);
@@ -249,7 +249,6 @@ public abstract static class CallNode extends PythonVarargsBuiltinNode {
249249
@Child private LookupSpecialMethodNode lookupInit = LookupSpecialMethodNode.create(__INIT__);
250250
@Child private IsSubtypeNode isSubTypeNode;
251251
@Child private TypeNodes.GetNameNode getNameNode;
252-
@Child private IsBuiltinClassProfile isClassClassProfile = IsBuiltinClassProfile.create();
253252

254253
@CompilationFinal private boolean newWasDescriptor = false;
255254

@@ -325,9 +324,10 @@ protected Object doIt0BuiltinSingle(VirtualFrame frame, @SuppressWarnings("unuse
325324
return op(frame, cachedSelf.getType(), arguments, keywords, true, plib);
326325
}
327326

328-
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = {"self == cachedSelf", "!isPythonBuiltinClass(cachedSelf)"}, assumptions = "singleContextAssumption()")
329-
protected Object doIt0User(VirtualFrame frame, @SuppressWarnings("unused") PythonAbstractClass self, Object[] arguments, PKeyword[] keywords,
330-
@Cached("self") PythonAbstractClass cachedSelf,
327+
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = {"self == cachedSelf", "isPythonClass(cachedSelf)",
328+
"!isPythonBuiltinClass(cachedSelf)"}, assumptions = "singleContextAssumption()")
329+
protected Object doIt0User(VirtualFrame frame, @SuppressWarnings("unused") Object self, Object[] arguments, PKeyword[] keywords,
330+
@Cached("self") Object cachedSelf,
331331
@CachedLibrary(limit = "3") PythonObjectLibrary plib) {
332332
return op(frame, cachedSelf, arguments, keywords, true, plib);
333333
}
@@ -605,7 +605,7 @@ Object setBases(VirtualFrame frame, PythonClass cls, PTuple value,
605605
for (int i = 0; i < a.length; i++) {
606606
if (PGuards.isPythonClass(a[i])) {
607607
if (isSubtypeNode.execute(frame, a[i], cls) ||
608-
hasMRO(getMroNode, (PythonAbstractClass) a[i]) && typeIsSubtypeBaseChain((PythonAbstractClass) a[i], cls, getBase, isSameTypeNode)) {
608+
hasMRO(getMroNode, a[i]) && typeIsSubtypeBaseChain(a[i], cls, getBase, isSameTypeNode)) {
609609
throw raise(TypeError, ErrorMessages.BASES_ITEM_CAUSES_INHERITANCE_CYCLE);
610610
}
611611
baseClasses[i] = (PythonAbstractClass) a[i];
@@ -627,18 +627,18 @@ Object setBases(VirtualFrame frame, PythonClass cls, PTuple value,
627627
return PNone.NONE;
628628
}
629629

630-
private static boolean hasMRO(GetMroNode getMroNode, PythonAbstractClass i) {
630+
private static boolean hasMRO(GetMroNode getMroNode, Object i) {
631631
PythonAbstractClass[] mro = getMroNode.execute(i);
632632
return mro != null && mro.length > 0;
633633
}
634634

635-
private static boolean typeIsSubtypeBaseChain(PythonAbstractClass a, PythonAbstractClass b, GetBaseClassNode getBaseNode, IsSameTypeNode isSameTypeNode) {
636-
PythonAbstractClass base = a;
635+
private static boolean typeIsSubtypeBaseChain(Object a, Object b, GetBaseClassNode getBaseNode, IsSameTypeNode isSameTypeNode) {
636+
Object base = a;
637637
do {
638638
if (isSameTypeNode.execute(base, b)) {
639639
return true;
640640
}
641-
base = (PythonAbstractClass) getBaseNode.execute(base);
641+
base = getBaseNode.execute(base);
642642
} while (base != null);
643643

644644
return (isSameTypeNode.execute(b, PythonBuiltinClassType.PythonObject));
@@ -699,7 +699,7 @@ Object doManaged(PythonManagedClass self,
699699
}
700700

701701
@Specialization
702-
Object doNative(PythonNativeClass self,
702+
static Object doNative(PythonNativeClass self,
703703
@Cached CExtNodes.GetTypeMemberNode getTpDictNode) {
704704
return getTpDictNode.execute(self, NativeMember.TP_DICT);
705705
}
@@ -838,12 +838,12 @@ abstract static class AbstractSlotNode extends PythonBinaryBuiltinNode {
838838
@Builtin(name = __NAME__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
839839
abstract static class NameNode extends AbstractSlotNode {
840840
@Specialization(guards = "isNoValue(value)")
841-
String getNameType(PythonBuiltinClassType cls, @SuppressWarnings("unused") PNone value) {
841+
static String getNameType(PythonBuiltinClassType cls, @SuppressWarnings("unused") PNone value) {
842842
return cls.getName();
843843
}
844844

845845
@Specialization(guards = "isNoValue(value)")
846-
String getNameBuiltin(PythonManagedClass cls, @SuppressWarnings("unused") PNone value) {
846+
static String getNameBuiltin(PythonManagedClass cls, @SuppressWarnings("unused") PNone value) {
847847
return cls.getName();
848848
}
849849

@@ -873,7 +873,7 @@ Object setName(PythonClass cls, Object value,
873873
}
874874

875875
@Specialization(guards = "isNoValue(value)")
876-
Object getModule(PythonAbstractNativeObject cls, @SuppressWarnings("unused") PNone value,
876+
static Object getModule(PythonAbstractNativeObject cls, @SuppressWarnings("unused") PNone value,
877877
@Cached GetTypeMemberNode getTpNameNode) {
878878
// 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...'
879879
String tpName = (String) getTpNameNode.execute(cls, NativeMember.TP_NAME);
@@ -900,13 +900,13 @@ private static String getQualName(String fqname) {
900900
abstract static class ModuleNode extends AbstractSlotNode {
901901

902902
@Specialization(guards = "isNoValue(value)")
903-
Object getModuleType(PythonBuiltinClassType cls, @SuppressWarnings("unused") PNone value) {
903+
static Object getModuleType(PythonBuiltinClassType cls, @SuppressWarnings("unused") PNone value) {
904904
String module = cls.getPublicInModule();
905905
return module == null ? BuiltinNames.BUILTINS : module;
906906
}
907907

908908
@Specialization(guards = "isNoValue(value)")
909-
Object getModuleBuiltin(PythonBuiltinClass cls, @SuppressWarnings("unused") PNone value) {
909+
static Object getModuleBuiltin(PythonBuiltinClass cls, @SuppressWarnings("unused") PNone value) {
910910
return getModuleType(cls.getType(), value);
911911
}
912912

@@ -921,14 +921,14 @@ Object getModule(PythonClass cls, @SuppressWarnings("unused") PNone value,
921921
}
922922

923923
@Specialization(guards = "!isNoValue(value)")
924-
Object setModule(PythonClass cls, Object value,
924+
static Object setModule(PythonClass cls, Object value,
925925
@Cached("create()") WriteAttributeToObjectNode writeAttrNode) {
926926
writeAttrNode.execute(cls, __MODULE__, value);
927927
return PNone.NONE;
928928
}
929929

930930
@Specialization(guards = "isNoValue(value)")
931-
Object getModule(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
931+
static Object getModule(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
932932
@Cached GetTypeMemberNode getTpNameNode) {
933933
// 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...'
934934
String tpName = (String) getTpNameNode.execute(cls, NativeMember.TP_NAME);
@@ -953,12 +953,12 @@ private static Object getModuleName(String fqname) {
953953
@Builtin(name = __QUALNAME__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
954954
abstract static class QualNameNode extends AbstractSlotNode {
955955
@Specialization(guards = "isNoValue(value)")
956-
String getName(PythonBuiltinClassType cls, @SuppressWarnings("unused") PNone value) {
956+
static String getName(PythonBuiltinClassType cls, @SuppressWarnings("unused") PNone value) {
957957
return cls.getQualifiedName();
958958
}
959959

960960
@Specialization(guards = "isNoValue(value)")
961-
String getName(PythonManagedClass cls, @SuppressWarnings("unused") PNone value) {
961+
static String getName(PythonManagedClass cls, @SuppressWarnings("unused") PNone value) {
962962
return cls.getQualName();
963963
}
964964

@@ -979,7 +979,7 @@ Object setName(PythonClass cls, Object value,
979979
}
980980

981981
@Specialization(guards = "isNoValue(value)")
982-
String getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
982+
static String getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
983983
@Cached GetTypeMemberNode getTpNameNode) {
984984
// 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...'
985985
String tpName = (String) getTpNameNode.execute(cls, NativeMember.TP_NAME);
@@ -1011,7 +1011,7 @@ Object getDictoffsetType(PythonBuiltinClassType cls, @SuppressWarnings("unused")
10111011
}
10121012

10131013
@Specialization(guards = "isNoValue(value)")
1014-
Object getDictoffsetManaged(PythonManagedClass cls, @SuppressWarnings("unused") PNone value,
1014+
static Object getDictoffsetManaged(PythonManagedClass cls, @SuppressWarnings("unused") PNone value,
10151015
@Cached("create()") IsBuiltinClassProfile profile,
10161016
@Cached("create()") ReadAttributeFromObjectNode getName) {
10171017
// recursion anchor; since the metaclass of 'type' is 'type'
@@ -1032,13 +1032,13 @@ Object setDictoffsetBuiltin(@SuppressWarnings("unused") PythonBuiltinClass cls,
10321032
}
10331033

10341034
@Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)"})
1035-
Object setDictoffsetClass(PythonClass cls, Object value,
1035+
static Object setDictoffsetClass(PythonClass cls, Object value,
10361036
@Cached("create()") WriteAttributeToObjectNode setName) {
10371037
return setName.execute(cls, __DICTOFFSET__, value);
10381038
}
10391039

10401040
@Specialization(guards = "isNoValue(value)")
1041-
Object getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
1041+
static Object getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
10421042
@Cached GetTypeMemberNode getTpDictoffsetNode) {
10431043
return getTpDictoffsetNode.execute(cls, NativeMember.TP_DICTOFFSET);
10441044
}
@@ -1060,7 +1060,7 @@ Object getItemsizeType(PythonBuiltinClassType cls, @SuppressWarnings("unused") P
10601060
}
10611061

10621062
@Specialization(guards = "isNoValue(value)")
1063-
Object getItemsizeManaged(PythonManagedClass cls, @SuppressWarnings("unused") PNone value,
1063+
static Object getItemsizeManaged(PythonManagedClass cls, @SuppressWarnings("unused") PNone value,
10641064
@Cached("create()") IsBuiltinClassProfile profile,
10651065
@Cached("create()") ReadAttributeFromObjectNode getName) {
10661066
// recursion anchor; since the metaclass of 'type' is 'type'
@@ -1081,13 +1081,13 @@ Object setItemsizeBuiltin(@SuppressWarnings("unused") PythonBuiltinClass cls, @S
10811081
}
10821082

10831083
@Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)"})
1084-
Object setItemsize(PythonClass cls, Object value,
1084+
static Object setItemsize(PythonClass cls, Object value,
10851085
@Cached("create()") WriteAttributeToObjectNode setName) {
10861086
return setName.execute(cls, __ITEMSIZE__, value);
10871087
}
10881088

10891089
@Specialization(guards = "isNoValue(value)")
1090-
Object getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
1090+
static Object getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
10911091
@Cached GetTypeMemberNode getTpDictoffsetNode) {
10921092
return getTpDictoffsetNode.execute(cls, NativeMember.TP_ITEMSIZE);
10931093
}
@@ -1108,7 +1108,7 @@ Object getBasicsizeType(PythonBuiltinClassType cls, @SuppressWarnings("unused")
11081108
}
11091109

11101110
@Specialization(guards = "isNoValue(value)")
1111-
Object getBasicsizeManaged(PythonManagedClass cls, @SuppressWarnings("unused") PNone value,
1111+
static Object getBasicsizeManaged(PythonManagedClass cls, @SuppressWarnings("unused") PNone value,
11121112
@Cached("create()") IsBuiltinClassProfile profile,
11131113
@Cached("create()") ReadAttributeFromObjectNode getName) {
11141114
// recursion anchor; since the metaclass of 'type' is 'type'
@@ -1129,13 +1129,13 @@ Object setBasicsizeBuiltin(@SuppressWarnings("unused") PythonBuiltinClass cls, @
11291129
}
11301130

11311131
@Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)"})
1132-
Object setBasicsize(PythonClass cls, Object value,
1132+
static Object setBasicsize(PythonClass cls, Object value,
11331133
@Cached("create()") WriteAttributeToObjectNode setName) {
11341134
return setName.execute(cls, __BASICSIZE__, value);
11351135
}
11361136

11371137
@Specialization(guards = "isNoValue(value)")
1138-
Object getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
1138+
static Object getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
11391139
@Cached("create()") GetTypeMemberNode getTpDictoffsetNode) {
11401140
return getTpDictoffsetNode.execute(cls, NativeMember.TP_BASICSIZE);
11411141
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected static boolean compareStrings(String key, String cachedKey) {
9090
}
9191

9292
@Specialization(guards = "compareStrings(key, cachedKey)", limit = "2")
93-
protected Object lookupConstantMRO(Object klass, @SuppressWarnings("unused") String key,
93+
protected static Object lookupConstantMRO(Object klass, @SuppressWarnings("unused") String key,
9494
@Cached("key") @SuppressWarnings("unused") String cachedKey,
9595
@Cached("create(key)") LookupAttributeInMRONode lookup) {
9696
return lookup.execute(klass);
@@ -106,7 +106,7 @@ protected Object lookup(PythonBuiltinClassType klass, Object key) {
106106
}
107107

108108
@Specialization(replaces = "lookupConstantMRO")
109-
protected Object lookup(Object klass, Object key,
109+
protected static Object lookup(Object klass, Object key,
110110
@Cached("create()") GetMroStorageNode getMroNode,
111111
@Cached("createForceType()") ReadAttributeFromObjectNode readAttrNode) {
112112
return lookupSlow(klass, key, getMroNode, readAttrNode, false);
@@ -117,6 +117,7 @@ static class DynamicUncached extends Dynamic {
117117
private final ReadAttributeFromObjectNode readAttrNode = ReadAttributeFromObjectNode.getUncachedForceType();
118118
private final GetMroStorageNode getMroNode = GetMroStorageNode.getUncached();
119119

120+
@TruffleBoundary
120121
@Override
121122
public Object execute(Object klass, Object key) {
122123
if (klass instanceof PythonBuiltinClassType) {
@@ -183,7 +184,7 @@ protected static Object findAttr(PythonCore core, PythonBuiltinClassType klass,
183184
}
184185

185186
@Specialization(guards = {"klass == cachedKlass"}, limit = "getAttributeAccessInlineCacheMaxDepth()")
186-
protected Object lookupPBCTCached(@SuppressWarnings("unused") PythonBuiltinClassType klass,
187+
protected static Object lookupPBCTCached(@SuppressWarnings("unused") PythonBuiltinClassType klass,
187188
@Cached("klass") @SuppressWarnings("unused") PythonBuiltinClassType cachedKlass,
188189
@Cached("findAttr(getCore(), cachedKlass, key)") Object cachedValue) {
189190
return cachedValue;
@@ -228,13 +229,13 @@ protected PythonClassAssumptionPair findAttrClassAndAssumptionInMRO(Object klass
228229
@Specialization(guards = {"isSameType(cachedKlass, klass)", "cachedClassInMROInfo != null"}, //
229230
limit = "getAttributeAccessInlineCacheMaxDepth()", //
230231
assumptions = {"cachedClassInMROInfo.assumption", "singleContextAssumption()"})
231-
protected Object lookupConstantMROCached(@SuppressWarnings("unused") Object klass,
232+
protected static Object lookupConstantMROCached(@SuppressWarnings("unused") Object klass,
232233
@Cached("klass") @SuppressWarnings("unused") Object cachedKlass,
233234
@Cached("findAttrClassAndAssumptionInMRO(cachedKlass)") PythonClassAssumptionPair cachedClassInMROInfo) {
234235
return cachedClassInMROInfo.value;
235236
}
236237

237-
protected ReadAttributeFromObjectNode[] create(int size) {
238+
protected static ReadAttributeFromObjectNode[] create(int size) {
238239
ReadAttributeFromObjectNode[] nodes = new ReadAttributeFromObjectNode[size];
239240
for (int i = 0; i < size; i++) {
240241
nodes[i] = ReadAttributeFromObjectNode.createForceType();

0 commit comments

Comments
 (0)