Skip to content

Commit c7ab56f

Browse files
msimaceksteve-s
authored andcommitted
Revert back to using slot lookup node for new
1 parent fecbcbb commit c7ab56f

File tree

6 files changed

+44
-103
lines changed

6 files changed

+44
-103
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
154154
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
155155
import com.oracle.graal.python.builtins.objects.namespace.PSimpleNamespace;
156-
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins.InitNode;
156+
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
157157
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltinsFactory;
158158
import com.oracle.graal.python.builtins.objects.object.PythonObject;
159159
import com.oracle.graal.python.builtins.objects.property.PProperty;
@@ -175,7 +175,6 @@
175175
import com.oracle.graal.python.builtins.objects.type.TypeNodes.CreateTypeNode;
176176
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsAcceptableBaseNode;
177177
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
178-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.LookupNewNode;
179178
import com.oracle.graal.python.builtins.objects.type.TypeNodes.NeedsNativeAllocationNode;
180179
import com.oracle.graal.python.builtins.objects.types.PGenericAlias;
181180
import com.oracle.graal.python.lib.CanBeDoubleNode;
@@ -1753,7 +1752,7 @@ public abstract static class ObjectNode extends PythonVarargsBuiltinNode {
17531752

17541753
@Child private SplitArgsNode splitArgsNode;
17551754
@Child private LookupCallableSlotInMRONode lookupInit;
1756-
@Child private LookupNewNode lookupNew;
1755+
@Child private LookupCallableSlotInMRONode lookupNew;
17571756
@Child private ReportAbstractClassNode reportAbstractClassNode;
17581757
@CompilationFinal private ValueProfile profileInit;
17591758
@CompilationFinal private ValueProfile profileNew;
@@ -1860,7 +1859,7 @@ private void checkExcessArgs(Object type, Object[] varargs, PKeyword[] kwargs) {
18601859
if (varargs.length != 0 || kwargs.length != 0) {
18611860
if (lookupNew == null) {
18621861
CompilerDirectives.transferToInterpreterAndInvalidate();
1863-
lookupNew = insert(LookupNewNode.create());
1862+
lookupNew = insert(LookupCallableSlotInMRONode.create(SpecialMethodSlot.New));
18641863
}
18651864
if (lookupInit == null) {
18661865
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -1882,10 +1881,10 @@ private void checkExcessArgs(Object type, Object[] varargs, PKeyword[] kwargs) {
18821881
CompilerDirectives.transferToInterpreterAndInvalidate();
18831882
profileInitFactory = ValueProfile.createClassProfile();
18841883
}
1885-
if (InitNode.overridesBuiltinMethod(profileNew.profile(lookupNew.execute(type)), BuiltinConstructorsFactory.ObjectNodeFactory.class, profileNewFactory)) {
1884+
if (ObjectBuiltins.InitNode.overridesBuiltinMethod(type, profileNew, lookupNew, profileNewFactory, BuiltinConstructorsFactory.ObjectNodeFactory.class)) {
18861885
throw raise(TypeError, ErrorMessages.NEW_TAKES_ONE_ARG);
18871886
}
1888-
if (!InitNode.overridesBuiltinMethod(profileInit.profile(lookupInit.execute(type)), ObjectBuiltinsFactory.InitNodeFactory.class, profileInitFactory)) {
1887+
if (!ObjectBuiltins.InitNode.overridesBuiltinMethod(type, profileInit, lookupInit, profileInitFactory, ObjectBuiltinsFactory.InitNodeFactory.class)) {
18891888
throw raise(TypeError, ErrorMessages.NEW_TAKES_NO_ARGS, type);
18901889
}
18911890
}
@@ -2407,7 +2406,7 @@ public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments,
24072406
Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict namespaceOrig, PKeyword[] kwds,
24082407
@Bind("this") Node inliningTarget,
24092408
@Cached GetClassNode getClassNode,
2410-
@Cached LookupNewNode getNewFuncNode,
2409+
@Cached("create(New)") LookupCallableSlotInMRONode getNewFuncNode,
24112410
@Cached TypeBuiltins.BindNew bindNew,
24122411
@Exclusive @Cached IsTypeNode isTypeNode,
24132412
@Cached PyObjectLookupAttr lookupMroEntriesNode,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@
136136
import com.oracle.graal.python.builtins.objects.object.PythonObject;
137137
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
138138
import com.oracle.graal.python.builtins.objects.type.PythonClass;
139+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
139140
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode;
140141
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
141142
import com.oracle.graal.python.builtins.objects.type.TypeNodes.HasSameConstructorNode;
142143
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
143-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.LookupNewNode;
144144
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
145145
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
146146
import com.oracle.graal.python.lib.PyTupleSizeNode;
@@ -151,6 +151,7 @@
151151
import com.oracle.graal.python.nodes.PRaiseNode;
152152
import com.oracle.graal.python.nodes.SpecialAttributeNames;
153153
import com.oracle.graal.python.nodes.SpecialMethodNames;
154+
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
154155
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
155156
import com.oracle.graal.python.nodes.attributes.WriteAttributeToDynamicObjectNode;
156157
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
@@ -2360,6 +2361,7 @@ record HPyTypeSpecParam(int kind, Object object) {
23602361
* } HPyType_Spec;
23612362
* </pre>
23622363
*/
2364+
@ImportStatic(SpecialMethodSlot.class)
23632365
@GenerateUncached
23642366
abstract static class HPyCreateTypeFromSpecNode extends Node {
23652367

@@ -2394,7 +2396,7 @@ Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpecParamA
23942396
@Cached HPyCreateGetSetDescriptorNode createGetSetDescriptorNode,
23952397
@Cached GetBaseClassNode getBaseClassNode,
23962398
@Cached ReadAttributeFromObjectNode readHPyTypeFlagsNode,
2397-
@Cached LookupNewNode lookupNewNode,
2399+
@Cached(parameters = "New") LookupCallableSlotInMRONode lookupNewNode,
23982400
@Cached HPyAsPythonObjectNode hPyAsPythonObjectNode,
23992401
@Cached PRaiseNode raiseNode) {
24002402

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
9898
import com.oracle.graal.python.builtins.objects.type.TypeNodes.CheckCompatibleForAssigmentNode;
9999
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode;
100-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.LookupNewNode;
101100
import com.oracle.graal.python.lib.PyObjectLookupAttr;
102101
import com.oracle.graal.python.lib.PyObjectSizeNode;
103102
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -249,17 +248,16 @@ PNone init(Object self, Object[] arguments, PKeyword[] keywords,
249248
@Cached("create(Init)") LookupCallableSlotInMRONode lookupInit,
250249
@Cached(value = "createLookupProfile(getClassNode)", inline = false) ValueProfile profileInit,
251250
@Cached(value = "createClassProfile()", inline = false) ValueProfile profileInitFactory,
252-
@Cached LookupNewNode lookupNew,
251+
@Cached("create(New)") LookupCallableSlotInMRONode lookupNew,
253252
@Cached(value = "createLookupProfile(getClassNode)", inline = false) ValueProfile profileNew,
254253
@Cached(value = "createClassProfile()", inline = false) ValueProfile profileNewFactory) {
255254
if (arguments.length != 0 || keywords.length != 0) {
256255
Object type = getClassNode.execute(inliningTarget, self);
257-
if (overridesNew.profile(inliningTarget, overridesBuiltinMethod(profileInit.profile(lookupInit.execute(type)), ObjectBuiltinsFactory.InitNodeFactory.class, profileInitFactory))) {
256+
if (overridesNew.profile(inliningTarget, overridesBuiltinMethod(type, profileInit, lookupInit, profileInitFactory, ObjectBuiltinsFactory.InitNodeFactory.class))) {
258257
throw raise(TypeError, ErrorMessages.INIT_TAKES_ONE_ARG_OBJECT);
259258
}
260259

261-
if (overridesInit.profile(inliningTarget,
262-
!overridesBuiltinMethod(profileNew.profile(lookupNew.execute(type)), BuiltinConstructorsFactory.ObjectNodeFactory.class, profileNewFactory))) {
260+
if (overridesInit.profile(inliningTarget, !overridesBuiltinMethod(type, profileNew, lookupNew, profileNewFactory, BuiltinConstructorsFactory.ObjectNodeFactory.class))) {
263261
throw raise(TypeError, ErrorMessages.INIT_TAKES_ONE_ARG, type);
264262
}
265263
}
@@ -276,9 +274,11 @@ protected static ValueProfile createLookupProfile(Node node) {
276274

277275
/**
278276
* Simple utility method to check if a method was overridden. The {@code profile} parameter
279-
* must not be an identity profile when AST sharing is enabled.
277+
* must {@emph not} be an identity profile when AST sharing is enabled.
280278
*/
281-
public static <T extends NodeFactory<? extends PythonBuiltinBaseNode>> boolean overridesBuiltinMethod(Object method, Class<T> builtinNodeFactoryClass, ValueProfile factoryProfile) {
279+
public static <T extends NodeFactory<? extends PythonBuiltinBaseNode>> boolean overridesBuiltinMethod(Object type, ValueProfile profile, LookupCallableSlotInMRONode lookup,
280+
ValueProfile factoryProfile, Class<T> builtinNodeFactoryClass) {
281+
Object method = profile.profile(lookup.execute(type));
282282
if (method instanceof PBuiltinFunction) {
283283
NodeFactory<? extends PythonBuiltinBaseNode> factory = factoryProfile.profile(((PBuiltinFunction) method).getBuiltinNodeFactory());
284284
return !builtinNodeFactoryClass.isInstance(factory);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@
159159
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode;
160160
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
161161
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSubclassesNode;
162-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.LookupNewNode;
163162
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
163+
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
164164
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode;
165165
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
166166
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
@@ -665,7 +665,7 @@ private static void fixupNewSlot(Object[] slots, Object type) {
665665
Object tpBaseInheritedNew = ReadAttributeFromObjectNode.getUncachedForceType().execute(type, New.name);
666666
if (tpBaseInheritedNew == PNone.NO_VALUE) {
667667
Object base = GetBaseClassNode.executeUncached(type);
668-
tpBaseInheritedNew = LookupNewNode.executeUncached(base);
668+
tpBaseInheritedNew = LookupCallableSlotInMRONode.getUncached(New).execute(base);
669669
}
670670
slots[New.ordinal()] = tpBaseInheritedNew;
671671
}

0 commit comments

Comments
 (0)