|
123 | 123 | import com.oracle.graal.python.builtins.objects.cext.PythonNativeVoidPtr;
|
124 | 124 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
|
125 | 125 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
|
126 |
| -import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory; |
127 | 126 | import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes;
|
128 | 127 | import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
|
129 | 128 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode;
|
130 | 129 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode;
|
131 |
| -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.NativeToPythonNodeGen; |
132 | 130 | import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CByteArrayWrapper;
|
133 | 131 | import com.oracle.graal.python.builtins.objects.code.CodeNodes;
|
134 | 132 | import com.oracle.graal.python.builtins.objects.code.PCode;
|
|
166 | 164 | import com.oracle.graal.python.builtins.objects.str.PString;
|
167 | 165 | import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
|
168 | 166 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
169 |
| -import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass; |
170 | 167 | import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
|
171 | 168 | import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
|
172 | 169 | import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
|
173 | 170 | import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
|
174 | 171 | import com.oracle.graal.python.builtins.objects.type.TypeFlags;
|
175 | 172 | import com.oracle.graal.python.builtins.objects.type.TypeNodes;
|
176 | 173 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.CreateTypeNode;
|
177 |
| -import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroNode; |
178 | 174 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsAcceptableBaseNode;
|
179 | 175 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
|
180 | 176 | import com.oracle.graal.python.builtins.objects.types.PGenericAlias;
|
@@ -1803,13 +1799,9 @@ protected PList constructList(Object cls, @SuppressWarnings("unused") Object[] a
|
1803 | 1799 | @GenerateNodeFactory
|
1804 | 1800 | public abstract static class ObjectNode extends PythonVarargsBuiltinNode {
|
1805 | 1801 |
|
1806 |
| - @Child private PCallCapiFunction callCapiFunction; |
1807 |
| - @Children private CExtNodes.ToSulongNode[] toSulongNodes; |
1808 |
| - @Child private NativeToPythonNode asPythonObjectNode; |
1809 | 1802 | @Child private SplitArgsNode splitArgsNode;
|
1810 | 1803 | @Child private LookupCallableSlotInMRONode lookupInit;
|
1811 | 1804 | @Child private LookupCallableSlotInMRONode lookupNew;
|
1812 |
| - @Child private ReportAbstractClassNode reportAbstractClassNode; |
1813 | 1805 | @CompilationFinal private ValueProfile profileInit;
|
1814 | 1806 | @CompilationFinal private ValueProfile profileNew;
|
1815 | 1807 | @CompilationFinal private ValueProfile profileInitFactory;
|
@@ -1867,68 +1859,47 @@ Object doBuiltinTypeType(PythonBuiltinClassType self, Object[] varargs, PKeyword
|
1867 | 1859 | @Specialization(guards = "self.needsNativeAllocation()")
|
1868 | 1860 | Object doNativeObjectIndirect(VirtualFrame frame, PythonManagedClass self, Object[] varargs, PKeyword[] kwargs,
|
1869 | 1861 | @Bind("this") Node inliningTarget,
|
1870 |
| - @Cached GetMroNode getMroNode, |
1871 |
| - @Shared @Cached ReportAbstractClassNode reportAbstractClassNode) { |
| 1862 | + @Shared @Cached ReportAbstractClassNode reportAbstractClassNode, |
| 1863 | + @Shared @Cached CallNativeGenericNewNode callNativeGenericNewNode) { |
1872 | 1864 | checkExcessArgs(self, varargs, kwargs);
|
1873 | 1865 | if (self.isAbstractClass()) {
|
1874 | 1866 | throw reportAbstractClassNode.execute(frame, inliningTarget, self);
|
1875 | 1867 | }
|
1876 |
| - Object nativeBaseClass = findFirstNativeBaseClass(getMroNode.execute(self)); |
1877 |
| - return callNativeGenericNewNode(self, nativeBaseClass, varargs, kwargs); |
| 1868 | + return callNativeGenericNewNode.execute(inliningTarget, self); |
1878 | 1869 | }
|
1879 | 1870 |
|
1880 | 1871 | @Specialization(guards = "isNativeClass(self)")
|
1881 | 1872 | @SuppressWarnings("truffle-static-method")
|
1882 | 1873 | Object doNativeObjectDirect(VirtualFrame frame, Object self, Object[] varargs, PKeyword[] kwargs,
|
1883 | 1874 | @Bind("this") Node inliningTarget,
|
1884 | 1875 | @Exclusive @Cached TypeNodes.GetTypeFlagsNode getTypeFlagsNode,
|
1885 |
| - @Shared @Cached ReportAbstractClassNode reportAbstractClassNode) { |
| 1876 | + @Shared @Cached ReportAbstractClassNode reportAbstractClassNode, |
| 1877 | + @Shared @Cached CallNativeGenericNewNode callNativeGenericNewNode) { |
1886 | 1878 | checkExcessArgs(self, varargs, kwargs);
|
1887 | 1879 | if ((getTypeFlagsNode.execute(self) & TypeFlags.IS_ABSTRACT) != 0) {
|
1888 | 1880 | throw reportAbstractClassNode.execute(frame, inliningTarget, self);
|
1889 | 1881 | }
|
1890 |
| - return callNativeGenericNewNode(self, self, varargs, kwargs); |
| 1882 | + return callNativeGenericNewNode.execute(inliningTarget, self); |
1891 | 1883 | }
|
1892 | 1884 |
|
1893 |
| - @SuppressWarnings("unused") |
1894 |
| - @Fallback |
1895 |
| - Object fallback(Object o, Object[] varargs, PKeyword[] kwargs) { |
1896 |
| - throw raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "object.__new__(X): X", o); |
1897 |
| - } |
| 1885 | + @GenerateInline |
| 1886 | + @GenerateCached(false) |
| 1887 | + protected abstract static class CallNativeGenericNewNode extends Node { |
| 1888 | + abstract Object execute(Node inliningTarget, Object cls); |
1898 | 1889 |
|
1899 |
| - private static Object findFirstNativeBaseClass(PythonAbstractClass[] methodResolutionOrder) { |
1900 |
| - for (Object cls : methodResolutionOrder) { |
1901 |
| - if (PGuards.isNativeClass(cls)) { |
1902 |
| - return cls; |
1903 |
| - } |
| 1890 | + @Specialization |
| 1891 | + static Object call(Object cls, |
| 1892 | + @Cached PythonToNativeNode toNativeNode, |
| 1893 | + @Cached NativeToPythonNode toPythonNode, |
| 1894 | + @Cached PCallCapiFunction callCapiFunction) { |
| 1895 | + return toPythonNode.execute(callCapiFunction.call(FUN_PY_OBJECT_NEW, toNativeNode.execute(cls))); |
1904 | 1896 | }
|
1905 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
1906 |
| - throw new IllegalStateException("class needs native allocation but has not native base class"); |
1907 | 1897 | }
|
1908 | 1898 |
|
1909 |
| - private Object callNativeGenericNewNode(Object type, Object nativeBase, Object[] varargs, PKeyword[] kwargs) { |
1910 |
| - if (callCapiFunction == null) { |
1911 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
1912 |
| - callCapiFunction = insert(PCallCapiFunction.create()); |
1913 |
| - } |
1914 |
| - if (toSulongNodes == null) { |
1915 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
1916 |
| - CExtNodes.ToSulongNode[] newToSulongNodes = new CExtNodes.ToSulongNode[4]; |
1917 |
| - for (int i = 0; i < newToSulongNodes.length; i++) { |
1918 |
| - newToSulongNodes[i] = CExtNodesFactory.ToSulongNodeGen.create(); |
1919 |
| - } |
1920 |
| - toSulongNodes = insert(newToSulongNodes); |
1921 |
| - } |
1922 |
| - if (asPythonObjectNode == null) { |
1923 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
1924 |
| - asPythonObjectNode = insert(NativeToPythonNodeGen.create()); |
1925 |
| - } |
1926 |
| - PKeyword[] kwarr = kwargs.length > 0 ? kwargs : null; |
1927 |
| - PTuple targs = factory().createTuple(varargs); |
1928 |
| - PDict dkwargs = factory().createDict(kwarr); |
1929 |
| - return asPythonObjectNode.execute( |
1930 |
| - callCapiFunction.call(FUN_PY_OBJECT_NEW, toSulongNodes[0].execute(type), toSulongNodes[1].execute(nativeBase), toSulongNodes[2].execute(targs), |
1931 |
| - toSulongNodes[3].execute(dkwargs))); |
| 1899 | + @SuppressWarnings("unused") |
| 1900 | + @Fallback |
| 1901 | + Object fallback(Object o, Object[] varargs, PKeyword[] kwargs) { |
| 1902 | + throw raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "object.__new__(X): X", o); |
1932 | 1903 | }
|
1933 | 1904 |
|
1934 | 1905 | private void checkExcessArgs(Object type, Object[] varargs, PKeyword[] kwargs) {
|
|
0 commit comments