Skip to content

Commit 44b7f6f

Browse files
committed
remove a few more caches of concrete classes that are invalid with shared ASTs
1 parent c98b735 commit 44b7f6f

File tree

7 files changed

+21
-31
lines changed

7 files changed

+21
-31
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -727,14 +727,13 @@ protected CExtNodes.SubtypeNew createSubtypeNew() {
727727
// logic similar to float_subtype_new(PyTypeObject *type, PyObject *x) from CPython
728728
// floatobject.c we have to first create a temporary float, then fill it into
729729
// a natively allocated subtype structure
730-
@Specialization(guards = "isSubtype.execute(cls, floatCls)", limit = "1")
730+
@Specialization(guards = "isSubtype.execute(cls, getBuiltinFloatClass())", limit = "1")
731731
Object doPythonObject(PythonNativeClass cls, Object obj,
732-
@Cached("getBuiltinFloatClass()") PythonBuiltinClass floatCls,
733732
@SuppressWarnings("unused") @Cached("create()") IsSubtypeNode isSubtype,
734733
@Cached("create(__FLOAT__)") LookupAndCallUnaryNode callFloatNode,
735734
@Cached("create()") BranchProfile gotException,
736735
@Cached("createSubtypeNew()") CExtNodes.SubtypeNew subtypeNew) {
737-
double realFloat = doubleFromObject(floatCls, obj, callFloatNode, gotException);
736+
double realFloat = doubleFromObject(getBuiltinFloatClass(), obj, callFloatNode, gotException);
738737
return subtypeNew.execute(cls, realFloat);
739738
}
740739

@@ -1627,13 +1626,12 @@ public PythonModule module(PythonClass cls, String name, String path) {
16271626
@GenerateNodeFactory
16281627
public abstract static class NotImplementedTypeNode extends PythonBuiltinNode {
16291628
protected PythonClass getNotImplementedClass() {
1630-
return getCore().lookupType(PNotImplemented.class);
1629+
return getCore().lookupType(PythonBuiltinClassType.PNotImplemented);
16311630
}
16321631

16331632
@Specialization
1634-
public PNotImplemented module(Object cls,
1635-
@Cached("getNotImplementedClass()") PythonClass notImplementedClass) {
1636-
if (cls != notImplementedClass) {
1633+
public PNotImplemented module(Object cls) {
1634+
if (cls != getNotImplementedClass()) {
16371635
throw raise(TypeError, "'NotImplementedType' object is not callable");
16381636
} else {
16391637
return PNotImplemented.NOT_IMPLEMENTED;
@@ -1655,13 +1653,12 @@ public PEllipsis call(Object cls, Object args, Object kwds) {
16551653
@GenerateNodeFactory
16561654
public abstract static class NoneTypeNode extends PythonBuiltinNode {
16571655
protected PythonClass getNoneClass() {
1658-
return getCore().lookupType(PNone.class);
1656+
return getCore().lookupType(PythonBuiltinClassType.PNone);
16591657
}
16601658

16611659
@Specialization
1662-
public PNone module(Object cls,
1663-
@Cached("getNoneClass()") PythonClass noneClass) {
1664-
if (cls != noneClass) {
1660+
public PNone module(Object cls) {
1661+
if (cls != getNoneClass()) {
16651662
throw raise(TypeError, "NoneType.__new__(%s) is not a subtype of NoneType", cls);
16661663
} else {
16671664
return PNone.NONE;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.oracle.graal.python.PythonLanguage;
5757
import com.oracle.graal.python.builtins.Builtin;
5858
import com.oracle.graal.python.builtins.CoreFunctions;
59+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5960
import com.oracle.graal.python.builtins.PythonBuiltins;
6061
import com.oracle.graal.python.builtins.modules.TruffleCextBuiltinsFactory.GetByteArrayNodeGen;
6162
import com.oracle.graal.python.builtins.modules.TruffleCextBuiltinsFactory.PNativeToPTypeNodeGen;
@@ -248,7 +249,7 @@ Object run(PythonNativeWrapper value,
248249
@Fallback
249250
Object runGeneric(Object value) {
250251
// TODO(fa) force primitive
251-
return getIntNode().executeWith(getCore().lookupType(Integer.class), value, PNone.NONE);
252+
return getIntNode().executeWith(getCore().lookupType(PythonBuiltinClassType.PInt), value, PNone.NONE);
252253
}
253254

254255
private BuiltinConstructors.IntNode getIntNode() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static byte[] fromList(PythonCore core, PList list) {
8989
} catch (ArithmeticException e) {
9090
}
9191
} else {
92-
throw core.raise(TypeError, "'%s' object cannot be interpreted as an integer", core.lookupType(item.getClass()));
92+
throw core.raise(TypeError, "'%p' object cannot be interpreted as an integer", item);
9393
}
9494
throw core.raise(ValueError, "byte must be in range(0, 256)");
9595
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.logging.Level;
4444

4545
import com.oracle.graal.python.PythonLanguage;
46+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4647
import com.oracle.graal.python.builtins.objects.PNone;
4748
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
4849
import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
@@ -278,8 +279,10 @@ Object doTpAsNumber(PythonClass object, @SuppressWarnings("unused") String key)
278279

279280
@Specialization(guards = "eq(TP_AS_BUFFER, key)")
280281
Object doTpAsBuffer(PythonClass object, @SuppressWarnings("unused") String key) {
281-
if (object == getCore().lookupType(PBytes.class) || object == getCore().lookupType(PByteArray.class) || object == getCore().lookupType(PMemoryView.class) ||
282-
object == getCore().lookupType(PBuffer.class)) {
282+
if (object == getCore().lookupType(PythonBuiltinClassType.PBytes) ||
283+
object == getCore().lookupType(PythonBuiltinClassType.PByteArray) ||
284+
object == getCore().lookupType(PythonBuiltinClassType.PMemoryView) ||
285+
object == getCore().lookupType(PythonBuiltinClassType.PBuffer)) {
283286
return new PyBufferProcsWrapper(object);
284287
}
285288

@@ -623,7 +626,7 @@ Object doTpDict(PythonClass object, @SuppressWarnings("unused") String key, Obje
623626
@Cached("create()") HashingStorageNodes.GetItemNode getItem,
624627
@Cached("create()") WriteAttributeToObjectNode writeAttrNode) {
625628
Object value = asPythonObjectNode.execute(nativeValue);
626-
if (value instanceof PDict && ((PDict) value).getPythonClass() == getCore().lookupType(PDict.class)) {
629+
if (value instanceof PDict && ((PDict) value).getPythonClass() == getCore().lookupType(PythonBuiltinClassType.PDict)) {
627630
// special and fast case: commit items and change store
628631
PDict d = (PDict) value;
629632
for (Object k : d.keys()) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.ArrayList;
5050
import java.util.Arrays;
5151

52+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5253
import com.oracle.graal.python.builtins.objects.PNone;
5354
import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage.FastDictStorage;
5455
import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage.PythonObjectDictStorage;
@@ -361,7 +362,7 @@ public HashingStorage doSequence(PythonObject iterable, @SuppressWarnings("unuse
361362
Object it = getIterator.executeWith(iterable);
362363

363364
ArrayList<PSequence> elements = new ArrayList<>();
364-
PythonClass listClass = getCore().lookupType(PList.class);
365+
PythonClass listClass = getCore().lookupType(PythonBuiltinClassType.PList);
365366
boolean isStringKey = false;
366367
try {
367368
while (true) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptorTypeBuiltins.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
import com.oracle.graal.python.builtins.Builtin;
5252
import com.oracle.graal.python.builtins.CoreFunctions;
53+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5354
import com.oracle.graal.python.builtins.PythonBuiltins;
5455
import com.oracle.graal.python.builtins.objects.PNone;
5556
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
@@ -89,14 +90,13 @@ Object repr(GetSetDescriptor descr) {
8990
@Builtin(name = __GET__, fixedNumOfArguments = 3)
9091
@GenerateNodeFactory
9192
abstract static class GetSetGetNode extends PythonTernaryBuiltinNode {
92-
private PythonBuiltinClass noneClass;
9393
@Child CallUnaryMethodNode callNode = CallUnaryMethodNode.create();
9494
private final BranchProfile branchProfile = BranchProfile.create();
9595

9696
// https://github.com/python/cpython/blob/e8b19656396381407ad91473af5da8b0d4346e88/Objects/descrobject.c#L149
9797
@Specialization
9898
Object get(GetSetDescriptor descr, Object obj, PythonClass type) {
99-
if (descr_check(getCore(), descr, obj, type, getNoneType())) {
99+
if (descr_check(getCore(), descr, obj, type, getCore().lookupType(PythonBuiltinClassType.PNone))) {
100100
return descr;
101101
}
102102
if (descr.getGet() != null) {
@@ -106,14 +106,6 @@ Object get(GetSetDescriptor descr, Object obj, PythonClass type) {
106106
throw raise(AttributeError, "attribute '%s' of '%s' objects is not readable", descr.getName(), descr.getType().getName());
107107
}
108108
}
109-
110-
private PythonBuiltinClass getNoneType() {
111-
if (noneClass == null) {
112-
CompilerDirectives.transferToInterpreterAndInvalidate();
113-
noneClass = getCore().lookupType(PNone.class);
114-
}
115-
return noneClass;
116-
}
117109
}
118110

119111
@Builtin(name = __SET__, fixedNumOfArguments = 3)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,6 @@ public static boolean isString(Object obj) {
296296
return obj instanceof String || obj instanceof PString;
297297
}
298298

299-
public static PythonBuiltinClass getClassFor(Class<? extends PythonBuiltinObject> cls, PythonCore core) {
300-
return core.lookupType(cls);
301-
}
302-
303299
public static boolean isBuiltinFunction(Object obj) {
304300
return obj instanceof PBuiltinFunction;
305301
}

0 commit comments

Comments
 (0)