Skip to content

Commit 842c34e

Browse files
committed
more specific specializations for class instantiation
1 parent 130c251 commit 842c34e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
9191
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
9292
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
93+
import com.oracle.graal.python.builtins.objects.type.PythonClass;
9394
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
9495
import com.oracle.graal.python.nodes.object.GetClassNode;
9596
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
@@ -310,7 +311,7 @@ public static boolean isIndexNegative(long idx) {
310311
}
311312

312313
public static boolean isPythonUserClass(Object klass) {
313-
return !isPythonBuiltinClass(klass);
314+
return klass instanceof PythonClass || PythonNativeClass.isInstance(klass);
314315
}
315316

316317
public static boolean isPythonBuiltinClassType(Object klass) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,25 @@ protected Object builtinFunctionCall(VirtualFrame frame, PBuiltinFunction callab
121121
return dispatch.executeCall(frame, callable, createArgs.execute(callable, arguments, keywords));
122122
}
123123

124-
@Specialization(guards = "!isCallable(callableObject)")
124+
@Specialization
125+
protected Object doType(VirtualFrame frame, PythonBuiltinClassType callableObject, Object[] arguments, PKeyword[] keywords,
126+
@Cached PRaiseNode raise,
127+
@Cached("create(__CALL__)") LookupInheritedAttributeNode callAttrGetterNode,
128+
@Cached CallVarargsMethodNode callCallNode) {
129+
Object call = callAttrGetterNode.execute(callableObject);
130+
return callCall(frame, callableObject, arguments, keywords, raise, callCallNode, call);
131+
}
132+
133+
@Specialization(guards = "isPythonClass(callableObject)", replaces = "doType")
134+
protected Object doPythonClass(VirtualFrame frame, Object callableObject, Object[] arguments, PKeyword[] keywords,
135+
@Cached PRaiseNode raise,
136+
@Cached("create(__CALL__)") LookupInheritedAttributeNode callAttrGetterNode,
137+
@Cached CallVarargsMethodNode callCallNode) {
138+
Object call = callAttrGetterNode.execute(callableObject);
139+
return callCall(frame, callableObject, arguments, keywords, raise, callCallNode, call);
140+
}
141+
142+
@Specialization(guards = "!isCallable(callableObject)", replaces = {"doType", "doPythonClass"})
125143
protected Object doObjectAndType(VirtualFrame frame, Object callableObject, Object[] arguments, PKeyword[] keywords,
126144
@Shared("raise") @Cached PRaiseNode raise,
127145
@Shared("lookupCall") @Cached("create(__CALL__)") LookupInheritedAttributeNode callAttrGetterNode,

0 commit comments

Comments
 (0)