Skip to content

Commit 792c7ae

Browse files
msimaceksteve-s
authored andcommitted
Use slot lookup for setting up native tp_new
1 parent c7ab56f commit 792c7ae

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,11 @@ static long doSingleContext(Object cls, CFields nativeMemberName, Object managed
12131213
}
12141214
}
12151215

1216+
/**
1217+
* This node is used for lookups of fields that are inherited from the dominant base instead of
1218+
* MRO, such as {@code tp_basicsize}. For MRO lookup, use
1219+
* {@link LookupNativeI64MemberInMRONode}.
1220+
*/
12161221
@GenerateUncached
12171222
public abstract static class LookupNativeI64MemberFromBaseNode extends Node {
12181223

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

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,11 @@
4848
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_del;
4949
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_free;
5050
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_vectorcall_offset;
51-
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_weaklistoffset;
5251
import static com.oracle.graal.python.builtins.objects.type.TypeBuiltins.TYPE_ALLOC;
53-
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___WEAKLISTOFFSET__;
54-
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NEW__;
5552

5653
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5754
import com.oracle.graal.python.builtins.modules.ctypes.StgDictObject;
5855
import com.oracle.graal.python.builtins.objects.PNone;
59-
import com.oracle.graal.python.builtins.objects.PythonAbstractObject.PInteropGetAttributeNode;
60-
import com.oracle.graal.python.builtins.objects.PythonAbstractObjectFactory.PInteropGetAttributeNodeGen;
6156
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.LookupNativeI64MemberInMRONodeGen;
6257
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.LookupNativeMemberInMRONodeGen;
6358
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode;
@@ -75,23 +70,21 @@
7570
import com.oracle.graal.python.builtins.objects.dict.PDict;
7671
import com.oracle.graal.python.builtins.objects.method.PDecoratedMethod;
7772
import com.oracle.graal.python.builtins.objects.str.PString;
78-
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
7973
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
74+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
8075
import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
8176
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode;
8277
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassesNode;
78+
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBasicSizeNode;
79+
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetItemSizeNode;
8380
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
8481
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetTypeFlagsNode;
85-
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.GetBasicSizeNodeGen;
82+
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetWeakListOffsetNode;
8683
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.GetDictOffsetNodeGen;
87-
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.GetItemSizeNodeGen;
8884
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.GetTypeFlagsNodeGen;
89-
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
90-
import com.oracle.graal.python.lib.PyNumberAsSizeNodeGen;
9185
import com.oracle.graal.python.nodes.PNodeWithContext;
9286
import com.oracle.graal.python.nodes.SpecialAttributeNames;
93-
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
94-
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONodeGen;
87+
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
9588
import com.oracle.graal.python.nodes.attributes.LookupNativeSlotNode;
9689
import com.oracle.graal.python.nodes.attributes.LookupNativeSlotNodeGen.LookupNativeGetattroSlotNodeGen;
9790
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.InlineIsBuiltinClassProfile;
@@ -268,9 +261,6 @@ static void initializeType(PythonClassNativeWrapper obj, Object mem,
268261

269262
PythonToNativeNode toNative = PythonToNativeNodeGen.getUncached();
270263
PythonToNativeNewRefNode toNativeNewRef = PythonToNativeNewRefNodeGen.getUncached();
271-
LookupAttributeInMRONode.Dynamic lookupAttrNode = LookupAttributeInMRONodeGen.DynamicNodeGen.getUncached();
272-
PyNumberAsSizeNode asSizeNode = PyNumberAsSizeNodeGen.getUncached();
273-
PInteropGetAttributeNode getAttrNode = PInteropGetAttributeNodeGen.getUncached();
274264
CastToTruffleStringNode castToStringNode = CastToTruffleStringNode.getUncached();
275265
CStructAccess.WritePointerNode writePtrNode = CStructAccessFactory.WritePointerNodeGen.getUncached();
276266
CStructAccess.WriteLongNode writeI64Node = CStructAccessFactory.WriteLongNodeGen.getUncached();
@@ -299,8 +289,9 @@ static void initializeType(PythonClassNativeWrapper obj, Object mem,
299289
writeI64Node.write(mem, CFields.PyVarObject__ob_size, 0L);
300290

301291
writePtrNode.write(mem, CFields.PyTypeObject__tp_name, clazz.getClassNativeWrapper().getNameWrapper());
302-
writeI64Node.write(mem, CFields.PyTypeObject__tp_basicsize, GetBasicSizeNodeGen.getUncached().execute(null, clazz));
303-
writeI64Node.write(mem, CFields.PyTypeObject__tp_itemsize, GetItemSizeNodeGen.getUncached().execute(null, clazz));
292+
writeI64Node.write(mem, CFields.PyTypeObject__tp_basicsize, GetBasicSizeNode.executeUncached(clazz));
293+
writeI64Node.write(mem, CFields.PyTypeObject__tp_itemsize, GetItemSizeNode.executeUncached(clazz));
294+
writeI64Node.write(mem, CFields.PyTypeObject__tp_weaklistoffset, GetWeakListOffsetNode.executeUncached(clazz));
304295
writePtrNode.write(mem, CFields.PyTypeObject__tp_dealloc, lookup(clazz, PyTypeObject__tp_dealloc, TypeBuiltins.TYPE_DEALLOC));
305296
writeI64Node.write(mem, CFields.PyTypeObject__tp_vectorcall_offset, lookupSize(clazz, PyTypeObject__tp_vectorcall_offset, TypeBuiltins.TYPE_VECTORCALL_OFFSET));
306297
writePtrNode.write(mem, CFields.PyTypeObject__tp_getattr, nullValue);
@@ -333,13 +324,6 @@ static void initializeType(PythonClassNativeWrapper obj, Object mem,
333324
writePtrNode.write(mem, CFields.PyTypeObject__tp_traverse, nullValue);
334325
writePtrNode.write(mem, CFields.PyTypeObject__tp_clear, nullValue);
335326
writePtrNode.write(mem, CFields.PyTypeObject__tp_richcompare, lookup(clazz, SlotMethodDef.TP_RICHCOMPARE));
336-
long weaklistoffset;
337-
if (clazz instanceof PythonBuiltinClass builtin) {
338-
weaklistoffset = builtin.getType().getWeaklistoffset();
339-
} else {
340-
weaklistoffset = LookupNativeI64MemberInMRONodeGen.getUncached().execute(clazz, PyTypeObject__tp_weaklistoffset, T___WEAKLISTOFFSET__);
341-
}
342-
writeI64Node.write(mem, CFields.PyTypeObject__tp_weaklistoffset, weaklistoffset);
343327
writePtrNode.write(mem, CFields.PyTypeObject__tp_iter, lookup(clazz, SlotMethodDef.TP_ITER));
344328
writePtrNode.write(mem, CFields.PyTypeObject__tp_iternext, lookup(clazz, SlotMethodDef.TP_ITERNEXT));
345329
writePtrNode.write(mem, CFields.PyTypeObject__tp_methods, nullValue);
@@ -373,7 +357,7 @@ static void initializeType(PythonClassNativeWrapper obj, Object mem,
373357
writePtrNode.write(mem, CFields.PyTypeObject__tp_alloc, lookup(clazz, PyTypeObject__tp_alloc, TYPE_ALLOC));
374358
// T___new__ is magically a staticmethod for Python types. The tp_new slot lookup
375359
// expects to get the function
376-
Object newFunction = lookupAttrNode.execute(clazz, T___NEW__);
360+
Object newFunction = LookupCallableSlotInMRONode.getUncached(SpecialMethodSlot.New).execute(clazz);
377361
if (newFunction instanceof PDecoratedMethod) {
378362
newFunction = ((PDecoratedMethod) newFunction).getCallable();
379363
}

0 commit comments

Comments
 (0)