Skip to content

Commit 85c3fb0

Browse files
committed
[GR-64551] Remove SpecialMethodSlot
PullRequest: graalpython/3771
2 parents f264067 + 7041530 commit 85c3fb0

File tree

84 files changed

+418
-3010
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+418
-3010
lines changed

graalpython/com.oracle.graal.python.cext/src/typeobject.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6605,9 +6605,6 @@ PyType_Ready(PyTypeObject *type)
66056605
type->tp_flags = (type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY;
66066606
assert(_PyType_CheckConsistency(type));
66076607

6608-
// GraalPy change
6609-
GraalPyTruffle_InitializeOldStyleSlots(type);
6610-
66116608
// GraalPy change: for reason, see first call to Py_INCREF in this function
66126609
Py_DECREF(type);
66136610
return 0;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
6666
import com.oracle.graal.python.builtins.objects.ellipsis.PEllipsis;
6767
import com.oracle.graal.python.builtins.objects.frame.PFrame;
68-
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor;
6968
import com.oracle.graal.python.builtins.objects.function.PArguments;
7069
import com.oracle.graal.python.builtins.objects.module.PythonModule;
7170
import com.oracle.graal.python.builtins.objects.object.PythonObject;
@@ -85,8 +84,8 @@
8584
import com.oracle.graal.python.nodes.HiddenAttr;
8685
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
8786
import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit;
88-
import com.oracle.graal.python.nodes.call.CallNode;
8987
import com.oracle.graal.python.nodes.call.CallDispatchers;
88+
import com.oracle.graal.python.nodes.call.CallNode;
9089
import com.oracle.graal.python.nodes.exception.TopLevelExceptionHandler;
9190
import com.oracle.graal.python.nodes.frame.GetFrameLocalsNode;
9291
import com.oracle.graal.python.nodes.frame.MaterializeFrameNode;
@@ -370,14 +369,6 @@ public boolean isSingleContext() {
370369
*/
371370
private volatile boolean isLanguageInitialized;
372371

373-
/**
374-
* A map to retrieve call targets of special slot methods for a given BuiltinMethodDescriptor.
375-
* Used to perform uncached calls to slots. The call targets are not directly part of
376-
* descriptors because that would make them specific to a language instance. We want to have
377-
* them global in order to be able to efficiently compare them in guards.
378-
*/
379-
private final ConcurrentHashMap<BuiltinMethodDescriptor, RootCallTarget> descriptorCallTargets = new ConcurrentHashMap<>();
380-
381372
private final Shape emptyShape = Shape.newBuilder().allowImplicitCastIntToDouble(false).allowImplicitCastIntToLong(true).shapeFlags(0).propertyAssumptions(true).build();
382373
@CompilationFinal(dimensions = 1) private final Shape[] builtinTypeInstanceShapes = new Shape[PythonBuiltinClassType.VALUES.length];
383374

@@ -1189,22 +1180,6 @@ private RootCallTarget createCachedCallTargetUnsafe(Function<PythonLanguage, Roo
11891180
return createCachedCallTargetUnsafe(rootNodeFunction, Arrays.asList(cacheKeys), cacheInSingleContext);
11901181
}
11911182

1192-
public void registerBuiltinDescriptorCallTarget(BuiltinMethodDescriptor descriptor, RootCallTarget callTarget) {
1193-
descriptorCallTargets.put(descriptor, callTarget);
1194-
}
1195-
1196-
/**
1197-
* Gets a {@link CallTarget} for given {@link BuiltinMethodDescriptor}. The
1198-
* {@link BuiltinMethodDescriptor} must have been inserted into the slots of some Python class
1199-
* in the current context, otherwise its {@link CallTarget} will not be cached here.
1200-
*/
1201-
@TruffleBoundary
1202-
public RootCallTarget getDescriptorCallTarget(BuiltinMethodDescriptor descriptor) {
1203-
RootCallTarget callTarget = descriptorCallTargets.get(descriptor);
1204-
assert callTarget != null : "Missing call target for builtin slot descriptor " + descriptor;
1205-
return callTarget;
1206-
}
1207-
12081183
@Override
12091184
protected void exitContext(PythonContext context, ExitMode exitMode, int exitCode) {
12101185
if (context.getCApiContext() != null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@
362362
import com.oracle.graal.python.builtins.objects.tuple.TupleGetterBuiltins;
363363
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
364364
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
365-
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
366365
import com.oracle.graal.python.builtins.objects.type.TpSlots;
367366
import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
368367
import com.oracle.graal.python.builtins.objects.types.GenericAliasBuiltins;
@@ -920,14 +919,12 @@ public final void initialize(PythonContext context) {
920919
initializeImportlib();
921920
context.applyModuleOptions();
922921
initializePython3Core(context.getCoreHomeOrFail());
923-
assert SpecialMethodSlot.checkSlotOverrides(this);
924922
initialized = true;
925923
}
926924

927925
private void initializeJavaCore() {
928926
initializeTypes();
929927
populateBuiltins();
930-
SpecialMethodSlot.initializeBuiltinsSpecialMethodSlots(this);
931928
publishBuiltinModules();
932929
builtinsModule = builtinModules.get(BuiltinNames.T_BUILTINS);
933930
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@
176176
import com.oracle.graal.python.builtins.objects.foreign.ForeignObjectBuiltins;
177177
import com.oracle.graal.python.builtins.objects.frame.FrameBuiltins;
178178
import com.oracle.graal.python.builtins.objects.function.AbstractFunctionBuiltins;
179-
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor;
180179
import com.oracle.graal.python.builtins.objects.function.FunctionBuiltins;
181180
import com.oracle.graal.python.builtins.objects.function.MethodDescriptorBuiltins;
182181
import com.oracle.graal.python.builtins.objects.function.WrapperDescriptorBuiltins;
@@ -261,7 +260,6 @@
261260
import com.oracle.graal.python.builtins.objects.tuple.StructSequenceBuiltins;
262261
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins;
263262
import com.oracle.graal.python.builtins.objects.tuple.TupleGetterBuiltins;
264-
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
265263
import com.oracle.graal.python.builtins.objects.type.TpSlots;
266264
import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
267265
import com.oracle.graal.python.builtins.objects.types.GenericAliasBuiltins;
@@ -1246,15 +1244,6 @@ public TypeBuilder doc(String doc) {
12461244
@CompilationFinal private PythonBuiltinClassType type;
12471245
@CompilationFinal private int weaklistoffset;
12481246

1249-
/**
1250-
* Lookup cache for special slots defined in {@link SpecialMethodSlot}. Use
1251-
* {@link SpecialMethodSlot} to access the values. Unlike the cache in
1252-
* {@link com.oracle.graal.python.builtins.objects.type.PythonManagedClass}, this caches only
1253-
* builtin context independent values, most notably instances of {@link BuiltinMethodDescriptor}
1254-
* .
1255-
*/
1256-
private Object[] specialMethodSlots;
1257-
12581247
/**
12591248
* The slots defined directly on the builtin class.
12601249
*/
@@ -1339,13 +1328,6 @@ public TruffleString getDoc() {
13391328
return doc;
13401329
}
13411330

1342-
/**
1343-
* Access the values using methods in {@link SpecialMethodSlot}.
1344-
*/
1345-
public Object[] getSpecialMethodSlots() {
1346-
return specialMethodSlots;
1347-
}
1348-
13491331
public TpSlots getSlots() {
13501332
return slots;
13511333
}
@@ -1354,11 +1336,6 @@ public TpSlots getDeclaredSlots() {
13541336
return declaredSlots;
13551337
}
13561338

1357-
public void setSpecialMethodSlots(Object[] slots) {
1358-
assert specialMethodSlots == null; // should be assigned only once per VM
1359-
specialMethodSlots = slots;
1360-
}
1361-
13621339
public int getWeaklistoffset() {
13631340
return weaklistoffset;
13641341
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static Object reconstructCached(VirtualFrame frame, Object arrayType, TruffleStr
9999
@Exclusive @Cached PyObjectCallMethodObjArgs callDecode,
100100
@Exclusive @Cached ArrayBuiltins.FromBytesNode fromBytesNode,
101101
@Exclusive @Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
102+
@Exclusive @Cached TypeNodes.IsTypeNode isTypeNode,
102103
@Exclusive @Cached IsSubtypeNode isSubtypeNode,
103104
@Exclusive @Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
104105
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
@@ -109,7 +110,8 @@ static Object reconstructCached(VirtualFrame frame, Object arrayType, TruffleStr
109110
if (format == null) {
110111
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_TYPECODE);
111112
}
112-
return doReconstruct(frame, inliningTarget, arrayType, typeCode, cachedCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, formatProfile.profile(format),
113+
return doReconstruct(frame, inliningTarget, arrayType, typeCode, cachedCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isTypeNode, isSubtypeNode, byteSwapNode,
114+
formatProfile.profile(format),
113115
getInstanceShape, raiseNode);
114116
}
115117

@@ -119,6 +121,7 @@ static Object reconstruct(VirtualFrame frame, Object arrayType, TruffleString ty
119121
@Exclusive @Cached PyObjectCallMethodObjArgs callDecode,
120122
@Exclusive @Cached ArrayBuiltins.FromBytesNode fromBytesNode,
121123
@Exclusive @Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
124+
@Exclusive @Cached TypeNodes.IsTypeNode isTypeNode,
122125
@Exclusive @Cached IsSubtypeNode isSubtypeNode,
123126
@Exclusive @Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
124127
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
@@ -129,15 +132,19 @@ static Object reconstruct(VirtualFrame frame, Object arrayType, TruffleString ty
129132
if (format == null) {
130133
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_TYPECODE);
131134
}
132-
return doReconstruct(frame, inliningTarget, arrayType, typeCode, mformatCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, format, getInstanceShape,
135+
return doReconstruct(frame, inliningTarget, arrayType, typeCode, mformatCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isTypeNode, isSubtypeNode, byteSwapNode, format,
136+
getInstanceShape,
133137
raiseNode);
134138
}
135139

136140
private static Object doReconstruct(VirtualFrame frame, Node inliningTarget, Object arrayType, TruffleString typeCode, int mformatCode, PBytes bytes, PyObjectCallMethodObjArgs callDecode,
137-
ArrayBuiltins.FromBytesNode fromBytesNode, ArrayBuiltins.FromUnicodeNode fromUnicodeNode, IsSubtypeNode isSubtypeNode,
141+
ArrayBuiltins.FromBytesNode fromBytesNode, ArrayBuiltins.FromUnicodeNode fromUnicodeNode, TypeNodes.IsTypeNode isTypeNode, IsSubtypeNode isSubtypeNode,
138142
ArrayBuiltins.ByteSwapNode byteSwapNode, BufferFormat format,
139143
TypeNodes.GetInstanceShape getInstanceShape, PRaiseNode raiseNode) {
140-
if (!isSubtypeNode.execute(frame, arrayType, PythonBuiltinClassType.PArray)) {
144+
if (!isTypeNode.execute(inliningTarget, arrayType)) {
145+
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.FIRST_ARGUMENT_MUST_BE_A_TYPE_OBJECT_NOT_P, arrayType);
146+
}
147+
if (!isSubtypeNode.execute(arrayType, PythonBuiltinClassType.PArray)) {
141148
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_NOT_SUBTYPE_OF_ARRAY, arrayType);
142149
}
143150
MachineFormat machineFormat = MachineFormat.fromCode(mformatCode);

0 commit comments

Comments
 (0)